blob: cfa24f9f1682db8336ebc12715f177724f236c47 [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000093 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000094 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Tim Northovera2292d02013-06-10 23:20:58 +0000155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
157 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
160 }
James Molloy21efa7d2011-09-28 14:21:38 +0000161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
163 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
166 }
Tim Northovera2292d02013-06-10 23:20:58 +0000167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
169 }
170
Evan Cheng284b4672011-07-08 22:36:29 +0000171 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000174 }
James Molloy21efa7d2011-09-28 14:21:38 +0000175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
177 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000178
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000179 /// @name Auto-generated Match Functions
180 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000181
Chris Lattner3e4582a2010-09-06 19:11:01 +0000182#define GET_ASSEMBLER_HEADER
183#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000184
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000185 /// }
186
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000194 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000195 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000198 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
206 }
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
209 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
219 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000220
221 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000224 void cvtThumbBranches(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
226
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000227 bool validateInstruction(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000229 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000230 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000231 bool shouldOmitCCOutOperand(StringRef Mnemonic,
232 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000233 bool shouldOmitPredicateOperand(StringRef Mnemonic,
234 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Gouly5d0564d2013-08-02 19:18:12 +0000235 bool isDeprecated(MCInst &Inst, StringRef &Info);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000236
Kevin Enderbyccab3172009-09-15 00:27:25 +0000237public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000238 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000239 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000240 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000241 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000242 Match_RequiresThumb2,
243#define GET_OPERAND_DIAGNOSTIC_TYPES
244#include "ARMGenAsmMatcher.inc"
245
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000246 };
247
Evan Cheng91111d22011-07-09 05:47:46 +0000248 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000249 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000250 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000251
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000252 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000253 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000254
Evan Cheng4d1ca962011-07-08 01:53:10 +0000255 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000256 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000257
258 // Not in an ITBlock to start with.
259 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000260
261 // Set ELF header flags.
262 // FIXME: This should eventually end up somewhere else where more
263 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000264 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
265 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
266 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000267 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000268
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000269 // Implementation of the MCTargetAsmParser interface:
270 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000271 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
272 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000273 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000274 bool ParseDirective(AsmToken DirectiveID);
275
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000276 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000277 unsigned checkTargetMatchPredicate(MCInst &Inst);
278
Chad Rosier49963552012-10-13 00:26:04 +0000279 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000280 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000281 MCStreamer &Out, unsigned &ErrorInfo,
282 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000283};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000284} // end anonymous namespace
285
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000286namespace {
287
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000288/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000289/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000290class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000291 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000292 k_CondCode,
293 k_CCOut,
294 k_ITCondMask,
295 k_CoprocNum,
296 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000297 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000298 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000299 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000300 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000301 k_Memory,
302 k_PostIndexRegister,
303 k_MSRMask,
304 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000305 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000306 k_Register,
307 k_RegisterList,
308 k_DPRRegisterList,
309 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000310 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000311 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000312 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000313 k_ShiftedRegister,
314 k_ShiftedImmediate,
315 k_ShifterImmediate,
316 k_RotateImmediate,
317 k_BitfieldDescriptor,
318 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000319 } Kind;
320
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000321 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000322 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000323
Eric Christopher8996c5d2013-03-15 00:42:55 +0000324 struct CCOp {
325 ARMCC::CondCodes Val;
326 };
327
328 struct CopOp {
329 unsigned Val;
330 };
331
332 struct CoprocOptionOp {
333 unsigned Val;
334 };
335
336 struct ITMaskOp {
337 unsigned Mask:4;
338 };
339
340 struct MBOptOp {
341 ARM_MB::MemBOpt Val;
342 };
343
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000344 struct ISBOptOp {
345 ARM_ISB::InstSyncBOpt Val;
346 };
347
Eric Christopher8996c5d2013-03-15 00:42:55 +0000348 struct IFlagsOp {
349 ARM_PROC::IFlags Val;
350 };
351
352 struct MMaskOp {
353 unsigned Val;
354 };
355
356 struct TokOp {
357 const char *Data;
358 unsigned Length;
359 };
360
361 struct RegOp {
362 unsigned RegNum;
363 };
364
365 // A vector register list is a sequential list of 1 to 4 registers.
366 struct VectorListOp {
367 unsigned RegNum;
368 unsigned Count;
369 unsigned LaneIndex;
370 bool isDoubleSpaced;
371 };
372
373 struct VectorIndexOp {
374 unsigned Val;
375 };
376
377 struct ImmOp {
378 const MCExpr *Val;
379 };
380
381 /// Combined record for all forms of ARM address expressions.
382 struct MemoryOp {
383 unsigned BaseRegNum;
384 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
385 // was specified.
386 const MCConstantExpr *OffsetImm; // Offset immediate value
387 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
388 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
389 unsigned ShiftImm; // shift for OffsetReg.
390 unsigned Alignment; // 0 = no alignment specified
391 // n = alignment in bytes (2, 4, 8, 16, or 32)
392 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
393 };
394
395 struct PostIdxRegOp {
396 unsigned RegNum;
397 bool isAdd;
398 ARM_AM::ShiftOpc ShiftTy;
399 unsigned ShiftImm;
400 };
401
402 struct ShifterImmOp {
403 bool isASR;
404 unsigned Imm;
405 };
406
407 struct RegShiftedRegOp {
408 ARM_AM::ShiftOpc ShiftTy;
409 unsigned SrcReg;
410 unsigned ShiftReg;
411 unsigned ShiftImm;
412 };
413
414 struct RegShiftedImmOp {
415 ARM_AM::ShiftOpc ShiftTy;
416 unsigned SrcReg;
417 unsigned ShiftImm;
418 };
419
420 struct RotImmOp {
421 unsigned Imm;
422 };
423
424 struct BitfieldOp {
425 unsigned LSB;
426 unsigned Width;
427 };
428
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000429 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000430 struct CCOp CC;
431 struct CopOp Cop;
432 struct CoprocOptionOp CoprocOption;
433 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000434 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000435 struct ITMaskOp ITMask;
436 struct IFlagsOp IFlags;
437 struct MMaskOp MMask;
438 struct TokOp Tok;
439 struct RegOp Reg;
440 struct VectorListOp VectorList;
441 struct VectorIndexOp VectorIndex;
442 struct ImmOp Imm;
443 struct MemoryOp Memory;
444 struct PostIdxRegOp PostIdxReg;
445 struct ShifterImmOp ShifterImm;
446 struct RegShiftedRegOp RegShiftedReg;
447 struct RegShiftedImmOp RegShiftedImm;
448 struct RotImmOp RotImm;
449 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000450 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000451
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000452 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
453public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000454 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
455 Kind = o.Kind;
456 StartLoc = o.StartLoc;
457 EndLoc = o.EndLoc;
458 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000459 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000460 CC = o.CC;
461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000462 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000463 ITMask = o.ITMask;
464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000465 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000466 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000468 case k_CCOut:
469 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000470 Reg = o.Reg;
471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000472 case k_RegisterList:
473 case k_DPRRegisterList:
474 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000475 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000476 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000477 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000478 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000479 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000480 VectorList = o.VectorList;
481 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000482 case k_CoprocNum:
483 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000484 Cop = o.Cop;
485 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000486 case k_CoprocOption:
487 CoprocOption = o.CoprocOption;
488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000490 Imm = o.Imm;
491 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000492 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000493 MBOpt = o.MBOpt;
494 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000495 case k_InstSyncBarrierOpt:
496 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000497 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000498 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000500 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000501 PostIdxReg = o.PostIdxReg;
502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000503 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000504 MMask = o.MMask;
505 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000506 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000507 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000510 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000513 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000515 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000516 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000517 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000518 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000519 RotImm = o.RotImm;
520 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000521 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000522 Bitfield = o.Bitfield;
523 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000524 case k_VectorIndex:
525 VectorIndex = o.VectorIndex;
526 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000527 }
528 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000529
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000530 /// getStartLoc - Get the location of the first token of this operand.
531 SMLoc getStartLoc() const { return StartLoc; }
532 /// getEndLoc - Get the location of the last token of this operand.
533 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000534 /// getLocRange - Get the range between the first and last token of this
535 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000536 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
537
Daniel Dunbard8042b72010-08-11 06:36:53 +0000538 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000540 return CC.Val;
541 }
542
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000543 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000544 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000545 return Cop.Val;
546 }
547
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000548 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000549 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000550 return StringRef(Tok.Data, Tok.Length);
551 }
552
553 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000554 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000555 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000556 }
557
Bill Wendlingbed94652010-11-09 23:28:44 +0000558 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000559 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
560 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000561 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000562 }
563
Kevin Enderbyf5079942009-10-13 22:19:02 +0000564 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000565 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000566 return Imm.Val;
567 }
568
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000569 unsigned getVectorIndex() const {
570 assert(Kind == k_VectorIndex && "Invalid access!");
571 return VectorIndex.Val;
572 }
573
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000574 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000575 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000576 return MBOpt.Val;
577 }
578
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000579 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
580 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
581 return ISBOpt.Val;
582 }
583
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000584 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000585 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000586 return IFlags.Val;
587 }
588
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000589 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000591 return MMask.Val;
592 }
593
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 bool isCoprocNum() const { return Kind == k_CoprocNum; }
595 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000596 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000597 bool isCondCode() const { return Kind == k_CondCode; }
598 bool isCCOut() const { return Kind == k_CCOut; }
599 bool isITMask() const { return Kind == k_ITCondMask; }
600 bool isITCondCode() const { return Kind == k_CondCode; }
601 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000602 // checks whether this operand is an unsigned offset which fits is a field
603 // of specified width and scaled by a specific number of bits
604 template<unsigned width, unsigned scale>
605 bool isUnsignedOffset() const {
606 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000607 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000608 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
609 int64_t Val = CE->getValue();
610 int64_t Align = 1LL << scale;
611 int64_t Max = Align * ((1LL << width) - 1);
612 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
613 }
614 return false;
615 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000616 // checks whether this operand is an signed offset which fits is a field
617 // of specified width and scaled by a specific number of bits
618 template<unsigned width, unsigned scale>
619 bool isSignedOffset() const {
620 if (!isImm()) return false;
621 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
622 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
623 int64_t Val = CE->getValue();
624 int64_t Align = 1LL << scale;
625 int64_t Max = Align * ((1LL << (width-1)) - 1);
626 int64_t Min = -Align * (1LL << (width-1));
627 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
628 }
629 return false;
630 }
631
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000632 // checks whether this operand is a memory operand computed as an offset
633 // applied to PC. the offset may have 8 bits of magnitude and is represented
634 // with two bits of shift. textually it may be either [pc, #imm], #imm or
635 // relocable expression...
636 bool isThumbMemPC() const {
637 int64_t Val = 0;
638 if (isImm()) {
639 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
641 if (!CE) return false;
642 Val = CE->getValue();
643 }
644 else if (isMem()) {
645 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
646 if(Memory.BaseRegNum != ARM::PC) return false;
647 Val = Memory.OffsetImm->getValue();
648 }
649 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000650 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000651 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000652 bool isFPImm() const {
653 if (!isImm()) return false;
654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
657 return Val != -1;
658 }
Jim Grosbachea231912011-12-22 22:19:05 +0000659 bool isFBits16() const {
660 if (!isImm()) return false;
661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
664 return Value >= 0 && Value <= 16;
665 }
666 bool isFBits32() const {
667 if (!isImm()) return false;
668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
671 return Value >= 1 && Value <= 32;
672 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000673 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000674 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
679 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000680 bool isImm0_4() const {
681 if (!isImm()) return false;
682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value >= 0 && Value < 5;
686 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000687 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000688 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
693 }
694 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000695 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
700 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000701 bool isImm0_508s4Neg() const {
702 if (!isImm()) return false;
703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = -CE->getValue();
706 // explicitly exclude zero. we want that to use the normal 0_508 version.
707 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
708 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000709 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000710 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
712 if (!CE) return false;
713 int64_t Value = CE->getValue();
714 return Value >= 0 && Value < 256;
715 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000716 bool isImm0_4095() const {
717 if (!isImm()) return false;
718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
719 if (!CE) return false;
720 int64_t Value = CE->getValue();
721 return Value >= 0 && Value < 4096;
722 }
723 bool isImm0_4095Neg() const {
724 if (!isImm()) return false;
725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
726 if (!CE) return false;
727 int64_t Value = -CE->getValue();
728 return Value > 0 && Value < 4096;
729 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000730 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000731 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
733 if (!CE) return false;
734 int64_t Value = CE->getValue();
735 return Value >= 0 && Value < 2;
736 }
737 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000738 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
740 if (!CE) return false;
741 int64_t Value = CE->getValue();
742 return Value >= 0 && Value < 4;
743 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000744 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000745 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int64_t Value = CE->getValue();
749 return Value >= 0 && Value < 8;
750 }
751 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000752 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value < 16;
757 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000758 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000759 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int64_t Value = CE->getValue();
763 return Value >= 0 && Value < 32;
764 }
Jim Grosbach00326402011-12-08 01:30:04 +0000765 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000766 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return Value >= 0 && Value < 64;
771 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000772 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000773 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 if (!CE) return false;
776 int64_t Value = CE->getValue();
777 return Value == 8;
778 }
779 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000780 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int64_t Value = CE->getValue();
784 return Value == 16;
785 }
786 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000787 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = CE->getValue();
791 return Value == 32;
792 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000793 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000794 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
796 if (!CE) return false;
797 int64_t Value = CE->getValue();
798 return Value > 0 && Value <= 8;
799 }
800 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000801 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = CE->getValue();
805 return Value > 0 && Value <= 16;
806 }
807 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000808 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
810 if (!CE) return false;
811 int64_t Value = CE->getValue();
812 return Value > 0 && Value <= 32;
813 }
814 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000815 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
817 if (!CE) return false;
818 int64_t Value = CE->getValue();
819 return Value > 0 && Value <= 64;
820 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000821 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000822 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
824 if (!CE) return false;
825 int64_t Value = CE->getValue();
826 return Value > 0 && Value < 8;
827 }
828 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000829 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
831 if (!CE) return false;
832 int64_t Value = CE->getValue();
833 return Value > 0 && Value < 16;
834 }
835 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000836 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return Value > 0 && Value < 32;
841 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000842 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000843 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value > 0 && Value < 17;
848 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000849 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000850 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value > 0 && Value < 33;
855 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000856 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000857 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value >= 0 && Value < 33;
862 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000863 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000864 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value >= 0 && Value < 65536;
869 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000870 bool isImm256_65535Expr() const {
871 if (!isImm()) return false;
872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 // If it's not a constant expression, it'll generate a fixup and be
874 // handled later.
875 if (!CE) return true;
876 int64_t Value = CE->getValue();
877 return Value >= 256 && Value < 65536;
878 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000879 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000880 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000881 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
882 // If it's not a constant expression, it'll generate a fixup and be
883 // handled later.
884 if (!CE) return true;
885 int64_t Value = CE->getValue();
886 return Value >= 0 && Value < 65536;
887 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000888 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000889 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
893 return Value >= 0 && Value <= 0xffffff;
894 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000895 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return Value > 0 && Value < 33;
901 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000902 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return Value >= 0 && Value < 32;
908 }
909 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000910 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
914 return Value > 0 && Value <= 32;
915 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000916 bool isAdrLabel() const {
917 // If we have an immediate that's not a constant, treat it as a label
918 // reference needing a fixup. If it is a constant, but it can't fit
919 // into shift immediate encoding, we reject it.
920 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
921 else return (isARMSOImm() || isARMSOImmNeg());
922 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000923 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000924 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
926 if (!CE) return false;
927 int64_t Value = CE->getValue();
928 return ARM_AM::getSOImmVal(Value) != -1;
929 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000930 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000931 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Value = CE->getValue();
935 return ARM_AM::getSOImmVal(~Value) != -1;
936 }
Jim Grosbach30506252011-12-08 00:31:07 +0000937 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000938 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000942 // Only use this when not representable as a plain so_imm.
943 return ARM_AM::getSOImmVal(Value) == -1 &&
944 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000945 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000946 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000947 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
949 if (!CE) return false;
950 int64_t Value = CE->getValue();
951 return ARM_AM::getT2SOImmVal(Value) != -1;
952 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000953 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000954 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
956 if (!CE) return false;
957 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000958 return ARM_AM::getT2SOImmVal(Value) == -1 &&
959 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000960 }
Jim Grosbach30506252011-12-08 00:31:07 +0000961 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000962 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
964 if (!CE) return false;
965 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000966 // Only use this when not representable as a plain so_imm.
967 return ARM_AM::getT2SOImmVal(Value) == -1 &&
968 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000969 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000970 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000971 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000972 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
973 if (!CE) return false;
974 int64_t Value = CE->getValue();
975 return Value == 1 || Value == 0;
976 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000977 bool isReg() const { return Kind == k_Register; }
978 bool isRegList() const { return Kind == k_RegisterList; }
979 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
980 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
981 bool isToken() const { return Kind == k_Token; }
982 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000983 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000984 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000985 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
986 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
987 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
988 bool isRotImm() const { return Kind == k_RotateImmediate; }
989 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
990 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000991 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000992 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000993 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000994 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000995 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000996 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000997 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000998 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
999 (alignOK || Memory.Alignment == 0);
1000 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001001 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001002 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001003 return false;
1004 // Base register must be PC.
1005 if (Memory.BaseRegNum != ARM::PC)
1006 return false;
1007 // Immediate offset in range [-4095, 4095].
1008 if (!Memory.OffsetImm) return true;
1009 int64_t Val = Memory.OffsetImm->getValue();
1010 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1011 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001012 bool isAlignedMemory() const {
1013 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001014 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001015 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001016 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001017 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001018 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001019 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001020 if (!Memory.OffsetImm) return true;
1021 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001022 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001023 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001024 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001025 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001026 // Immediate offset in range [-4095, 4095].
1027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1028 if (!CE) return false;
1029 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001030 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001031 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001032 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001033 // If we have an immediate that's not a constant, treat it as a label
1034 // reference needing a fixup. If it is a constant, it's something else
1035 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001036 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001037 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001038 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001039 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001040 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001041 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001042 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001043 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001044 if (!Memory.OffsetImm) return true;
1045 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001046 // The #-0 offset is encoded as INT32_MIN, and we have to check
1047 // for this too.
1048 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001049 }
1050 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001051 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001052 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001053 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001054 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1055 // Immediate offset in range [-255, 255].
1056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1057 if (!CE) return false;
1058 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001059 // Special case, #-0 is INT32_MIN.
1060 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001061 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001062 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001063 // If we have an immediate that's not a constant, treat it as a label
1064 // reference needing a fixup. If it is a constant, it's something else
1065 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001066 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001067 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001068 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001069 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001070 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001071 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001072 if (!Memory.OffsetImm) return true;
1073 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001074 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001075 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001076 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001077 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001078 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001079 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001080 return false;
1081 return true;
1082 }
1083 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001084 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001085 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1086 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001087 return false;
1088 return true;
1089 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001090 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001091 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001092 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001093 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001094 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001095 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001096 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001097 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001098 return false;
1099 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001100 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001101 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001102 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001103 return false;
1104 return true;
1105 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001106 bool isMemThumbRR() const {
1107 // Thumb reg+reg addressing is simple. Just two registers, a base and
1108 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001109 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001110 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001111 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001112 return isARMLowRegister(Memory.BaseRegNum) &&
1113 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001114 }
1115 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001116 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001117 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001118 return false;
1119 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001120 if (!Memory.OffsetImm) return true;
1121 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001122 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1123 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001124 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001125 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001126 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001127 return false;
1128 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001129 if (!Memory.OffsetImm) return true;
1130 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001131 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1132 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001133 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001134 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001135 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001136 return false;
1137 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001138 if (!Memory.OffsetImm) return true;
1139 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001140 return Val >= 0 && Val <= 31;
1141 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001142 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001143 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001144 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001145 return false;
1146 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001147 if (!Memory.OffsetImm) return true;
1148 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001149 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001150 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001151 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001152 // If we have an immediate that's not a constant, treat it as a label
1153 // reference needing a fixup. If it is a constant, it's something else
1154 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001155 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001156 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001157 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001158 return false;
1159 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001160 if (!Memory.OffsetImm) return true;
1161 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001162 // Special case, #-0 is INT32_MIN.
1163 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001164 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001165 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001166 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001167 return false;
1168 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001169 if (!Memory.OffsetImm) return true;
1170 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001171 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1172 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001173 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001174 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001175 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001176 // Base reg of PC isn't allowed for these encodings.
1177 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001178 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001179 if (!Memory.OffsetImm) return true;
1180 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001181 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001182 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001183 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001184 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001185 return false;
1186 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001187 if (!Memory.OffsetImm) return true;
1188 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001189 return Val >= 0 && Val < 256;
1190 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001191 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001192 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001193 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001194 // Base reg of PC isn't allowed for these encodings.
1195 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001196 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001197 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001198 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001199 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001200 }
1201 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001202 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001203 return false;
1204 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001205 if (!Memory.OffsetImm) return true;
1206 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001207 return (Val >= 0 && Val < 4096);
1208 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001209 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001210 // If we have an immediate that's not a constant, treat it as a label
1211 // reference needing a fixup. If it is a constant, it's something else
1212 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001213 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001214 return true;
1215
Chad Rosier41099832012-09-11 23:02:35 +00001216 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001217 return false;
1218 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001219 if (!Memory.OffsetImm) return true;
1220 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001221 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001222 }
1223 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001224 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001225 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1226 if (!CE) return false;
1227 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001228 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001229 }
Jim Grosbach93981412011-10-11 21:55:36 +00001230 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001231 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001232 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1233 if (!CE) return false;
1234 int64_t Val = CE->getValue();
1235 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1236 (Val == INT32_MIN);
1237 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001238
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001239 bool isMSRMask() const { return Kind == k_MSRMask; }
1240 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001241
Jim Grosbach741cd732011-10-17 22:26:03 +00001242 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001243 bool isSingleSpacedVectorList() const {
1244 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1245 }
1246 bool isDoubleSpacedVectorList() const {
1247 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1248 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001249 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001250 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001251 return VectorList.Count == 1;
1252 }
1253
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001254 bool isVecListDPair() const {
1255 if (!isSingleSpacedVectorList()) return false;
1256 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1257 .contains(VectorList.RegNum));
1258 }
1259
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001260 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001261 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001262 return VectorList.Count == 3;
1263 }
1264
Jim Grosbach846bcff2011-10-21 20:35:01 +00001265 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001266 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001267 return VectorList.Count == 4;
1268 }
1269
Jim Grosbache5307f92012-03-05 21:43:40 +00001270 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001271 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001272 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1273 .contains(VectorList.RegNum));
1274 }
1275
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001276 bool isVecListThreeQ() const {
1277 if (!isDoubleSpacedVectorList()) return false;
1278 return VectorList.Count == 3;
1279 }
1280
Jim Grosbach1e946a42012-01-24 00:43:12 +00001281 bool isVecListFourQ() const {
1282 if (!isDoubleSpacedVectorList()) return false;
1283 return VectorList.Count == 4;
1284 }
1285
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001286 bool isSingleSpacedVectorAllLanes() const {
1287 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1288 }
1289 bool isDoubleSpacedVectorAllLanes() const {
1290 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1291 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001292 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001293 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001294 return VectorList.Count == 1;
1295 }
1296
Jim Grosbach13a292c2012-03-06 22:01:44 +00001297 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001298 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001299 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1300 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001301 }
1302
Jim Grosbached428bc2012-03-06 23:10:38 +00001303 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001304 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001305 return VectorList.Count == 2;
1306 }
1307
Jim Grosbachb78403c2012-01-24 23:47:04 +00001308 bool isVecListThreeDAllLanes() const {
1309 if (!isSingleSpacedVectorAllLanes()) return false;
1310 return VectorList.Count == 3;
1311 }
1312
1313 bool isVecListThreeQAllLanes() const {
1314 if (!isDoubleSpacedVectorAllLanes()) return false;
1315 return VectorList.Count == 3;
1316 }
1317
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001318 bool isVecListFourDAllLanes() const {
1319 if (!isSingleSpacedVectorAllLanes()) return false;
1320 return VectorList.Count == 4;
1321 }
1322
1323 bool isVecListFourQAllLanes() const {
1324 if (!isDoubleSpacedVectorAllLanes()) return false;
1325 return VectorList.Count == 4;
1326 }
1327
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001328 bool isSingleSpacedVectorIndexed() const {
1329 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1330 }
1331 bool isDoubleSpacedVectorIndexed() const {
1332 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1333 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001334 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001335 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001336 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1337 }
1338
Jim Grosbachda511042011-12-14 23:35:06 +00001339 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001340 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001341 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1342 }
1343
1344 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001345 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001346 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1347 }
1348
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001349 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001350 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001351 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1352 }
1353
Jim Grosbachda511042011-12-14 23:35:06 +00001354 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001355 if (!isSingleSpacedVectorIndexed()) return false;
1356 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1357 }
1358
1359 bool isVecListTwoQWordIndexed() const {
1360 if (!isDoubleSpacedVectorIndexed()) return false;
1361 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1362 }
1363
1364 bool isVecListTwoQHWordIndexed() const {
1365 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001366 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1367 }
1368
1369 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001370 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001371 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1372 }
1373
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001374 bool isVecListThreeDByteIndexed() const {
1375 if (!isSingleSpacedVectorIndexed()) return false;
1376 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1377 }
1378
1379 bool isVecListThreeDHWordIndexed() const {
1380 if (!isSingleSpacedVectorIndexed()) return false;
1381 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1382 }
1383
1384 bool isVecListThreeQWordIndexed() const {
1385 if (!isDoubleSpacedVectorIndexed()) return false;
1386 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1387 }
1388
1389 bool isVecListThreeQHWordIndexed() const {
1390 if (!isDoubleSpacedVectorIndexed()) return false;
1391 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1392 }
1393
1394 bool isVecListThreeDWordIndexed() const {
1395 if (!isSingleSpacedVectorIndexed()) return false;
1396 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1397 }
1398
Jim Grosbach14952a02012-01-24 18:37:25 +00001399 bool isVecListFourDByteIndexed() const {
1400 if (!isSingleSpacedVectorIndexed()) return false;
1401 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1402 }
1403
1404 bool isVecListFourDHWordIndexed() const {
1405 if (!isSingleSpacedVectorIndexed()) return false;
1406 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1407 }
1408
1409 bool isVecListFourQWordIndexed() const {
1410 if (!isDoubleSpacedVectorIndexed()) return false;
1411 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1412 }
1413
1414 bool isVecListFourQHWordIndexed() const {
1415 if (!isDoubleSpacedVectorIndexed()) return false;
1416 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1417 }
1418
1419 bool isVecListFourDWordIndexed() const {
1420 if (!isSingleSpacedVectorIndexed()) return false;
1421 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1422 }
1423
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001424 bool isVectorIndex8() const {
1425 if (Kind != k_VectorIndex) return false;
1426 return VectorIndex.Val < 8;
1427 }
1428 bool isVectorIndex16() const {
1429 if (Kind != k_VectorIndex) return false;
1430 return VectorIndex.Val < 4;
1431 }
1432 bool isVectorIndex32() const {
1433 if (Kind != k_VectorIndex) return false;
1434 return VectorIndex.Val < 2;
1435 }
1436
Jim Grosbach741cd732011-10-17 22:26:03 +00001437 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001438 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1440 // Must be a constant.
1441 if (!CE) return false;
1442 int64_t Value = CE->getValue();
1443 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1444 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001445 return Value >= 0 && Value < 256;
1446 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001447
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001448 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001449 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001450 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1451 // Must be a constant.
1452 if (!CE) return false;
1453 int64_t Value = CE->getValue();
1454 // i16 value in the range [0,255] or [0x0100, 0xff00]
1455 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1456 }
1457
Jim Grosbach8211c052011-10-18 00:22:00 +00001458 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001459 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001460 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1461 // Must be a constant.
1462 if (!CE) return false;
1463 int64_t Value = CE->getValue();
1464 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1465 return (Value >= 0 && Value < 256) ||
1466 (Value >= 0x0100 && Value <= 0xff00) ||
1467 (Value >= 0x010000 && Value <= 0xff0000) ||
1468 (Value >= 0x01000000 && Value <= 0xff000000);
1469 }
1470
1471 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001472 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001473 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1474 // Must be a constant.
1475 if (!CE) return false;
1476 int64_t Value = CE->getValue();
1477 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1478 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1479 return (Value >= 0 && Value < 256) ||
1480 (Value >= 0x0100 && Value <= 0xff00) ||
1481 (Value >= 0x010000 && Value <= 0xff0000) ||
1482 (Value >= 0x01000000 && Value <= 0xff000000) ||
1483 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1484 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1485 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001486 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001487 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001488 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1489 // Must be a constant.
1490 if (!CE) return false;
1491 int64_t Value = ~CE->getValue();
1492 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1493 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1494 return (Value >= 0 && Value < 256) ||
1495 (Value >= 0x0100 && Value <= 0xff00) ||
1496 (Value >= 0x010000 && Value <= 0xff0000) ||
1497 (Value >= 0x01000000 && Value <= 0xff000000) ||
1498 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1499 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1500 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001501
Jim Grosbache4454e02011-10-18 16:18:11 +00001502 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001503 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001504 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1505 // Must be a constant.
1506 if (!CE) return false;
1507 uint64_t Value = CE->getValue();
1508 // i64 value with each byte being either 0 or 0xff.
1509 for (unsigned i = 0; i < 8; ++i)
1510 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1511 return true;
1512 }
1513
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001514 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001515 // Add as immediates when possible. Null MCExpr = 0.
1516 if (Expr == 0)
1517 Inst.addOperand(MCOperand::CreateImm(0));
1518 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001519 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1520 else
1521 Inst.addOperand(MCOperand::CreateExpr(Expr));
1522 }
1523
Daniel Dunbard8042b72010-08-11 06:36:53 +00001524 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001525 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001526 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001527 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1528 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001529 }
1530
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001531 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && "Invalid number of operands!");
1533 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1534 }
1535
Jim Grosbach48399582011-10-12 17:34:41 +00001536 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1537 assert(N == 1 && "Invalid number of operands!");
1538 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1539 }
1540
1541 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1542 assert(N == 1 && "Invalid number of operands!");
1543 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1544 }
1545
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001546 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 1 && "Invalid number of operands!");
1548 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1549 }
1550
1551 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1552 assert(N == 1 && "Invalid number of operands!");
1553 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1554 }
1555
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001556 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1557 assert(N == 1 && "Invalid number of operands!");
1558 Inst.addOperand(MCOperand::CreateReg(getReg()));
1559 }
1560
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001561 void addRegOperands(MCInst &Inst, unsigned N) const {
1562 assert(N == 1 && "Invalid number of operands!");
1563 Inst.addOperand(MCOperand::CreateReg(getReg()));
1564 }
1565
Jim Grosbachac798e12011-07-25 20:49:51 +00001566 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001567 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001568 assert(isRegShiftedReg() &&
1569 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001570 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1571 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001572 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001573 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001574 }
1575
Jim Grosbachac798e12011-07-25 20:49:51 +00001576 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001577 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001578 assert(isRegShiftedImm() &&
1579 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001580 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001581 // Shift of #32 is encoded as 0 where permitted
1582 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001583 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001584 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001585 }
1586
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001587 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001588 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001589 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1590 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001591 }
1592
Bill Wendling8d2aa032010-11-08 23:49:57 +00001593 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001594 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001595 const SmallVectorImpl<unsigned> &RegList = getRegList();
1596 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001597 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1598 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001599 }
1600
Bill Wendling9898ac92010-11-17 04:32:08 +00001601 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1602 addRegListOperands(Inst, N);
1603 }
1604
1605 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1606 addRegListOperands(Inst, N);
1607 }
1608
Jim Grosbach833b9d32011-07-27 20:15:40 +00001609 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1610 assert(N == 1 && "Invalid number of operands!");
1611 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1612 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1613 }
1614
Jim Grosbach864b6092011-07-28 21:34:26 +00001615 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1616 assert(N == 1 && "Invalid number of operands!");
1617 // Munge the lsb/width into a bitfield mask.
1618 unsigned lsb = Bitfield.LSB;
1619 unsigned width = Bitfield.Width;
1620 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1621 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1622 (32 - (lsb + width)));
1623 Inst.addOperand(MCOperand::CreateImm(Mask));
1624 }
1625
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001626 void addImmOperands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 addExpr(Inst, getImm());
1629 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001630
Jim Grosbachea231912011-12-22 22:19:05 +00001631 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1632 assert(N == 1 && "Invalid number of operands!");
1633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1634 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1635 }
1636
1637 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1640 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1641 }
1642
Jim Grosbache7fbce72011-10-03 23:38:36 +00001643 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001645 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1646 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1647 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001648 }
1649
Jim Grosbach7db8d692011-09-08 22:07:06 +00001650 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 // FIXME: We really want to scale the value here, but the LDRD/STRD
1653 // instruction don't encode operands that way yet.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1656 }
1657
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001658 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1659 assert(N == 1 && "Invalid number of operands!");
1660 // The immediate is scaled by four in the encoding and is stored
1661 // in the MCInst as such. Lop off the low two bits here.
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1664 }
1665
Jim Grosbach930f2f62012-04-05 20:57:13 +00001666 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The immediate is scaled by four in the encoding and is stored
1669 // in the MCInst as such. Lop off the low two bits here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1672 }
1673
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001674 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The immediate is scaled by four in the encoding and is stored
1677 // in the MCInst as such. Lop off the low two bits here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1680 }
1681
Jim Grosbach475c6db2011-07-25 23:09:14 +00001682 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The constant encodes as the immediate-1, and we store in the instruction
1685 // the bits as encoded, so subtract off one here.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1688 }
1689
Jim Grosbach801e0a32011-07-22 23:16:18 +00001690 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1691 assert(N == 1 && "Invalid number of operands!");
1692 // The constant encodes as the immediate-1, and we store in the instruction
1693 // the bits as encoded, so subtract off one here.
1694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1695 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1696 }
1697
Jim Grosbach46dd4132011-08-17 21:51:27 +00001698 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1699 assert(N == 1 && "Invalid number of operands!");
1700 // The constant encodes as the immediate, except for 32, which encodes as
1701 // zero.
1702 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1703 unsigned Imm = CE->getValue();
1704 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1705 }
1706
Jim Grosbach27c1e252011-07-21 17:23:04 +00001707 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1710 // the instruction as well.
1711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1712 int Val = CE->getValue();
1713 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1714 }
1715
Jim Grosbachb009a872011-10-28 22:36:30 +00001716 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1717 assert(N == 1 && "Invalid number of operands!");
1718 // The operand is actually a t2_so_imm, but we have its bitwise
1719 // negation in the assembly source, so twiddle it here.
1720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1722 }
1723
Jim Grosbach30506252011-12-08 00:31:07 +00001724 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1725 assert(N == 1 && "Invalid number of operands!");
1726 // The operand is actually a t2_so_imm, but we have its
1727 // negation in the assembly source, so twiddle it here.
1728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1730 }
1731
Jim Grosbach930f2f62012-04-05 20:57:13 +00001732 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1733 assert(N == 1 && "Invalid number of operands!");
1734 // The operand is actually an imm0_4095, but we have its
1735 // negation in the assembly source, so twiddle it here.
1736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1737 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1738 }
1739
Mihai Popad36cbaa2013-07-03 09:21:44 +00001740 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1741 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1742 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1743 return;
1744 }
1745
1746 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1747 assert(SR && "Unknown value type!");
1748 Inst.addOperand(MCOperand::CreateExpr(SR));
1749 }
1750
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001751 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1752 assert(N == 1 && "Invalid number of operands!");
1753 if (isImm()) {
1754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1755 if (CE) {
1756 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1757 return;
1758 }
1759
1760 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1761 assert(SR && "Unknown value type!");
1762 Inst.addOperand(MCOperand::CreateExpr(SR));
1763 return;
1764 }
1765
1766 assert(isMem() && "Unknown value type!");
1767 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1768 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1769 }
1770
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001771 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1772 assert(N == 1 && "Invalid number of operands!");
1773 // The operand is actually a so_imm, but we have its bitwise
1774 // negation in the assembly source, so twiddle it here.
1775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1776 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1777 }
1778
Jim Grosbach30506252011-12-08 00:31:07 +00001779 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 1 && "Invalid number of operands!");
1781 // The operand is actually a so_imm, but we have its
1782 // negation in the assembly source, so twiddle it here.
1783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1784 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1785 }
1786
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001787 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1788 assert(N == 1 && "Invalid number of operands!");
1789 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1790 }
1791
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001792 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1795 }
1796
Jim Grosbachd3595712011-08-03 23:50:40 +00001797 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001799 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001800 }
1801
Jim Grosbach94298a92012-01-18 22:46:46 +00001802 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1803 assert(N == 1 && "Invalid number of operands!");
1804 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001805 Inst.addOperand(MCOperand::CreateImm(Imm));
1806 }
1807
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001808 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1809 assert(N == 1 && "Invalid number of operands!");
1810 assert(isImm() && "Not an immediate!");
1811
1812 // If we have an immediate that's not a constant, treat it as a label
1813 // reference needing a fixup.
1814 if (!isa<MCConstantExpr>(getImm())) {
1815 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1816 return;
1817 }
1818
1819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1820 int Val = CE->getValue();
1821 Inst.addOperand(MCOperand::CreateImm(Val));
1822 }
1823
Jim Grosbacha95ec992011-10-11 17:29:55 +00001824 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 2 && "Invalid number of operands!");
1826 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1827 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1828 }
1829
Jim Grosbachd3595712011-08-03 23:50:40 +00001830 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1831 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001832 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1833 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001834 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1835 // Special case for #-0
1836 if (Val == INT32_MIN) Val = 0;
1837 if (Val < 0) Val = -Val;
1838 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1839 } else {
1840 // For register offset, we encode the shift type and negation flag
1841 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001842 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1843 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001844 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001845 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1846 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001847 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001848 }
1849
Jim Grosbachcd17c122011-08-04 23:01:30 +00001850 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 2 && "Invalid number of operands!");
1852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1853 assert(CE && "non-constant AM2OffsetImm operand!");
1854 int32_t Val = CE->getValue();
1855 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1856 // Special case for #-0
1857 if (Val == INT32_MIN) Val = 0;
1858 if (Val < 0) Val = -Val;
1859 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1860 Inst.addOperand(MCOperand::CreateReg(0));
1861 Inst.addOperand(MCOperand::CreateImm(Val));
1862 }
1863
Jim Grosbach5b96b802011-08-10 20:29:19 +00001864 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1865 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001866 // If we have an immediate that's not a constant, treat it as a label
1867 // reference needing a fixup. If it is a constant, it's something else
1868 // and we reject it.
1869 if (isImm()) {
1870 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1871 Inst.addOperand(MCOperand::CreateReg(0));
1872 Inst.addOperand(MCOperand::CreateImm(0));
1873 return;
1874 }
1875
Jim Grosbach871dff72011-10-11 15:59:20 +00001876 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1877 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001878 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1879 // Special case for #-0
1880 if (Val == INT32_MIN) Val = 0;
1881 if (Val < 0) Val = -Val;
1882 Val = ARM_AM::getAM3Opc(AddSub, Val);
1883 } else {
1884 // For register offset, we encode the shift type and negation flag
1885 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001886 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001887 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001888 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1889 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001890 Inst.addOperand(MCOperand::CreateImm(Val));
1891 }
1892
1893 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1894 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001895 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001896 int32_t Val =
1897 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1898 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1899 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001900 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001901 }
1902
1903 // Constant offset.
1904 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1905 int32_t Val = CE->getValue();
1906 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1907 // Special case for #-0
1908 if (Val == INT32_MIN) Val = 0;
1909 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001910 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001911 Inst.addOperand(MCOperand::CreateReg(0));
1912 Inst.addOperand(MCOperand::CreateImm(Val));
1913 }
1914
Jim Grosbachd3595712011-08-03 23:50:40 +00001915 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1916 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001917 // If we have an immediate that's not a constant, treat it as a label
1918 // reference needing a fixup. If it is a constant, it's something else
1919 // and we reject it.
1920 if (isImm()) {
1921 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1922 Inst.addOperand(MCOperand::CreateImm(0));
1923 return;
1924 }
1925
Jim Grosbachd3595712011-08-03 23:50:40 +00001926 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001927 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001928 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1929 // Special case for #-0
1930 if (Val == INT32_MIN) Val = 0;
1931 if (Val < 0) Val = -Val;
1932 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001933 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001934 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001935 }
1936
Jim Grosbach7db8d692011-09-08 22:07:06 +00001937 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1938 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001939 // If we have an immediate that's not a constant, treat it as a label
1940 // reference needing a fixup. If it is a constant, it's something else
1941 // and we reject it.
1942 if (isImm()) {
1943 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1944 Inst.addOperand(MCOperand::CreateImm(0));
1945 return;
1946 }
1947
Jim Grosbach871dff72011-10-11 15:59:20 +00001948 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1949 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001950 Inst.addOperand(MCOperand::CreateImm(Val));
1951 }
1952
Jim Grosbacha05627e2011-09-09 18:37:27 +00001953 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1954 assert(N == 2 && "Invalid number of operands!");
1955 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001956 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1957 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001958 Inst.addOperand(MCOperand::CreateImm(Val));
1959 }
1960
Jim Grosbachd3595712011-08-03 23:50:40 +00001961 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1962 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001963 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1964 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001965 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001966 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001967
Jim Grosbach2392c532011-09-07 23:39:14 +00001968 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1969 addMemImm8OffsetOperands(Inst, N);
1970 }
1971
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001972 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001973 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001974 }
1975
1976 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1977 assert(N == 2 && "Invalid number of operands!");
1978 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001979 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001980 addExpr(Inst, getImm());
1981 Inst.addOperand(MCOperand::CreateImm(0));
1982 return;
1983 }
1984
1985 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001986 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1987 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001988 Inst.addOperand(MCOperand::CreateImm(Val));
1989 }
1990
Jim Grosbachd3595712011-08-03 23:50:40 +00001991 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1992 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001993 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001994 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001995 addExpr(Inst, getImm());
1996 Inst.addOperand(MCOperand::CreateImm(0));
1997 return;
1998 }
1999
2000 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002001 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2002 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002003 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002004 }
Bill Wendling811c9362010-11-30 07:44:32 +00002005
Jim Grosbach05541f42011-09-19 22:21:13 +00002006 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2007 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002008 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2009 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002010 }
2011
2012 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2013 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002014 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2015 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002016 }
2017
Jim Grosbachd3595712011-08-03 23:50:40 +00002018 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2019 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002020 unsigned Val =
2021 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2022 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002023 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2024 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002025 Inst.addOperand(MCOperand::CreateImm(Val));
2026 }
2027
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002028 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2029 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002030 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2031 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2032 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002033 }
2034
Jim Grosbachd3595712011-08-03 23:50:40 +00002035 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002037 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2038 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002039 }
2040
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002041 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2042 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002043 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2044 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002045 Inst.addOperand(MCOperand::CreateImm(Val));
2046 }
2047
Jim Grosbach26d35872011-08-19 18:55:51 +00002048 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2049 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002050 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2051 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002052 Inst.addOperand(MCOperand::CreateImm(Val));
2053 }
2054
Jim Grosbacha32c7532011-08-19 18:49:59 +00002055 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2056 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002057 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2058 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002059 Inst.addOperand(MCOperand::CreateImm(Val));
2060 }
2061
Jim Grosbach23983d62011-08-19 18:13:48 +00002062 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2063 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002064 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2065 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002066 Inst.addOperand(MCOperand::CreateImm(Val));
2067 }
2068
Jim Grosbachd3595712011-08-03 23:50:40 +00002069 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2070 assert(N == 1 && "Invalid number of operands!");
2071 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2072 assert(CE && "non-constant post-idx-imm8 operand!");
2073 int Imm = CE->getValue();
2074 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002075 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002076 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2077 Inst.addOperand(MCOperand::CreateImm(Imm));
2078 }
2079
Jim Grosbach93981412011-10-11 21:55:36 +00002080 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2081 assert(N == 1 && "Invalid number of operands!");
2082 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2083 assert(CE && "non-constant post-idx-imm8s4 operand!");
2084 int Imm = CE->getValue();
2085 bool isAdd = Imm >= 0;
2086 if (Imm == INT32_MIN) Imm = 0;
2087 // Immediate is scaled by 4.
2088 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2089 Inst.addOperand(MCOperand::CreateImm(Imm));
2090 }
2091
Jim Grosbachd3595712011-08-03 23:50:40 +00002092 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2093 assert(N == 2 && "Invalid number of operands!");
2094 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002095 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2096 }
2097
2098 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2099 assert(N == 2 && "Invalid number of operands!");
2100 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2101 // The sign, shift type, and shift amount are encoded in a single operand
2102 // using the AM2 encoding helpers.
2103 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2104 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2105 PostIdxReg.ShiftTy);
2106 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002107 }
2108
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002109 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2110 assert(N == 1 && "Invalid number of operands!");
2111 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2112 }
2113
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002114 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2115 assert(N == 1 && "Invalid number of operands!");
2116 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2117 }
2118
Jim Grosbach182b6a02011-11-29 23:51:09 +00002119 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002120 assert(N == 1 && "Invalid number of operands!");
2121 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2122 }
2123
Jim Grosbach04945c42011-12-02 00:35:16 +00002124 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2125 assert(N == 2 && "Invalid number of operands!");
2126 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2127 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2128 }
2129
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002130 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2131 assert(N == 1 && "Invalid number of operands!");
2132 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2133 }
2134
2135 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2136 assert(N == 1 && "Invalid number of operands!");
2137 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2138 }
2139
2140 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2141 assert(N == 1 && "Invalid number of operands!");
2142 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2143 }
2144
Jim Grosbach741cd732011-10-17 22:26:03 +00002145 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 // The immediate encodes the type of constant as well as the value.
2148 // Mask in that this is an i8 splat.
2149 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2150 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2151 }
2152
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002153 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2154 assert(N == 1 && "Invalid number of operands!");
2155 // The immediate encodes the type of constant as well as the value.
2156 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2157 unsigned Value = CE->getValue();
2158 if (Value >= 256)
2159 Value = (Value >> 8) | 0xa00;
2160 else
2161 Value |= 0x800;
2162 Inst.addOperand(MCOperand::CreateImm(Value));
2163 }
2164
Jim Grosbach8211c052011-10-18 00:22:00 +00002165 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2166 assert(N == 1 && "Invalid number of operands!");
2167 // The immediate encodes the type of constant as well as the value.
2168 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2169 unsigned Value = CE->getValue();
2170 if (Value >= 256 && Value <= 0xff00)
2171 Value = (Value >> 8) | 0x200;
2172 else if (Value > 0xffff && Value <= 0xff0000)
2173 Value = (Value >> 16) | 0x400;
2174 else if (Value > 0xffffff)
2175 Value = (Value >> 24) | 0x600;
2176 Inst.addOperand(MCOperand::CreateImm(Value));
2177 }
2178
2179 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2180 assert(N == 1 && "Invalid number of operands!");
2181 // The immediate encodes the type of constant as well as the value.
2182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2183 unsigned Value = CE->getValue();
2184 if (Value >= 256 && Value <= 0xffff)
2185 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2186 else if (Value > 0xffff && Value <= 0xffffff)
2187 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2188 else if (Value > 0xffffff)
2189 Value = (Value >> 24) | 0x600;
2190 Inst.addOperand(MCOperand::CreateImm(Value));
2191 }
2192
Jim Grosbach045b6c72011-12-19 23:51:07 +00002193 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2194 assert(N == 1 && "Invalid number of operands!");
2195 // The immediate encodes the type of constant as well as the value.
2196 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2197 unsigned Value = ~CE->getValue();
2198 if (Value >= 256 && Value <= 0xffff)
2199 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2200 else if (Value > 0xffff && Value <= 0xffffff)
2201 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2202 else if (Value > 0xffffff)
2203 Value = (Value >> 24) | 0x600;
2204 Inst.addOperand(MCOperand::CreateImm(Value));
2205 }
2206
Jim Grosbache4454e02011-10-18 16:18:11 +00002207 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2208 assert(N == 1 && "Invalid number of operands!");
2209 // The immediate encodes the type of constant as well as the value.
2210 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2211 uint64_t Value = CE->getValue();
2212 unsigned Imm = 0;
2213 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2214 Imm |= (Value & 1) << i;
2215 }
2216 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2217 }
2218
Jim Grosbach602aa902011-07-13 15:34:57 +00002219 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002220
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002221 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002222 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002223 Op->ITMask.Mask = Mask;
2224 Op->StartLoc = S;
2225 Op->EndLoc = S;
2226 return Op;
2227 }
2228
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002229 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002230 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002231 Op->CC.Val = CC;
2232 Op->StartLoc = S;
2233 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002234 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002235 }
2236
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002237 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002238 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002239 Op->Cop.Val = CopVal;
2240 Op->StartLoc = S;
2241 Op->EndLoc = S;
2242 return Op;
2243 }
2244
2245 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002246 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002247 Op->Cop.Val = CopVal;
2248 Op->StartLoc = S;
2249 Op->EndLoc = S;
2250 return Op;
2251 }
2252
Jim Grosbach48399582011-10-12 17:34:41 +00002253 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2254 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2255 Op->Cop.Val = Val;
2256 Op->StartLoc = S;
2257 Op->EndLoc = E;
2258 return Op;
2259 }
2260
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002261 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002262 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002263 Op->Reg.RegNum = RegNum;
2264 Op->StartLoc = S;
2265 Op->EndLoc = S;
2266 return Op;
2267 }
2268
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002269 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002270 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002271 Op->Tok.Data = Str.data();
2272 Op->Tok.Length = Str.size();
2273 Op->StartLoc = S;
2274 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002275 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002276 }
2277
Bill Wendling2063b842010-11-18 23:43:05 +00002278 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002279 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002280 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002281 Op->StartLoc = S;
2282 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002283 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002284 }
2285
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002286 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2287 unsigned SrcReg,
2288 unsigned ShiftReg,
2289 unsigned ShiftImm,
2290 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002291 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002292 Op->RegShiftedReg.ShiftTy = ShTy;
2293 Op->RegShiftedReg.SrcReg = SrcReg;
2294 Op->RegShiftedReg.ShiftReg = ShiftReg;
2295 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002296 Op->StartLoc = S;
2297 Op->EndLoc = E;
2298 return Op;
2299 }
2300
Owen Andersonb595ed02011-07-21 18:54:16 +00002301 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2302 unsigned SrcReg,
2303 unsigned ShiftImm,
2304 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002305 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002306 Op->RegShiftedImm.ShiftTy = ShTy;
2307 Op->RegShiftedImm.SrcReg = SrcReg;
2308 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002309 Op->StartLoc = S;
2310 Op->EndLoc = E;
2311 return Op;
2312 }
2313
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002314 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002315 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002316 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002317 Op->ShifterImm.isASR = isASR;
2318 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002319 Op->StartLoc = S;
2320 Op->EndLoc = E;
2321 return Op;
2322 }
2323
Jim Grosbach833b9d32011-07-27 20:15:40 +00002324 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002325 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002326 Op->RotImm.Imm = Imm;
2327 Op->StartLoc = S;
2328 Op->EndLoc = E;
2329 return Op;
2330 }
2331
Jim Grosbach864b6092011-07-28 21:34:26 +00002332 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2333 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002334 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002335 Op->Bitfield.LSB = LSB;
2336 Op->Bitfield.Width = Width;
2337 Op->StartLoc = S;
2338 Op->EndLoc = E;
2339 return Op;
2340 }
2341
Bill Wendling2cae3272010-11-09 22:44:22 +00002342 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002343 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002344 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002345 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002346 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002347
Chad Rosierfa705ee2013-07-01 20:49:23 +00002348 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002349 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002350 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002351 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002352 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002353
Chad Rosierfa705ee2013-07-01 20:49:23 +00002354 // Sort based on the register encoding values.
2355 array_pod_sort(Regs.begin(), Regs.end());
2356
Bill Wendling9898ac92010-11-17 04:32:08 +00002357 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002358 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002359 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002360 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002361 Op->StartLoc = StartLoc;
2362 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002363 return Op;
2364 }
2365
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002366 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002367 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002368 ARMOperand *Op = new ARMOperand(k_VectorList);
2369 Op->VectorList.RegNum = RegNum;
2370 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002371 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002372 Op->StartLoc = S;
2373 Op->EndLoc = E;
2374 return Op;
2375 }
2376
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002377 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002378 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002379 SMLoc S, SMLoc E) {
2380 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2381 Op->VectorList.RegNum = RegNum;
2382 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002383 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002384 Op->StartLoc = S;
2385 Op->EndLoc = E;
2386 return Op;
2387 }
2388
Jim Grosbach04945c42011-12-02 00:35:16 +00002389 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002390 unsigned Index,
2391 bool isDoubleSpaced,
2392 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002393 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2394 Op->VectorList.RegNum = RegNum;
2395 Op->VectorList.Count = Count;
2396 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002397 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002398 Op->StartLoc = S;
2399 Op->EndLoc = E;
2400 return Op;
2401 }
2402
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002403 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2404 MCContext &Ctx) {
2405 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2406 Op->VectorIndex.Val = Idx;
2407 Op->StartLoc = S;
2408 Op->EndLoc = E;
2409 return Op;
2410 }
2411
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002412 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002413 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002414 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002415 Op->StartLoc = S;
2416 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002417 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002418 }
2419
Jim Grosbachd3595712011-08-03 23:50:40 +00002420 static ARMOperand *CreateMem(unsigned BaseRegNum,
2421 const MCConstantExpr *OffsetImm,
2422 unsigned OffsetRegNum,
2423 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002424 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002425 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002426 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002427 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002428 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002429 Op->Memory.BaseRegNum = BaseRegNum;
2430 Op->Memory.OffsetImm = OffsetImm;
2431 Op->Memory.OffsetRegNum = OffsetRegNum;
2432 Op->Memory.ShiftType = ShiftType;
2433 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002434 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002435 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002436 Op->StartLoc = S;
2437 Op->EndLoc = E;
2438 return Op;
2439 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002440
Jim Grosbachc320c852011-08-05 21:28:30 +00002441 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2442 ARM_AM::ShiftOpc ShiftTy,
2443 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002444 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002445 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002446 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002447 Op->PostIdxReg.isAdd = isAdd;
2448 Op->PostIdxReg.ShiftTy = ShiftTy;
2449 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002450 Op->StartLoc = S;
2451 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002452 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002453 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002454
2455 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002456 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002457 Op->MBOpt.Val = Opt;
2458 Op->StartLoc = S;
2459 Op->EndLoc = S;
2460 return Op;
2461 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002462
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002463 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2464 SMLoc S) {
2465 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2466 Op->ISBOpt.Val = Opt;
2467 Op->StartLoc = S;
2468 Op->EndLoc = S;
2469 return Op;
2470 }
2471
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002472 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002473 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002474 Op->IFlags.Val = IFlags;
2475 Op->StartLoc = S;
2476 Op->EndLoc = S;
2477 return Op;
2478 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002479
2480 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002481 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002482 Op->MMask.Val = MMask;
2483 Op->StartLoc = S;
2484 Op->EndLoc = S;
2485 return Op;
2486 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002487};
2488
2489} // end anonymous namespace.
2490
Jim Grosbach602aa902011-07-13 15:34:57 +00002491void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002492 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002493 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002494 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002496 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002497 OS << "<ccout " << getReg() << ">";
2498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002499 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002500 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002501 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2502 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2503 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002504 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2505 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2506 break;
2507 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002508 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002509 OS << "<coprocessor number: " << getCoproc() << ">";
2510 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002511 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002512 OS << "<coprocessor register: " << getCoproc() << ">";
2513 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002514 case k_CoprocOption:
2515 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002517 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002518 OS << "<mask: " << getMSRMask() << ">";
2519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002520 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002521 getImm()->print(OS);
2522 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002523 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002524 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002525 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002526 case k_InstSyncBarrierOpt:
2527 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2528 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002529 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002530 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002531 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002532 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002533 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002534 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002535 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2536 << PostIdxReg.RegNum;
2537 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2538 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2539 << PostIdxReg.ShiftImm;
2540 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002541 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002542 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002543 OS << "<ARM_PROC::";
2544 unsigned IFlags = getProcIFlags();
2545 for (int i=2; i >= 0; --i)
2546 if (IFlags & (1 << i))
2547 OS << ARM_PROC::IFlagsToString(1 << i);
2548 OS << ">";
2549 break;
2550 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002551 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002552 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002553 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002554 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002555 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2556 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002557 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002558 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002559 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002560 << RegShiftedReg.SrcReg << " "
2561 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2562 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002563 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002564 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002565 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002566 << RegShiftedImm.SrcReg << " "
2567 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2568 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002569 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002570 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002571 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2572 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002573 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002574 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2575 << ", width: " << Bitfield.Width << ">";
2576 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002577 case k_RegisterList:
2578 case k_DPRRegisterList:
2579 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002580 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002581
Bill Wendlingbed94652010-11-09 23:28:44 +00002582 const SmallVectorImpl<unsigned> &RegList = getRegList();
2583 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002584 I = RegList.begin(), E = RegList.end(); I != E; ) {
2585 OS << *I;
2586 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002587 }
2588
2589 OS << ">";
2590 break;
2591 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002592 case k_VectorList:
2593 OS << "<vector_list " << VectorList.Count << " * "
2594 << VectorList.RegNum << ">";
2595 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002596 case k_VectorListAllLanes:
2597 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2598 << VectorList.RegNum << ">";
2599 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002600 case k_VectorListIndexed:
2601 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2602 << VectorList.Count << " * " << VectorList.RegNum << ">";
2603 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002604 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002605 OS << "'" << getToken() << "'";
2606 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002607 case k_VectorIndex:
2608 OS << "<vectorindex " << getVectorIndex() << ">";
2609 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002610 }
2611}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002612
2613/// @name Auto-generated Match Functions
2614/// {
2615
2616static unsigned MatchRegisterName(StringRef Name);
2617
2618/// }
2619
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002620bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2621 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002622 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002623 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002624 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002625
2626 return (RegNo == (unsigned)-1);
2627}
2628
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002629/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002630/// and if it is a register name the token is eaten and the register number is
2631/// returned. Otherwise return -1.
2632///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002633int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002634 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002635 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002636
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002637 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002638 unsigned RegNum = MatchRegisterName(lowerCase);
2639 if (!RegNum) {
2640 RegNum = StringSwitch<unsigned>(lowerCase)
2641 .Case("r13", ARM::SP)
2642 .Case("r14", ARM::LR)
2643 .Case("r15", ARM::PC)
2644 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002645 // Additional register name aliases for 'gas' compatibility.
2646 .Case("a1", ARM::R0)
2647 .Case("a2", ARM::R1)
2648 .Case("a3", ARM::R2)
2649 .Case("a4", ARM::R3)
2650 .Case("v1", ARM::R4)
2651 .Case("v2", ARM::R5)
2652 .Case("v3", ARM::R6)
2653 .Case("v4", ARM::R7)
2654 .Case("v5", ARM::R8)
2655 .Case("v6", ARM::R9)
2656 .Case("v7", ARM::R10)
2657 .Case("v8", ARM::R11)
2658 .Case("sb", ARM::R9)
2659 .Case("sl", ARM::R10)
2660 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002661 .Default(0);
2662 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002663 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002664 // Check for aliases registered via .req. Canonicalize to lower case.
2665 // That's more consistent since register names are case insensitive, and
2666 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2667 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002668 // If no match, return failure.
2669 if (Entry == RegisterReqs.end())
2670 return -1;
2671 Parser.Lex(); // Eat identifier token.
2672 return Entry->getValue();
2673 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002674
Chris Lattner44e5981c2010-10-30 04:09:10 +00002675 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002676
Chris Lattner44e5981c2010-10-30 04:09:10 +00002677 return RegNum;
2678}
Jim Grosbach99710a82010-11-01 16:44:21 +00002679
Jim Grosbachbb24c592011-07-13 18:49:30 +00002680// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2681// If a recoverable error occurs, return 1. If an irrecoverable error
2682// occurs, return -1. An irrecoverable error is one where tokens have been
2683// consumed in the process of trying to parse the shifter (i.e., when it is
2684// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002685int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002686 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2687 SMLoc S = Parser.getTok().getLoc();
2688 const AsmToken &Tok = Parser.getTok();
2689 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2690
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002691 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002692 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002693 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002694 .Case("lsl", ARM_AM::lsl)
2695 .Case("lsr", ARM_AM::lsr)
2696 .Case("asr", ARM_AM::asr)
2697 .Case("ror", ARM_AM::ror)
2698 .Case("rrx", ARM_AM::rrx)
2699 .Default(ARM_AM::no_shift);
2700
2701 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002702 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002703
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002704 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002705
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002706 // The source register for the shift has already been added to the
2707 // operand list, so we need to pop it off and combine it into the shifted
2708 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002709 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002710 if (!PrevOp->isReg())
2711 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2712 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002713
2714 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002715 int64_t Imm = 0;
2716 int ShiftReg = 0;
2717 if (ShiftTy == ARM_AM::rrx) {
2718 // RRX Doesn't have an explicit shift amount. The encoder expects
2719 // the shift register to be the same as the source register. Seems odd,
2720 // but OK.
2721 ShiftReg = SrcReg;
2722 } else {
2723 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002724 if (Parser.getTok().is(AsmToken::Hash) ||
2725 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002726 Parser.Lex(); // Eat hash.
2727 SMLoc ImmLoc = Parser.getTok().getLoc();
2728 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002729 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002730 Error(ImmLoc, "invalid immediate shift value");
2731 return -1;
2732 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002733 // The expression must be evaluatable as an immediate.
2734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002735 if (!CE) {
2736 Error(ImmLoc, "invalid immediate shift value");
2737 return -1;
2738 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002739 // Range check the immediate.
2740 // lsl, ror: 0 <= imm <= 31
2741 // lsr, asr: 0 <= imm <= 32
2742 Imm = CE->getValue();
2743 if (Imm < 0 ||
2744 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2745 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002746 Error(ImmLoc, "immediate shift value out of range");
2747 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002748 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002749 // shift by zero is a nop. Always send it through as lsl.
2750 // ('as' compatibility)
2751 if (Imm == 0)
2752 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002753 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002754 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002755 EndLoc = Parser.getTok().getEndLoc();
2756 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002757 if (ShiftReg == -1) {
2758 Error (L, "expected immediate or register in shift operand");
2759 return -1;
2760 }
2761 } else {
2762 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002763 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002764 return -1;
2765 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002766 }
2767
Owen Andersonb595ed02011-07-21 18:54:16 +00002768 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2769 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002770 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002771 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002772 else
2773 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002774 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002775
Jim Grosbachbb24c592011-07-13 18:49:30 +00002776 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002777}
2778
2779
Bill Wendling2063b842010-11-18 23:43:05 +00002780/// Try to parse a register name. The token must be an Identifier when called.
2781/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2782/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002783///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002784/// TODO this is likely to change to allow different register types and or to
2785/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002786bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002787tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002788 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002789 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002790 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002791 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002792
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002793 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2794 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002795
Chris Lattner44e5981c2010-10-30 04:09:10 +00002796 const AsmToken &ExclaimTok = Parser.getTok();
2797 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002798 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2799 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002800 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002801 return false;
2802 }
2803
2804 // Also check for an index operand. This is only legal for vector registers,
2805 // but that'll get caught OK in operand matching, so we don't need to
2806 // explicitly filter everything else out here.
2807 if (Parser.getTok().is(AsmToken::LBrac)) {
2808 SMLoc SIdx = Parser.getTok().getLoc();
2809 Parser.Lex(); // Eat left bracket token.
2810
2811 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002812 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002813 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002814 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002815 if (!MCE)
2816 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002817
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002818 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002819 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002820
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002821 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002822 Parser.Lex(); // Eat right bracket token.
2823
2824 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2825 SIdx, E,
2826 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002827 }
2828
Bill Wendling2063b842010-11-18 23:43:05 +00002829 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002830}
2831
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002832/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2833/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2834/// "c5", ...
2835static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002836 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2837 // but efficient.
2838 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002839 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002840 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002841 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002842 return -1;
2843 switch (Name[1]) {
2844 default: return -1;
2845 case '0': return 0;
2846 case '1': return 1;
2847 case '2': return 2;
2848 case '3': return 3;
2849 case '4': return 4;
2850 case '5': return 5;
2851 case '6': return 6;
2852 case '7': return 7;
2853 case '8': return 8;
2854 case '9': return 9;
2855 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002856 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002857 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002858 return -1;
2859 switch (Name[2]) {
2860 default: return -1;
2861 case '0': return 10;
2862 case '1': return 11;
2863 case '2': return 12;
2864 case '3': return 13;
2865 case '4': return 14;
2866 case '5': return 15;
2867 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002868 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002869}
2870
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002871/// parseITCondCode - Try to parse a condition code for an IT instruction.
2872ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2873parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2874 SMLoc S = Parser.getTok().getLoc();
2875 const AsmToken &Tok = Parser.getTok();
2876 if (!Tok.is(AsmToken::Identifier))
2877 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002878 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002879 .Case("eq", ARMCC::EQ)
2880 .Case("ne", ARMCC::NE)
2881 .Case("hs", ARMCC::HS)
2882 .Case("cs", ARMCC::HS)
2883 .Case("lo", ARMCC::LO)
2884 .Case("cc", ARMCC::LO)
2885 .Case("mi", ARMCC::MI)
2886 .Case("pl", ARMCC::PL)
2887 .Case("vs", ARMCC::VS)
2888 .Case("vc", ARMCC::VC)
2889 .Case("hi", ARMCC::HI)
2890 .Case("ls", ARMCC::LS)
2891 .Case("ge", ARMCC::GE)
2892 .Case("lt", ARMCC::LT)
2893 .Case("gt", ARMCC::GT)
2894 .Case("le", ARMCC::LE)
2895 .Case("al", ARMCC::AL)
2896 .Default(~0U);
2897 if (CC == ~0U)
2898 return MatchOperand_NoMatch;
2899 Parser.Lex(); // Eat the token.
2900
2901 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2902
2903 return MatchOperand_Success;
2904}
2905
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002906/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002907/// token must be an Identifier when called, and if it is a coprocessor
2908/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002909ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002910parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002911 SMLoc S = Parser.getTok().getLoc();
2912 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002913 if (Tok.isNot(AsmToken::Identifier))
2914 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002915
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002916 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002917 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002918 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002919
2920 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002921 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002922 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002923}
2924
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002925/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002926/// token must be an Identifier when called, and if it is a coprocessor
2927/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002928ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002929parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002930 SMLoc S = Parser.getTok().getLoc();
2931 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002932 if (Tok.isNot(AsmToken::Identifier))
2933 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002934
2935 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2936 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002937 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002938
2939 Parser.Lex(); // Eat identifier token.
2940 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002941 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002942}
2943
Jim Grosbach48399582011-10-12 17:34:41 +00002944/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2945/// coproc_option : '{' imm0_255 '}'
2946ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2947parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2948 SMLoc S = Parser.getTok().getLoc();
2949
2950 // If this isn't a '{', this isn't a coprocessor immediate operand.
2951 if (Parser.getTok().isNot(AsmToken::LCurly))
2952 return MatchOperand_NoMatch;
2953 Parser.Lex(); // Eat the '{'
2954
2955 const MCExpr *Expr;
2956 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002957 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002958 Error(Loc, "illegal expression");
2959 return MatchOperand_ParseFail;
2960 }
2961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2962 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2963 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2964 return MatchOperand_ParseFail;
2965 }
2966 int Val = CE->getValue();
2967
2968 // Check for and consume the closing '}'
2969 if (Parser.getTok().isNot(AsmToken::RCurly))
2970 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002971 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002972 Parser.Lex(); // Eat the '}'
2973
2974 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2975 return MatchOperand_Success;
2976}
2977
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002978// For register list parsing, we need to map from raw GPR register numbering
2979// to the enumeration values. The enumeration values aren't sorted by
2980// register number due to our using "sp", "lr" and "pc" as canonical names.
2981static unsigned getNextRegister(unsigned Reg) {
2982 // If this is a GPR, we need to do it manually, otherwise we can rely
2983 // on the sort ordering of the enumeration since the other reg-classes
2984 // are sane.
2985 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2986 return Reg + 1;
2987 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002988 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002989 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2990 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2991 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2992 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2993 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2994 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2995 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2996 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2997 }
2998}
2999
Jim Grosbach85a23432011-11-11 21:27:40 +00003000// Return the low-subreg of a given Q register.
3001static unsigned getDRegFromQReg(unsigned QReg) {
3002 switch (QReg) {
3003 default: llvm_unreachable("expected a Q register!");
3004 case ARM::Q0: return ARM::D0;
3005 case ARM::Q1: return ARM::D2;
3006 case ARM::Q2: return ARM::D4;
3007 case ARM::Q3: return ARM::D6;
3008 case ARM::Q4: return ARM::D8;
3009 case ARM::Q5: return ARM::D10;
3010 case ARM::Q6: return ARM::D12;
3011 case ARM::Q7: return ARM::D14;
3012 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003013 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003014 case ARM::Q10: return ARM::D20;
3015 case ARM::Q11: return ARM::D22;
3016 case ARM::Q12: return ARM::D24;
3017 case ARM::Q13: return ARM::D26;
3018 case ARM::Q14: return ARM::D28;
3019 case ARM::Q15: return ARM::D30;
3020 }
3021}
3022
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003023/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003024bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003025parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003026 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003027 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003028 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003029 Parser.Lex(); // Eat '{' token.
3030 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003031
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003032 // Check the first register in the list to see what register class
3033 // this is a list of.
3034 int Reg = tryParseRegister();
3035 if (Reg == -1)
3036 return Error(RegLoc, "register expected");
3037
Jim Grosbach85a23432011-11-11 21:27:40 +00003038 // The reglist instructions have at most 16 registers, so reserve
3039 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003040 int EReg = 0;
3041 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003042
3043 // Allow Q regs and just interpret them as the two D sub-registers.
3044 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3045 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003046 EReg = MRI->getEncodingValue(Reg);
3047 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003048 ++Reg;
3049 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003050 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003051 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3052 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3053 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3054 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3055 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3056 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3057 else
3058 return Error(RegLoc, "invalid register in register list");
3059
Jim Grosbach85a23432011-11-11 21:27:40 +00003060 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003061 EReg = MRI->getEncodingValue(Reg);
3062 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003063
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003064 // This starts immediately after the first register token in the list,
3065 // so we can see either a comma or a minus (range separator) as a legal
3066 // next token.
3067 while (Parser.getTok().is(AsmToken::Comma) ||
3068 Parser.getTok().is(AsmToken::Minus)) {
3069 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003070 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003071 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003072 int EndReg = tryParseRegister();
3073 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003074 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003075 // Allow Q regs and just interpret them as the two D sub-registers.
3076 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3077 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003078 // If the register is the same as the start reg, there's nothing
3079 // more to do.
3080 if (Reg == EndReg)
3081 continue;
3082 // The register must be in the same register class as the first.
3083 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003084 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003085 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003086 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003087 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003088
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003089 // Add all the registers in the range to the register list.
3090 while (Reg != EndReg) {
3091 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003092 EReg = MRI->getEncodingValue(Reg);
3093 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003094 }
3095 continue;
3096 }
3097 Parser.Lex(); // Eat the comma.
3098 RegLoc = Parser.getTok().getLoc();
3099 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003100 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003101 Reg = tryParseRegister();
3102 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003103 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003104 // Allow Q regs and just interpret them as the two D sub-registers.
3105 bool isQReg = false;
3106 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3107 Reg = getDRegFromQReg(Reg);
3108 isQReg = true;
3109 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003110 // The register must be in the same register class as the first.
3111 if (!RC->contains(Reg))
3112 return Error(RegLoc, "invalid register in register list");
3113 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003114 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003115 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3116 Warning(RegLoc, "register list not in ascending order");
3117 else
3118 return Error(RegLoc, "register list not in ascending order");
3119 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003120 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003121 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3122 ") in register list");
3123 continue;
3124 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003125 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003126 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3127 Reg != OldReg + 1)
3128 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003129 EReg = MRI->getEncodingValue(Reg);
3130 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3131 if (isQReg) {
3132 EReg = MRI->getEncodingValue(++Reg);
3133 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3134 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003135 }
3136
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003137 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003138 return Error(Parser.getTok().getLoc(), "'}' expected");
3139 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003140 Parser.Lex(); // Eat '}' token.
3141
Jim Grosbach18bf3632011-12-13 21:48:29 +00003142 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003143 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003144
3145 // The ARM system instruction variants for LDM/STM have a '^' token here.
3146 if (Parser.getTok().is(AsmToken::Caret)) {
3147 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3148 Parser.Lex(); // Eat '^' token.
3149 }
3150
Bill Wendling2063b842010-11-18 23:43:05 +00003151 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003152}
3153
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003154// Helper function to parse the lane index for vector lists.
3155ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003156parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003157 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003158 if (Parser.getTok().is(AsmToken::LBrac)) {
3159 Parser.Lex(); // Eat the '['.
3160 if (Parser.getTok().is(AsmToken::RBrac)) {
3161 // "Dn[]" is the 'all lanes' syntax.
3162 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003163 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003164 Parser.Lex(); // Eat the ']'.
3165 return MatchOperand_Success;
3166 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003167
3168 // There's an optional '#' token here. Normally there wouldn't be, but
3169 // inline assemble puts one in, and it's friendly to accept that.
3170 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003171 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003172
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003173 const MCExpr *LaneIndex;
3174 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003175 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003176 Error(Loc, "illegal expression");
3177 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003178 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003179 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3180 if (!CE) {
3181 Error(Loc, "lane index must be empty or an integer");
3182 return MatchOperand_ParseFail;
3183 }
3184 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3185 Error(Parser.getTok().getLoc(), "']' expected");
3186 return MatchOperand_ParseFail;
3187 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003188 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003189 Parser.Lex(); // Eat the ']'.
3190 int64_t Val = CE->getValue();
3191
3192 // FIXME: Make this range check context sensitive for .8, .16, .32.
3193 if (Val < 0 || Val > 7) {
3194 Error(Parser.getTok().getLoc(), "lane index out of range");
3195 return MatchOperand_ParseFail;
3196 }
3197 Index = Val;
3198 LaneKind = IndexedLane;
3199 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003200 }
3201 LaneKind = NoLanes;
3202 return MatchOperand_Success;
3203}
3204
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003205// parse a vector register list
3206ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3207parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003208 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003209 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003210 SMLoc S = Parser.getTok().getLoc();
3211 // As an extension (to match gas), support a plain D register or Q register
3212 // (without encosing curly braces) as a single or double entry list,
3213 // respectively.
3214 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003215 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003216 int Reg = tryParseRegister();
3217 if (Reg == -1)
3218 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003219 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003220 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 if (Res != MatchOperand_Success)
3222 return Res;
3223 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003224 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003225 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 break;
3227 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003228 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3229 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003230 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003231 case IndexedLane:
3232 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003233 LaneIndex,
3234 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003235 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003236 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003237 return MatchOperand_Success;
3238 }
3239 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3240 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003241 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003242 if (Res != MatchOperand_Success)
3243 return Res;
3244 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003245 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003246 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003247 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003248 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003249 break;
3250 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003251 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3252 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003253 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3254 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003255 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003256 case IndexedLane:
3257 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003258 LaneIndex,
3259 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003260 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003261 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003262 return MatchOperand_Success;
3263 }
3264 Error(S, "vector register expected");
3265 return MatchOperand_ParseFail;
3266 }
3267
3268 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003269 return MatchOperand_NoMatch;
3270
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003271 Parser.Lex(); // Eat '{' token.
3272 SMLoc RegLoc = Parser.getTok().getLoc();
3273
3274 int Reg = tryParseRegister();
3275 if (Reg == -1) {
3276 Error(RegLoc, "register expected");
3277 return MatchOperand_ParseFail;
3278 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003279 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003280 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003281 unsigned FirstReg = Reg;
3282 // The list is of D registers, but we also allow Q regs and just interpret
3283 // them as the two D sub-registers.
3284 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3285 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003286 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3287 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003288 ++Reg;
3289 ++Count;
3290 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003291
3292 SMLoc E;
3293 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003294 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003295
Jim Grosbache891fe82011-11-15 23:19:15 +00003296 while (Parser.getTok().is(AsmToken::Comma) ||
3297 Parser.getTok().is(AsmToken::Minus)) {
3298 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003299 if (!Spacing)
3300 Spacing = 1; // Register range implies a single spaced list.
3301 else if (Spacing == 2) {
3302 Error(Parser.getTok().getLoc(),
3303 "sequential registers in double spaced list");
3304 return MatchOperand_ParseFail;
3305 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003306 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003307 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003308 int EndReg = tryParseRegister();
3309 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003310 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003311 return MatchOperand_ParseFail;
3312 }
3313 // Allow Q regs and just interpret them as the two D sub-registers.
3314 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3315 EndReg = getDRegFromQReg(EndReg) + 1;
3316 // If the register is the same as the start reg, there's nothing
3317 // more to do.
3318 if (Reg == EndReg)
3319 continue;
3320 // The register must be in the same register class as the first.
3321 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003322 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003323 return MatchOperand_ParseFail;
3324 }
3325 // Ranges must go from low to high.
3326 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003327 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003328 return MatchOperand_ParseFail;
3329 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003330 // Parse the lane specifier if present.
3331 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003332 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003333 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3334 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003335 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003336 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003337 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003338 return MatchOperand_ParseFail;
3339 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003340
3341 // Add all the registers in the range to the register list.
3342 Count += EndReg - Reg;
3343 Reg = EndReg;
3344 continue;
3345 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003346 Parser.Lex(); // Eat the comma.
3347 RegLoc = Parser.getTok().getLoc();
3348 int OldReg = Reg;
3349 Reg = tryParseRegister();
3350 if (Reg == -1) {
3351 Error(RegLoc, "register expected");
3352 return MatchOperand_ParseFail;
3353 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003354 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003355 // It's OK to use the enumeration values directly here rather, as the
3356 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003357 //
3358 // The list is of D registers, but we also allow Q regs and just interpret
3359 // them as the two D sub-registers.
3360 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003361 if (!Spacing)
3362 Spacing = 1; // Register range implies a single spaced list.
3363 else if (Spacing == 2) {
3364 Error(RegLoc,
3365 "invalid register in double-spaced list (must be 'D' register')");
3366 return MatchOperand_ParseFail;
3367 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003368 Reg = getDRegFromQReg(Reg);
3369 if (Reg != OldReg + 1) {
3370 Error(RegLoc, "non-contiguous register range");
3371 return MatchOperand_ParseFail;
3372 }
3373 ++Reg;
3374 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003375 // Parse the lane specifier if present.
3376 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003377 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003378 SMLoc LaneLoc = Parser.getTok().getLoc();
3379 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3380 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003381 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003382 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003383 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003384 return MatchOperand_ParseFail;
3385 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003386 continue;
3387 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003388 // Normal D register.
3389 // Figure out the register spacing (single or double) of the list if
3390 // we don't know it already.
3391 if (!Spacing)
3392 Spacing = 1 + (Reg == OldReg + 2);
3393
3394 // Just check that it's contiguous and keep going.
3395 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003396 Error(RegLoc, "non-contiguous register range");
3397 return MatchOperand_ParseFail;
3398 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003399 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003400 // Parse the lane specifier if present.
3401 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003402 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003403 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003404 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003405 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003406 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003407 Error(EndLoc, "mismatched lane index in register list");
3408 return MatchOperand_ParseFail;
3409 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003410 }
3411
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003412 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003413 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003414 return MatchOperand_ParseFail;
3415 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003416 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003417 Parser.Lex(); // Eat '}' token.
3418
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003419 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003420 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003421 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003422 // composite register classes.
3423 if (Count == 2) {
3424 const MCRegisterClass *RC = (Spacing == 1) ?
3425 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3426 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3427 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3428 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003429
Jim Grosbach2f50e922011-12-15 21:44:33 +00003430 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3431 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003432 break;
3433 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003434 // Two-register operands have been converted to the
3435 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003436 if (Count == 2) {
3437 const MCRegisterClass *RC = (Spacing == 1) ?
3438 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3439 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003440 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3441 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003442 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003443 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003444 S, E));
3445 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003446 case IndexedLane:
3447 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003448 LaneIndex,
3449 (Spacing == 2),
3450 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003451 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003452 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003453 return MatchOperand_Success;
3454}
3455
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003456/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003457ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003458parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003459 SMLoc S = Parser.getTok().getLoc();
3460 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003461 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003462
Jiangning Liu288e1af2012-08-02 08:21:27 +00003463 if (Tok.is(AsmToken::Identifier)) {
3464 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003465
Jiangning Liu288e1af2012-08-02 08:21:27 +00003466 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3467 .Case("sy", ARM_MB::SY)
3468 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003469 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003470 .Case("sh", ARM_MB::ISH)
3471 .Case("ish", ARM_MB::ISH)
3472 .Case("shst", ARM_MB::ISHST)
3473 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003474 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003475 .Case("nsh", ARM_MB::NSH)
3476 .Case("un", ARM_MB::NSH)
3477 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003478 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003479 .Case("unst", ARM_MB::NSHST)
3480 .Case("osh", ARM_MB::OSH)
3481 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003482 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003483 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003484
Joey Gouly926d3f52013-09-05 15:35:24 +00003485 // ishld, oshld, nshld and ld are only available from ARMv8.
3486 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3487 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3488 Opt = ~0U;
3489
Jiangning Liu288e1af2012-08-02 08:21:27 +00003490 if (Opt == ~0U)
3491 return MatchOperand_NoMatch;
3492
3493 Parser.Lex(); // Eat identifier token.
3494 } else if (Tok.is(AsmToken::Hash) ||
3495 Tok.is(AsmToken::Dollar) ||
3496 Tok.is(AsmToken::Integer)) {
3497 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003498 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003499 SMLoc Loc = Parser.getTok().getLoc();
3500
3501 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003502 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003503 Error(Loc, "illegal expression");
3504 return MatchOperand_ParseFail;
3505 }
3506
3507 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3508 if (!CE) {
3509 Error(Loc, "constant expression expected");
3510 return MatchOperand_ParseFail;
3511 }
3512
3513 int Val = CE->getValue();
3514 if (Val & ~0xf) {
3515 Error(Loc, "immediate value out of range");
3516 return MatchOperand_ParseFail;
3517 }
3518
3519 Opt = ARM_MB::RESERVED_0 + Val;
3520 } else
3521 return MatchOperand_ParseFail;
3522
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003523 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003524 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003525}
3526
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003527/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3528ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3529parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3530 SMLoc S = Parser.getTok().getLoc();
3531 const AsmToken &Tok = Parser.getTok();
3532 unsigned Opt;
3533
3534 if (Tok.is(AsmToken::Identifier)) {
3535 StringRef OptStr = Tok.getString();
3536
3537 if (OptStr.lower() == "sy")
3538 Opt = ARM_ISB::SY;
3539 else
3540 return MatchOperand_NoMatch;
3541
3542 Parser.Lex(); // Eat identifier token.
3543 } else if (Tok.is(AsmToken::Hash) ||
3544 Tok.is(AsmToken::Dollar) ||
3545 Tok.is(AsmToken::Integer)) {
3546 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003547 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003548 SMLoc Loc = Parser.getTok().getLoc();
3549
3550 const MCExpr *ISBarrierID;
3551 if (getParser().parseExpression(ISBarrierID)) {
3552 Error(Loc, "illegal expression");
3553 return MatchOperand_ParseFail;
3554 }
3555
3556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3557 if (!CE) {
3558 Error(Loc, "constant expression expected");
3559 return MatchOperand_ParseFail;
3560 }
3561
3562 int Val = CE->getValue();
3563 if (Val & ~0xf) {
3564 Error(Loc, "immediate value out of range");
3565 return MatchOperand_ParseFail;
3566 }
3567
3568 Opt = ARM_ISB::RESERVED_0 + Val;
3569 } else
3570 return MatchOperand_ParseFail;
3571
3572 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3573 (ARM_ISB::InstSyncBOpt)Opt, S));
3574 return MatchOperand_Success;
3575}
3576
3577
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003578/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003579ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003580parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003581 SMLoc S = Parser.getTok().getLoc();
3582 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003583 if (!Tok.is(AsmToken::Identifier))
3584 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003585 StringRef IFlagsStr = Tok.getString();
3586
Owen Anderson10c5b122011-10-05 17:16:40 +00003587 // An iflags string of "none" is interpreted to mean that none of the AIF
3588 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003589 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003590 if (IFlagsStr != "none") {
3591 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3592 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3593 .Case("a", ARM_PROC::A)
3594 .Case("i", ARM_PROC::I)
3595 .Case("f", ARM_PROC::F)
3596 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003597
Owen Anderson10c5b122011-10-05 17:16:40 +00003598 // If some specific iflag is already set, it means that some letter is
3599 // present more than once, this is not acceptable.
3600 if (Flag == ~0U || (IFlags & Flag))
3601 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003602
Owen Anderson10c5b122011-10-05 17:16:40 +00003603 IFlags |= Flag;
3604 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003605 }
3606
3607 Parser.Lex(); // Eat identifier token.
3608 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3609 return MatchOperand_Success;
3610}
3611
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003612/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003613ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003614parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003615 SMLoc S = Parser.getTok().getLoc();
3616 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003617 if (!Tok.is(AsmToken::Identifier))
3618 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003619 StringRef Mask = Tok.getString();
3620
James Molloy21efa7d2011-09-28 14:21:38 +00003621 if (isMClass()) {
3622 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003623 std::string Name = Mask.lower();
3624 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003625 // Note: in the documentation:
3626 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3627 // for MSR APSR_nzcvq.
3628 // but we do make it an alias here. This is so to get the "mask encoding"
3629 // bits correct on MSR APSR writes.
3630 //
3631 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3632 // should really only be allowed when writing a special register. Note
3633 // they get dropped in the MRS instruction reading a special register as
3634 // the SYSm field is only 8 bits.
3635 //
3636 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3637 // includes the DSP extension but that is not checked.
3638 .Case("apsr", 0x800)
3639 .Case("apsr_nzcvq", 0x800)
3640 .Case("apsr_g", 0x400)
3641 .Case("apsr_nzcvqg", 0xc00)
3642 .Case("iapsr", 0x801)
3643 .Case("iapsr_nzcvq", 0x801)
3644 .Case("iapsr_g", 0x401)
3645 .Case("iapsr_nzcvqg", 0xc01)
3646 .Case("eapsr", 0x802)
3647 .Case("eapsr_nzcvq", 0x802)
3648 .Case("eapsr_g", 0x402)
3649 .Case("eapsr_nzcvqg", 0xc02)
3650 .Case("xpsr", 0x803)
3651 .Case("xpsr_nzcvq", 0x803)
3652 .Case("xpsr_g", 0x403)
3653 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003654 .Case("ipsr", 0x805)
3655 .Case("epsr", 0x806)
3656 .Case("iepsr", 0x807)
3657 .Case("msp", 0x808)
3658 .Case("psp", 0x809)
3659 .Case("primask", 0x810)
3660 .Case("basepri", 0x811)
3661 .Case("basepri_max", 0x812)
3662 .Case("faultmask", 0x813)
3663 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003664 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003665
James Molloy21efa7d2011-09-28 14:21:38 +00003666 if (FlagsVal == ~0U)
3667 return MatchOperand_NoMatch;
3668
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003669 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003670 // basepri, basepri_max and faultmask only valid for V7m.
3671 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003672
James Molloy21efa7d2011-09-28 14:21:38 +00003673 Parser.Lex(); // Eat identifier token.
3674 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3675 return MatchOperand_Success;
3676 }
3677
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003678 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3679 size_t Start = 0, Next = Mask.find('_');
3680 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003681 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003682 if (Next != StringRef::npos)
3683 Flags = Mask.slice(Next+1, Mask.size());
3684
3685 // FlagsVal contains the complete mask:
3686 // 3-0: Mask
3687 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3688 unsigned FlagsVal = 0;
3689
3690 if (SpecReg == "apsr") {
3691 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003692 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003693 .Case("g", 0x4) // same as CPSR_s
3694 .Case("nzcvqg", 0xc) // same as CPSR_fs
3695 .Default(~0U);
3696
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003697 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003698 if (!Flags.empty())
3699 return MatchOperand_NoMatch;
3700 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003701 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003702 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003703 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003704 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3705 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003706 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003707 for (int i = 0, e = Flags.size(); i != e; ++i) {
3708 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3709 .Case("c", 1)
3710 .Case("x", 2)
3711 .Case("s", 4)
3712 .Case("f", 8)
3713 .Default(~0U);
3714
3715 // If some specific flag is already set, it means that some letter is
3716 // present more than once, this is not acceptable.
3717 if (FlagsVal == ~0U || (FlagsVal & Flag))
3718 return MatchOperand_NoMatch;
3719 FlagsVal |= Flag;
3720 }
3721 } else // No match for special register.
3722 return MatchOperand_NoMatch;
3723
Owen Anderson03a173e2011-10-21 18:43:28 +00003724 // Special register without flags is NOT equivalent to "fc" flags.
3725 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3726 // two lines would enable gas compatibility at the expense of breaking
3727 // round-tripping.
3728 //
3729 // if (!FlagsVal)
3730 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003731
3732 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3733 if (SpecReg == "spsr")
3734 FlagsVal |= 16;
3735
3736 Parser.Lex(); // Eat identifier token.
3737 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3738 return MatchOperand_Success;
3739}
3740
Jim Grosbach27c1e252011-07-21 17:23:04 +00003741ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3742parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3743 int Low, int High) {
3744 const AsmToken &Tok = Parser.getTok();
3745 if (Tok.isNot(AsmToken::Identifier)) {
3746 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3747 return MatchOperand_ParseFail;
3748 }
3749 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003750 std::string LowerOp = Op.lower();
3751 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003752 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3753 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3754 return MatchOperand_ParseFail;
3755 }
3756 Parser.Lex(); // Eat shift type token.
3757
3758 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003759 if (Parser.getTok().isNot(AsmToken::Hash) &&
3760 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003761 Error(Parser.getTok().getLoc(), "'#' expected");
3762 return MatchOperand_ParseFail;
3763 }
3764 Parser.Lex(); // Eat hash token.
3765
3766 const MCExpr *ShiftAmount;
3767 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003768 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003769 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003770 Error(Loc, "illegal expression");
3771 return MatchOperand_ParseFail;
3772 }
3773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3774 if (!CE) {
3775 Error(Loc, "constant expression expected");
3776 return MatchOperand_ParseFail;
3777 }
3778 int Val = CE->getValue();
3779 if (Val < Low || Val > High) {
3780 Error(Loc, "immediate value out of range");
3781 return MatchOperand_ParseFail;
3782 }
3783
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003784 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003785
3786 return MatchOperand_Success;
3787}
3788
Jim Grosbach0a547702011-07-22 17:44:50 +00003789ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3790parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3791 const AsmToken &Tok = Parser.getTok();
3792 SMLoc S = Tok.getLoc();
3793 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003794 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003795 return MatchOperand_ParseFail;
3796 }
Tim Northover4d141442013-05-31 15:58:45 +00003797 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003798 .Case("be", 1)
3799 .Case("le", 0)
3800 .Default(-1);
3801 Parser.Lex(); // Eat the token.
3802
3803 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003804 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003805 return MatchOperand_ParseFail;
3806 }
3807 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3808 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003809 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003810 return MatchOperand_Success;
3811}
3812
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003813/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3814/// instructions. Legal values are:
3815/// lsl #n 'n' in [0,31]
3816/// asr #n 'n' in [1,32]
3817/// n == 32 encoded as n == 0.
3818ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3819parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3820 const AsmToken &Tok = Parser.getTok();
3821 SMLoc S = Tok.getLoc();
3822 if (Tok.isNot(AsmToken::Identifier)) {
3823 Error(S, "shift operator 'asr' or 'lsl' expected");
3824 return MatchOperand_ParseFail;
3825 }
3826 StringRef ShiftName = Tok.getString();
3827 bool isASR;
3828 if (ShiftName == "lsl" || ShiftName == "LSL")
3829 isASR = false;
3830 else if (ShiftName == "asr" || ShiftName == "ASR")
3831 isASR = true;
3832 else {
3833 Error(S, "shift operator 'asr' or 'lsl' expected");
3834 return MatchOperand_ParseFail;
3835 }
3836 Parser.Lex(); // Eat the operator.
3837
3838 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003839 if (Parser.getTok().isNot(AsmToken::Hash) &&
3840 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003841 Error(Parser.getTok().getLoc(), "'#' expected");
3842 return MatchOperand_ParseFail;
3843 }
3844 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003845 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003846
3847 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003848 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003849 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003850 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003851 return MatchOperand_ParseFail;
3852 }
3853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3854 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003855 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003856 return MatchOperand_ParseFail;
3857 }
3858
3859 int64_t Val = CE->getValue();
3860 if (isASR) {
3861 // Shift amount must be in [1,32]
3862 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003863 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003864 return MatchOperand_ParseFail;
3865 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003866 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3867 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003868 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003869 return MatchOperand_ParseFail;
3870 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003871 if (Val == 32) Val = 0;
3872 } else {
3873 // Shift amount must be in [1,32]
3874 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003875 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003876 return MatchOperand_ParseFail;
3877 }
3878 }
3879
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003880 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003881
3882 return MatchOperand_Success;
3883}
3884
Jim Grosbach833b9d32011-07-27 20:15:40 +00003885/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3886/// of instructions. Legal values are:
3887/// ror #n 'n' in {0, 8, 16, 24}
3888ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3889parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3890 const AsmToken &Tok = Parser.getTok();
3891 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003892 if (Tok.isNot(AsmToken::Identifier))
3893 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003894 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003895 if (ShiftName != "ror" && ShiftName != "ROR")
3896 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003897 Parser.Lex(); // Eat the operator.
3898
3899 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003900 if (Parser.getTok().isNot(AsmToken::Hash) &&
3901 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003902 Error(Parser.getTok().getLoc(), "'#' expected");
3903 return MatchOperand_ParseFail;
3904 }
3905 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003906 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003907
3908 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003909 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003910 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003911 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003912 return MatchOperand_ParseFail;
3913 }
3914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3915 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003916 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003917 return MatchOperand_ParseFail;
3918 }
3919
3920 int64_t Val = CE->getValue();
3921 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3922 // normally, zero is represented in asm by omitting the rotate operand
3923 // entirely.
3924 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003925 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003926 return MatchOperand_ParseFail;
3927 }
3928
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003929 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003930
3931 return MatchOperand_Success;
3932}
3933
Jim Grosbach864b6092011-07-28 21:34:26 +00003934ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3935parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3936 SMLoc S = Parser.getTok().getLoc();
3937 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003938 if (Parser.getTok().isNot(AsmToken::Hash) &&
3939 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003940 Error(Parser.getTok().getLoc(), "'#' expected");
3941 return MatchOperand_ParseFail;
3942 }
3943 Parser.Lex(); // Eat hash token.
3944
3945 const MCExpr *LSBExpr;
3946 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003947 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003948 Error(E, "malformed immediate expression");
3949 return MatchOperand_ParseFail;
3950 }
3951 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3952 if (!CE) {
3953 Error(E, "'lsb' operand must be an immediate");
3954 return MatchOperand_ParseFail;
3955 }
3956
3957 int64_t LSB = CE->getValue();
3958 // The LSB must be in the range [0,31]
3959 if (LSB < 0 || LSB > 31) {
3960 Error(E, "'lsb' operand must be in the range [0,31]");
3961 return MatchOperand_ParseFail;
3962 }
3963 E = Parser.getTok().getLoc();
3964
3965 // Expect another immediate operand.
3966 if (Parser.getTok().isNot(AsmToken::Comma)) {
3967 Error(Parser.getTok().getLoc(), "too few operands");
3968 return MatchOperand_ParseFail;
3969 }
3970 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003971 if (Parser.getTok().isNot(AsmToken::Hash) &&
3972 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003973 Error(Parser.getTok().getLoc(), "'#' expected");
3974 return MatchOperand_ParseFail;
3975 }
3976 Parser.Lex(); // Eat hash token.
3977
3978 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003979 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003980 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003981 Error(E, "malformed immediate expression");
3982 return MatchOperand_ParseFail;
3983 }
3984 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3985 if (!CE) {
3986 Error(E, "'width' operand must be an immediate");
3987 return MatchOperand_ParseFail;
3988 }
3989
3990 int64_t Width = CE->getValue();
3991 // The LSB must be in the range [1,32-lsb]
3992 if (Width < 1 || Width > 32 - LSB) {
3993 Error(E, "'width' operand must be in the range [1,32-lsb]");
3994 return MatchOperand_ParseFail;
3995 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003996
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003997 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003998
3999 return MatchOperand_Success;
4000}
4001
Jim Grosbachd3595712011-08-03 23:50:40 +00004002ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4003parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4004 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004005 // postidx_reg := '+' register {, shift}
4006 // | '-' register {, shift}
4007 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004008
4009 // This method must return MatchOperand_NoMatch without consuming any tokens
4010 // in the case where there is no match, as other alternatives take other
4011 // parse methods.
4012 AsmToken Tok = Parser.getTok();
4013 SMLoc S = Tok.getLoc();
4014 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004015 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004016 if (Tok.is(AsmToken::Plus)) {
4017 Parser.Lex(); // Eat the '+' token.
4018 haveEaten = true;
4019 } else if (Tok.is(AsmToken::Minus)) {
4020 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004021 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004022 haveEaten = true;
4023 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004024
4025 SMLoc E = Parser.getTok().getEndLoc();
4026 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004027 if (Reg == -1) {
4028 if (!haveEaten)
4029 return MatchOperand_NoMatch;
4030 Error(Parser.getTok().getLoc(), "register expected");
4031 return MatchOperand_ParseFail;
4032 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004033
Jim Grosbachc320c852011-08-05 21:28:30 +00004034 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4035 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004036 if (Parser.getTok().is(AsmToken::Comma)) {
4037 Parser.Lex(); // Eat the ','.
4038 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4039 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004040
4041 // FIXME: Only approximates end...may include intervening whitespace.
4042 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004043 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004044
4045 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4046 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004047
4048 return MatchOperand_Success;
4049}
4050
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004051ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4052parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4053 // Check for a post-index addressing register operand. Specifically:
4054 // am3offset := '+' register
4055 // | '-' register
4056 // | register
4057 // | # imm
4058 // | # + imm
4059 // | # - imm
4060
4061 // This method must return MatchOperand_NoMatch without consuming any tokens
4062 // in the case where there is no match, as other alternatives take other
4063 // parse methods.
4064 AsmToken Tok = Parser.getTok();
4065 SMLoc S = Tok.getLoc();
4066
4067 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004068 if (Parser.getTok().is(AsmToken::Hash) ||
4069 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004070 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004071 // Explicitly look for a '-', as we need to encode negative zero
4072 // differently.
4073 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4074 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004075 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004076 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004077 return MatchOperand_ParseFail;
4078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4079 if (!CE) {
4080 Error(S, "constant expression expected");
4081 return MatchOperand_ParseFail;
4082 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004083 // Negative zero is encoded as the flag value INT32_MIN.
4084 int32_t Val = CE->getValue();
4085 if (isNegative && Val == 0)
4086 Val = INT32_MIN;
4087
4088 Operands.push_back(
4089 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4090
4091 return MatchOperand_Success;
4092 }
4093
4094
4095 bool haveEaten = false;
4096 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004097 if (Tok.is(AsmToken::Plus)) {
4098 Parser.Lex(); // Eat the '+' token.
4099 haveEaten = true;
4100 } else if (Tok.is(AsmToken::Minus)) {
4101 Parser.Lex(); // Eat the '-' token.
4102 isAdd = false;
4103 haveEaten = true;
4104 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004105
4106 Tok = Parser.getTok();
4107 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004108 if (Reg == -1) {
4109 if (!haveEaten)
4110 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004111 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004112 return MatchOperand_ParseFail;
4113 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004114
4115 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004116 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004117
4118 return MatchOperand_Success;
4119}
4120
Tim Northovereb5e4d52013-07-22 09:06:12 +00004121/// Convert parsed operands to MCInst. Needed here because this instruction
4122/// only has two register operands, but multiplication is commutative so
4123/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004124void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004125cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004126 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004127 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4128 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004129 // If we have a three-operand form, make sure to set Rn to be the operand
4130 // that isn't the same as Rd.
4131 unsigned RegOp = 4;
4132 if (Operands.size() == 6 &&
4133 ((ARMOperand*)Operands[4])->getReg() ==
4134 ((ARMOperand*)Operands[3])->getReg())
4135 RegOp = 5;
4136 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4137 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004138 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004139}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004140
Mihai Popaad18d3c2013-08-09 10:38:32 +00004141void ARMAsmParser::
4142cvtThumbBranches(MCInst &Inst,
4143 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4144 int CondOp = -1, ImmOp = -1;
4145 switch(Inst.getOpcode()) {
4146 case ARM::tB:
4147 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4148
4149 case ARM::t2B:
4150 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4151
4152 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4153 }
4154 // first decide whether or not the branch should be conditional
4155 // by looking at it's location relative to an IT block
4156 if(inITBlock()) {
4157 // inside an IT block we cannot have any conditional branches. any
4158 // such instructions needs to be converted to unconditional form
4159 switch(Inst.getOpcode()) {
4160 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4161 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4162 }
4163 } else {
4164 // outside IT blocks we can only have unconditional branches with AL
4165 // condition code or conditional branches with non-AL condition code
4166 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4167 switch(Inst.getOpcode()) {
4168 case ARM::tB:
4169 case ARM::tBcc:
4170 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4171 break;
4172 case ARM::t2B:
4173 case ARM::t2Bcc:
4174 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4175 break;
4176 }
4177 }
4178
4179 // now decide on encoding size based on branch target range
4180 switch(Inst.getOpcode()) {
4181 // classify tB as either t2B or t1B based on range of immediate operand
4182 case ARM::tB: {
4183 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4184 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4185 Inst.setOpcode(ARM::t2B);
4186 break;
4187 }
4188 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4189 case ARM::tBcc: {
4190 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4191 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4192 Inst.setOpcode(ARM::t2Bcc);
4193 break;
4194 }
4195 }
4196 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4197 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4198}
4199
Bill Wendlinge18980a2010-11-06 22:36:58 +00004200/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004201/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004202bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004203parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004204 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004205 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004206 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004207 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004208 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004209
Sean Callanan936b0d32010-01-19 21:44:56 +00004210 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004211 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004212 if (BaseRegNum == -1)
4213 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004214
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004215 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004216 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004217 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4218 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004219 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004220
Jim Grosbachd3595712011-08-03 23:50:40 +00004221 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004222 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004223 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004224
Jim Grosbachd3595712011-08-03 23:50:40 +00004225 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004226 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004227
Jim Grosbach40700e02011-09-19 18:42:21 +00004228 // If there's a pre-indexing writeback marker, '!', just add it as a token
4229 // operand. It's rather odd, but syntactically valid.
4230 if (Parser.getTok().is(AsmToken::Exclaim)) {
4231 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4232 Parser.Lex(); // Eat the '!'.
4233 }
4234
Jim Grosbachd3595712011-08-03 23:50:40 +00004235 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004236 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004237
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004238 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4239 "Lost colon or comma in memory operand?!");
4240 if (Tok.is(AsmToken::Comma)) {
4241 Parser.Lex(); // Eat the comma.
4242 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004243
Jim Grosbacha95ec992011-10-11 17:29:55 +00004244 // If we have a ':', it's an alignment specifier.
4245 if (Parser.getTok().is(AsmToken::Colon)) {
4246 Parser.Lex(); // Eat the ':'.
4247 E = Parser.getTok().getLoc();
4248
4249 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004250 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004251 return true;
4252
4253 // The expression has to be a constant. Memory references with relocations
4254 // don't come through here, as they use the <label> forms of the relevant
4255 // instructions.
4256 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4257 if (!CE)
4258 return Error (E, "constant expression expected");
4259
4260 unsigned Align = 0;
4261 switch (CE->getValue()) {
4262 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004263 return Error(E,
4264 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4265 case 16: Align = 2; break;
4266 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004267 case 64: Align = 8; break;
4268 case 128: Align = 16; break;
4269 case 256: Align = 32; break;
4270 }
4271
4272 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +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 Grosbacha95ec992011-10-11 17:29:55 +00004276 Parser.Lex(); // Eat right bracket token.
4277
4278 // Don't worry about range checking the value here. That's handled by
4279 // the is*() predicates.
4280 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4281 ARM_AM::no_shift, 0, Align,
4282 false, S, E));
4283
4284 // If there's a pre-indexing writeback marker, '!', just add it as a token
4285 // operand.
4286 if (Parser.getTok().is(AsmToken::Exclaim)) {
4287 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4288 Parser.Lex(); // Eat the '!'.
4289 }
4290
4291 return false;
4292 }
4293
4294 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004295 // offset. Be friendly and also accept a plain integer (without a leading
4296 // hash) for gas compatibility.
4297 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004298 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004299 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004300 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004301 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004302 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004303
Owen Anderson967674d2011-08-29 19:36:44 +00004304 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004305 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004306 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004307 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004308
4309 // The expression has to be a constant. Memory references with relocations
4310 // don't come through here, as they use the <label> forms of the relevant
4311 // instructions.
4312 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4313 if (!CE)
4314 return Error (E, "constant expression expected");
4315
Owen Anderson967674d2011-08-29 19:36:44 +00004316 // If the constant was #-0, represent it as INT32_MIN.
4317 int32_t Val = CE->getValue();
4318 if (isNegative && Val == 0)
4319 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4320
Jim Grosbachd3595712011-08-03 23:50:40 +00004321 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004322 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004323 return Error(Parser.getTok().getLoc(), "']' expected");
4324 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004325 Parser.Lex(); // Eat right bracket token.
4326
4327 // Don't worry about range checking the value here. That's handled by
4328 // the is*() predicates.
4329 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004330 ARM_AM::no_shift, 0, 0,
4331 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004332
4333 // If there's a pre-indexing writeback marker, '!', just add it as a token
4334 // operand.
4335 if (Parser.getTok().is(AsmToken::Exclaim)) {
4336 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4337 Parser.Lex(); // Eat the '!'.
4338 }
4339
4340 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004341 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004342
4343 // The register offset is optionally preceded by a '+' or '-'
4344 bool isNegative = false;
4345 if (Parser.getTok().is(AsmToken::Minus)) {
4346 isNegative = true;
4347 Parser.Lex(); // Eat the '-'.
4348 } else if (Parser.getTok().is(AsmToken::Plus)) {
4349 // Nothing to do.
4350 Parser.Lex(); // Eat the '+'.
4351 }
4352
4353 E = Parser.getTok().getLoc();
4354 int OffsetRegNum = tryParseRegister();
4355 if (OffsetRegNum == -1)
4356 return Error(E, "register expected");
4357
4358 // If there's a shift operator, handle it.
4359 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004360 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004361 if (Parser.getTok().is(AsmToken::Comma)) {
4362 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004363 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004364 return true;
4365 }
4366
4367 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004368 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004369 return Error(Parser.getTok().getLoc(), "']' expected");
4370 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004371 Parser.Lex(); // Eat right bracket token.
4372
4373 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004374 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004375 S, E));
4376
Jim Grosbachc320c852011-08-05 21:28:30 +00004377 // If there's a pre-indexing writeback marker, '!', just add it as a token
4378 // operand.
4379 if (Parser.getTok().is(AsmToken::Exclaim)) {
4380 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4381 Parser.Lex(); // Eat the '!'.
4382 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004383
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004384 return false;
4385}
4386
Jim Grosbachd3595712011-08-03 23:50:40 +00004387/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004388/// ( lsl | lsr | asr | ror ) , # shift_amount
4389/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004390/// return true if it parses a shift otherwise it returns false.
4391bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4392 unsigned &Amount) {
4393 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004394 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004395 if (Tok.isNot(AsmToken::Identifier))
4396 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004397 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004398 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4399 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004400 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004401 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004402 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004403 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004404 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004406 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004407 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004408 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004410 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004411 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004412
Jim Grosbachd3595712011-08-03 23:50:40 +00004413 // rrx stands alone.
4414 Amount = 0;
4415 if (St != ARM_AM::rrx) {
4416 Loc = Parser.getTok().getLoc();
4417 // A '#' and a shift amount.
4418 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004419 if (HashTok.isNot(AsmToken::Hash) &&
4420 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004421 return Error(HashTok.getLoc(), "'#' expected");
4422 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004423
Jim Grosbachd3595712011-08-03 23:50:40 +00004424 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004425 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004426 return true;
4427 // Range check the immediate.
4428 // lsl, ror: 0 <= imm <= 31
4429 // lsr, asr: 0 <= imm <= 32
4430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4431 if (!CE)
4432 return Error(Loc, "shift amount must be an immediate");
4433 int64_t Imm = CE->getValue();
4434 if (Imm < 0 ||
4435 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4436 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4437 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004438 // If <ShiftTy> #0, turn it into a no_shift.
4439 if (Imm == 0)
4440 St = ARM_AM::lsl;
4441 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4442 if (Imm == 32)
4443 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004444 Amount = Imm;
4445 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004446
4447 return false;
4448}
4449
Jim Grosbache7fbce72011-10-03 23:38:36 +00004450/// parseFPImm - A floating point immediate expression operand.
4451ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4452parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004453 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004454 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004455 // integer only.
4456 //
4457 // This routine still creates a generic Immediate operand, containing
4458 // a bitcast of the 64-bit floating point value. The various operands
4459 // that accept floats can check whether the value is valid for them
4460 // via the standard is*() predicates.
4461
Jim Grosbache7fbce72011-10-03 23:38:36 +00004462 SMLoc S = Parser.getTok().getLoc();
4463
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004464 if (Parser.getTok().isNot(AsmToken::Hash) &&
4465 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004466 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004467
4468 // Disambiguate the VMOV forms that can accept an FP immediate.
4469 // vmov.f32 <sreg>, #imm
4470 // vmov.f64 <dreg>, #imm
4471 // vmov.f32 <dreg>, #imm @ vector f32x2
4472 // vmov.f32 <qreg>, #imm @ vector f32x4
4473 //
4474 // There are also the NEON VMOV instructions which expect an
4475 // integer constant. Make sure we don't try to parse an FPImm
4476 // for these:
4477 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4478 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4479 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4480 TyOp->getToken() != ".f64"))
4481 return MatchOperand_NoMatch;
4482
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004483 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004484
4485 // Handle negation, as that still comes through as a separate token.
4486 bool isNegative = false;
4487 if (Parser.getTok().is(AsmToken::Minus)) {
4488 isNegative = true;
4489 Parser.Lex();
4490 }
4491 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004492 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004493 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004494 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004495 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4496 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004497 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004498 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004499 Operands.push_back(ARMOperand::CreateImm(
4500 MCConstantExpr::Create(IntVal, getContext()),
4501 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004502 return MatchOperand_Success;
4503 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004504 // Also handle plain integers. Instructions which allow floating point
4505 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004506 if (Tok.is(AsmToken::Integer)) {
4507 int64_t Val = Tok.getIntVal();
4508 Parser.Lex(); // Eat the token.
4509 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004510 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004511 return MatchOperand_ParseFail;
4512 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004513 double RealVal = ARM_AM::getFPImmFloat(Val);
4514 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4515 Operands.push_back(ARMOperand::CreateImm(
4516 MCConstantExpr::Create(Val, getContext()), S,
4517 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004518 return MatchOperand_Success;
4519 }
4520
Jim Grosbach235c8d22012-01-19 02:47:30 +00004521 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004522 return MatchOperand_ParseFail;
4523}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004524
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004525/// Parse a arm instruction operand. For now this parses the operand regardless
4526/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004527bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004528 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004529 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004530
4531 // Check if the current operand has a custom associated parser, if so, try to
4532 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004533 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4534 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004535 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004536 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4537 // there was a match, but an error occurred, in which case, just return that
4538 // the operand parsing failed.
4539 if (ResTy == MatchOperand_ParseFail)
4540 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004541
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004542 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004543 default:
4544 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004545 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004546 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004547 // If we've seen a branch mnemonic, the next operand must be a label. This
4548 // is true even if the label is a register name. So "br r1" means branch to
4549 // label "r1".
4550 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4551 if (!ExpectLabel) {
4552 if (!tryParseRegisterWithWriteBack(Operands))
4553 return false;
4554 int Res = tryParseShiftRegister(Operands);
4555 if (Res == 0) // success
4556 return false;
4557 else if (Res == -1) // irrecoverable error
4558 return true;
4559 // If this is VMRS, check for the apsr_nzcv operand.
4560 if (Mnemonic == "vmrs" &&
4561 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4562 S = Parser.getTok().getLoc();
4563 Parser.Lex();
4564 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4565 return false;
4566 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004567 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004568
4569 // Fall though for the Identifier case that is not a register or a
4570 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004571 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004572 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004573 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004574 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004575 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004576 // This was not a register so parse other operands that start with an
4577 // identifier (like labels) as expressions and create them as immediates.
4578 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004579 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004580 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004581 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004582 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004583 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4584 return false;
4585 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004586 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004587 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004588 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004589 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004590 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004591 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004592 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004593 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004594 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004595
4596 if (Parser.getTok().isNot(AsmToken::Colon)) {
4597 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4598 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004599 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004600 return true;
4601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4602 if (CE) {
4603 int32_t Val = CE->getValue();
4604 if (isNegative && Val == 0)
4605 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4606 }
4607 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4608 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004609
4610 // There can be a trailing '!' on operands that we want as a separate
4611 // '!' Token operand. Handle that here. For example, the compatibilty
4612 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4613 if (Parser.getTok().is(AsmToken::Exclaim)) {
4614 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4615 Parser.getTok().getLoc()));
4616 Parser.Lex(); // Eat exclaim token
4617 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004618 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004619 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004620 // w/ a ':' after the '#', it's just like a plain ':'.
4621 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004622 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004623 case AsmToken::Colon: {
4624 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004625 // FIXME: Check it's an expression prefix,
4626 // e.g. (FOO - :lower16:BAR) isn't legal.
4627 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004628 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004629 return true;
4630
Evan Cheng965b3c72011-01-13 07:58:56 +00004631 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004632 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004633 return true;
4634
Evan Cheng965b3c72011-01-13 07:58:56 +00004635 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004636 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004637 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004638 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004639 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004640 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004641 }
4642}
4643
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004644// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004645// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004646bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004647 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004648
4649 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004650 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004651 Parser.Lex(); // Eat ':'
4652
4653 if (getLexer().isNot(AsmToken::Identifier)) {
4654 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4655 return true;
4656 }
4657
4658 StringRef IDVal = Parser.getTok().getIdentifier();
4659 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004660 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004661 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004662 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004663 } else {
4664 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4665 return true;
4666 }
4667 Parser.Lex();
4668
4669 if (getLexer().isNot(AsmToken::Colon)) {
4670 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4671 return true;
4672 }
4673 Parser.Lex(); // Eat the last ':'
4674 return false;
4675}
4676
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004677/// \brief Given a mnemonic, split out possible predication code and carry
4678/// setting letters to form a canonical mnemonic and flags.
4679//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004680// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004681// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004682StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004683 unsigned &PredicationCode,
4684 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004685 unsigned &ProcessorIMod,
4686 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004687 PredicationCode = ARMCC::AL;
4688 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004689 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004690
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004691 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004692 //
4693 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004694 if ((Mnemonic == "movs" && isThumb()) ||
4695 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4696 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4697 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4698 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004699 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004700 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4701 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004702 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004703 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004704 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4705 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4706 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004707 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004708
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004709 // First, split out any predication code. Ignore mnemonics we know aren't
4710 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004711 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004712 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004713 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004714 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004715 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4716 .Case("eq", ARMCC::EQ)
4717 .Case("ne", ARMCC::NE)
4718 .Case("hs", ARMCC::HS)
4719 .Case("cs", ARMCC::HS)
4720 .Case("lo", ARMCC::LO)
4721 .Case("cc", ARMCC::LO)
4722 .Case("mi", ARMCC::MI)
4723 .Case("pl", ARMCC::PL)
4724 .Case("vs", ARMCC::VS)
4725 .Case("vc", ARMCC::VC)
4726 .Case("hi", ARMCC::HI)
4727 .Case("ls", ARMCC::LS)
4728 .Case("ge", ARMCC::GE)
4729 .Case("lt", ARMCC::LT)
4730 .Case("gt", ARMCC::GT)
4731 .Case("le", ARMCC::LE)
4732 .Case("al", ARMCC::AL)
4733 .Default(~0U);
4734 if (CC != ~0U) {
4735 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4736 PredicationCode = CC;
4737 }
Bill Wendling193961b2010-10-29 23:50:21 +00004738 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004739
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004740 // Next, determine if we have a carry setting bit. We explicitly ignore all
4741 // the instructions we know end in 's'.
4742 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004743 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004744 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4745 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4746 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004747 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004748 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004749 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004750 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004751 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004752 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004753 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4754 CarrySetting = true;
4755 }
4756
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004757 // The "cps" instruction can have a interrupt mode operand which is glued into
4758 // the mnemonic. Check if this is the case, split it and parse the imod op
4759 if (Mnemonic.startswith("cps")) {
4760 // Split out any imod code.
4761 unsigned IMod =
4762 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4763 .Case("ie", ARM_PROC::IE)
4764 .Case("id", ARM_PROC::ID)
4765 .Default(~0U);
4766 if (IMod != ~0U) {
4767 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4768 ProcessorIMod = IMod;
4769 }
4770 }
4771
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004772 // The "it" instruction has the condition mask on the end of the mnemonic.
4773 if (Mnemonic.startswith("it")) {
4774 ITMask = Mnemonic.slice(2, Mnemonic.size());
4775 Mnemonic = Mnemonic.slice(0, 2);
4776 }
4777
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004778 return Mnemonic;
4779}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004780
4781/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4782/// inclusion of carry set or predication code operands.
4783//
4784// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004785void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004786getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004787 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004788 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4789 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004790 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004791 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004792 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004793 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004794 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004795 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004796 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004797 Mnemonic == "mla" || Mnemonic == "smlal" ||
4798 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004799 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004800 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004801 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004802
Tim Northover2c45a382013-06-26 16:52:40 +00004803 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4804 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004805 Mnemonic == "trap" || Mnemonic == "hlt" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004806 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4807 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004808 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4809 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4810 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004811 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004812 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004813 } else if (!isThumb()) {
4814 // Some instructions are only predicable in Thumb mode
4815 CanAcceptPredicationCode
4816 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4817 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4818 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4819 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4820 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4821 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4822 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4823 } else if (isThumbOne()) {
4824 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004825 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004826 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004827}
4828
Jim Grosbach7283da92011-08-16 21:12:37 +00004829bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4830 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004831 // FIXME: This is all horribly hacky. We really need a better way to deal
4832 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004833
4834 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4835 // another does not. Specifically, the MOVW instruction does not. So we
4836 // special case it here and remove the defaulted (non-setting) cc_out
4837 // operand if that's the instruction we're trying to match.
4838 //
4839 // We do this as post-processing of the explicit operands rather than just
4840 // conditionally adding the cc_out in the first place because we need
4841 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004842 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004843 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4844 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4845 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4846 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004847
4848 // Register-register 'add' for thumb does not have a cc_out operand
4849 // when there are only two register operands.
4850 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4851 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4852 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4853 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4854 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004855 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004856 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4857 // have to check the immediate range here since Thumb2 has a variant
4858 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004859 if (((isThumb() && Mnemonic == "add") ||
4860 (isThumbTwo() && Mnemonic == "sub")) &&
4861 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004862 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4863 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4864 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004865 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004866 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004867 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004868 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004869 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4870 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004871 // selecting via the generic "add" mnemonic, so to know that we
4872 // should remove the cc_out operand, we have to explicitly check that
4873 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004874 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4875 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004876 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4877 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4878 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4879 // Nest conditions rather than one big 'if' statement for readability.
4880 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004881 // If both registers are low, we're in an IT block, and the immediate is
4882 // in range, we should use encoding T1 instead, which has a cc_out.
4883 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004884 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004885 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4886 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4887 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004888 // Check against T3. If the second register is the PC, this is an
4889 // alternate form of ADR, which uses encoding T4, so check for that too.
4890 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4891 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4892 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004893
4894 // Otherwise, we use encoding T4, which does not have a cc_out
4895 // operand.
4896 return true;
4897 }
4898
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004899 // The thumb2 multiply instruction doesn't have a CCOut register, so
4900 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4901 // use the 16-bit encoding or not.
4902 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4903 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4904 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4905 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4906 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4907 // If the registers aren't low regs, the destination reg isn't the
4908 // same as one of the source regs, or the cc_out operand is zero
4909 // outside of an IT block, we have to use the 32-bit encoding, so
4910 // remove the cc_out operand.
4911 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4912 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004913 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004914 !inITBlock() ||
4915 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4916 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4917 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4918 static_cast<ARMOperand*>(Operands[4])->getReg())))
4919 return true;
4920
Jim Grosbachefa7e952011-11-15 19:55:16 +00004921 // Also check the 'mul' syntax variant that doesn't specify an explicit
4922 // destination register.
4923 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4924 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4925 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4926 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4927 // If the registers aren't low regs or the cc_out operand is zero
4928 // outside of an IT block, we have to use the 32-bit encoding, so
4929 // remove the cc_out operand.
4930 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4931 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4932 !inITBlock()))
4933 return true;
4934
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004935
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004936
Jim Grosbach4b701af2011-08-24 21:42:27 +00004937 // Register-register 'add/sub' for thumb does not have a cc_out operand
4938 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4939 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4940 // right, this will result in better diagnostics (which operand is off)
4941 // anyway.
4942 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4943 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004944 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4945 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004946 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4947 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4948 (Operands.size() == 6 &&
4949 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004950 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004951
Jim Grosbach7283da92011-08-16 21:12:37 +00004952 return false;
4953}
4954
Joey Goulye8602552013-07-19 16:34:16 +00004955bool ARMAsmParser::shouldOmitPredicateOperand(
4956 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4957 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4958 unsigned RegIdx = 3;
4959 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4960 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4961 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4962 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4963 RegIdx = 4;
4964
4965 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4966 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4967 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4968 ARMMCRegisterClasses[ARM::QPRRegClassID]
4969 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4970 return true;
4971 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004972 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004973}
4974
Joey Gouly5d0564d2013-08-02 19:18:12 +00004975bool ARMAsmParser::isDeprecated(MCInst &Inst, StringRef &Info) {
4976 if (hasV8Ops() && Inst.getOpcode() == ARM::SETEND) {
4977 Info = "armv8";
4978 return true;
4979 }
Joey Goulyfcf67782013-08-02 20:50:01 +00004980 return false;
Joey Gouly5d0564d2013-08-02 19:18:12 +00004981}
4982
Jim Grosbach12952fe2011-11-11 23:08:10 +00004983static bool isDataTypeToken(StringRef Tok) {
4984 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4985 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4986 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4987 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4988 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4989 Tok == ".f" || Tok == ".d";
4990}
4991
4992// FIXME: This bit should probably be handled via an explicit match class
4993// in the .td files that matches the suffix instead of having it be
4994// a literal string token the way it is now.
4995static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4996 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4997}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004998static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4999 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005000/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005001bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5002 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005003 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005004 // Apply mnemonic aliases before doing anything else, as the destination
5005 // mnemnonic may include suffices and we want to handle them normally.
5006 // The generic tblgen'erated code does this later, at the start of
5007 // MatchInstructionImpl(), but that's too late for aliases that include
5008 // any sort of suffix.
5009 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005010 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5011 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005012
Jim Grosbachab5830e2011-12-14 02:16:11 +00005013 // First check for the ARM-specific .req directive.
5014 if (Parser.getTok().is(AsmToken::Identifier) &&
5015 Parser.getTok().getIdentifier() == ".req") {
5016 parseDirectiveReq(Name, NameLoc);
5017 // We always return 'error' for this, as we're done with this
5018 // statement and don't need to match the 'instruction."
5019 return true;
5020 }
5021
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005022 // Create the leading tokens for the mnemonic, split by '.' characters.
5023 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005024 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005025
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005026 // Split out the predication code and carry setting flag from the mnemonic.
5027 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005028 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005029 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005030 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005031 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005032 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005033
Jim Grosbach1c171b12011-08-25 17:23:55 +00005034 // In Thumb1, only the branch (B) instruction can be predicated.
5035 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005036 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005037 return Error(NameLoc, "conditional execution not supported in Thumb1");
5038 }
5039
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005040 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5041
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005042 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5043 // is the mask as it will be for the IT encoding if the conditional
5044 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5045 // where the conditional bit0 is zero, the instruction post-processing
5046 // will adjust the mask accordingly.
5047 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005048 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5049 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005050 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005051 return Error(Loc, "too many conditions on IT instruction");
5052 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005053 unsigned Mask = 8;
5054 for (unsigned i = ITMask.size(); i != 0; --i) {
5055 char pos = ITMask[i - 1];
5056 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005057 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005058 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005059 }
5060 Mask >>= 1;
5061 if (ITMask[i - 1] == 't')
5062 Mask |= 8;
5063 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005064 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005065 }
5066
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005067 // FIXME: This is all a pretty gross hack. We should automatically handle
5068 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005069
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005070 // Next, add the CCOut and ConditionCode operands, if needed.
5071 //
5072 // For mnemonics which can ever incorporate a carry setting bit or predication
5073 // code, our matching model involves us always generating CCOut and
5074 // ConditionCode operands to match the mnemonic "as written" and then we let
5075 // the matcher deal with finding the right instruction or generating an
5076 // appropriate error.
5077 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005078 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005079
Jim Grosbach03a8a162011-07-14 22:04:21 +00005080 // If we had a carry-set on an instruction that can't do that, issue an
5081 // error.
5082 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005083 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005084 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005085 "' can not set flags, but 's' suffix specified");
5086 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005087 // If we had a predication code on an instruction that can't do that, issue an
5088 // error.
5089 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005090 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005091 return Error(NameLoc, "instruction '" + Mnemonic +
5092 "' is not predicable, but condition code specified");
5093 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005094
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005095 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005096 if (CanAcceptCarrySet) {
5097 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005098 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005099 Loc));
5100 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005101
5102 // Add the predication code operand, if necessary.
5103 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005104 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5105 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005106 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005107 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005108 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005109
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005110 // Add the processor imod operand, if necessary.
5111 if (ProcessorIMod) {
5112 Operands.push_back(ARMOperand::CreateImm(
5113 MCConstantExpr::Create(ProcessorIMod, getContext()),
5114 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005115 }
5116
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005117 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005118 while (Next != StringRef::npos) {
5119 Start = Next;
5120 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005121 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005122
Jim Grosbach12952fe2011-11-11 23:08:10 +00005123 // Some NEON instructions have an optional datatype suffix that is
5124 // completely ignored. Check for that.
5125 if (isDataTypeToken(ExtraToken) &&
5126 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5127 continue;
5128
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005129 // For for ARM mode generate an error if the .n qualifier is used.
5130 if (ExtraToken == ".n" && !isThumb()) {
5131 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5132 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5133 "arm mode");
5134 }
5135
5136 // The .n qualifier is always discarded as that is what the tables
5137 // and matcher expect. In ARM mode the .w qualifier has no effect,
5138 // so discard it to avoid errors that can be caused by the matcher.
5139 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005140 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5141 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5142 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005143 }
5144
5145 // Read the remaining operands.
5146 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005147 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005148 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005149 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005150 return true;
5151 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005152
5153 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005154 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005155
5156 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005157 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005158 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005159 return true;
5160 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005161 }
5162 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005163
Chris Lattnera2a9d162010-09-11 16:18:25 +00005164 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005165 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005166 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005167 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005168 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005169
Chris Lattner91689c12010-09-08 05:10:46 +00005170 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005171
Jim Grosbach7283da92011-08-16 21:12:37 +00005172 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5173 // do and don't have a cc_out optional-def operand. With some spot-checks
5174 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005175 // parse and adjust accordingly before actually matching. We shouldn't ever
5176 // try to remove a cc_out operand that was explicitly set on the the
5177 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5178 // table driven matcher doesn't fit well with the ARM instruction set.
5179 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005180 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5181 Operands.erase(Operands.begin() + 1);
5182 delete Op;
5183 }
5184
Joey Goulye8602552013-07-19 16:34:16 +00005185 // Some instructions have the same mnemonic, but don't always
5186 // have a predicate. Distinguish them here and delete the
5187 // predicate if needed.
5188 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5189 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5190 Operands.erase(Operands.begin() + 1);
5191 delete Op;
5192 }
5193
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005194 // ARM mode 'blx' need special handling, as the register operand version
5195 // is predicable, but the label operand version is not. So, we can't rely
5196 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005197 // a k_CondCode operand in the list. If we're trying to match the label
5198 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005199 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5200 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5201 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5202 Operands.erase(Operands.begin() + 1);
5203 delete Op;
5204 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005205
Weiming Zhao8f56f882012-11-16 21:55:34 +00005206 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5207 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5208 // a single GPRPair reg operand is used in the .td file to replace the two
5209 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5210 // expressed as a GPRPair, so we have to manually merge them.
5211 // FIXME: We would really like to be able to tablegen'erate this.
5212 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005213 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5214 Mnemonic == "stlexd")) {
5215 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005216 unsigned Idx = isLoad ? 2 : 3;
5217 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5218 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5219
5220 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5221 // Adjust only if Op1 and Op2 are GPRs.
5222 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5223 MRC.contains(Op2->getReg())) {
5224 unsigned Reg1 = Op1->getReg();
5225 unsigned Reg2 = Op2->getReg();
5226 unsigned Rt = MRI->getEncodingValue(Reg1);
5227 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5228
5229 // Rt2 must be Rt + 1 and Rt must be even.
5230 if (Rt + 1 != Rt2 || (Rt & 1)) {
5231 Error(Op2->getStartLoc(), isLoad ?
5232 "destination operands must be sequential" :
5233 "source operands must be sequential");
5234 return true;
5235 }
5236 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5237 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5238 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5239 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5240 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5241 delete Op1;
5242 delete Op2;
5243 }
5244 }
5245
Kevin Enderby78f95722013-07-31 21:05:30 +00005246 // FIXME: As said above, this is all a pretty gross hack. This instruction
5247 // does not fit with other "subs" and tblgen.
5248 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5249 // so the Mnemonic is the original name "subs" and delete the predicate
5250 // operand so it will match the table entry.
5251 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5252 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5253 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5254 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5255 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5256 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5257 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5258 Operands.erase(Operands.begin());
5259 delete Op0;
5260 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5261
5262 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5263 Operands.erase(Operands.begin() + 1);
5264 delete Op1;
5265 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005266 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005267}
5268
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005269// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005270
5271// return 'true' if register list contains non-low GPR registers,
5272// 'false' otherwise. If Reg is in the register list or is HiReg, set
5273// 'containsReg' to true.
5274static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5275 unsigned HiReg, bool &containsReg) {
5276 containsReg = false;
5277 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5278 unsigned OpReg = Inst.getOperand(i).getReg();
5279 if (OpReg == Reg)
5280 containsReg = true;
5281 // Anything other than a low register isn't legal here.
5282 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5283 return true;
5284 }
5285 return false;
5286}
5287
Jim Grosbacha31f2232011-09-07 18:05:34 +00005288// Check if the specified regisgter is in the register list of the inst,
5289// starting at the indicated operand number.
5290static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5291 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5292 unsigned OpReg = Inst.getOperand(i).getReg();
5293 if (OpReg == Reg)
5294 return true;
5295 }
5296 return false;
5297}
5298
Jim Grosbached16ec42011-08-29 22:24:09 +00005299// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5300// the ARMInsts array) instead. Getting that here requires awkward
5301// API changes, though. Better way?
5302namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005303extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005304}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005305static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005306 return ARMInsts[Opcode];
5307}
5308
Richard Barton8d519fe2013-09-05 14:14:19 +00005309// Return true if instruction has the interesting property of being
5310// allowed in IT blocks, but not being predicable.
5311static bool instIsBreakpoint(const MCInst &Inst) {
5312 return Inst.getOpcode() == ARM::tBKPT ||
5313 Inst.getOpcode() == ARM::BKPT ||
5314 Inst.getOpcode() == ARM::tHLT ||
5315 Inst.getOpcode() == ARM::HLT;
5316
5317}
5318
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005319// FIXME: We would really like to be able to tablegen'erate this.
5320bool ARMAsmParser::
5321validateInstruction(MCInst &Inst,
5322 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005323 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005324 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005325
Jim Grosbached16ec42011-08-29 22:24:09 +00005326 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005327 // NOTE: BKPT and HLT instructions have the interesting property of being
5328 // allowed in IT blocks, but not being predicable. They just always
5329 // execute.
5330 if (inITBlock() && !instIsBreakpoint(Inst)) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005331 unsigned bit = 1;
5332 if (ITState.FirstCond)
5333 ITState.FirstCond = false;
5334 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005335 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005336 // The instruction must be predicable.
5337 if (!MCID.isPredicable())
5338 return Error(Loc, "instructions in IT block must be predicable");
5339 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5340 unsigned ITCond = bit ? ITState.Cond :
5341 ARMCC::getOppositeCondition(ITState.Cond);
5342 if (Cond != ITCond) {
5343 // Find the condition code Operand to get its SMLoc information.
5344 SMLoc CondLoc;
5345 for (unsigned i = 1; i < Operands.size(); ++i)
5346 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5347 CondLoc = Operands[i]->getStartLoc();
5348 return Error(CondLoc, "incorrect condition in IT block; got '" +
5349 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5350 "', but expected '" +
5351 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5352 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005353 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005354 } else if (isThumbTwo() && MCID.isPredicable() &&
5355 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005356 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5357 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005358 return Error(Loc, "predicated instructions must be in IT block");
5359
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005360 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005361 case ARM::LDRD:
5362 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005363 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005364 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005365 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5366 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005367 if (Rt2 != Rt + 1)
5368 return Error(Operands[3]->getStartLoc(),
5369 "destination operands must be sequential");
5370 return false;
5371 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005372 case ARM::STRD: {
5373 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005374 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5375 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005376 if (Rt2 != Rt + 1)
5377 return Error(Operands[3]->getStartLoc(),
5378 "source operands must be sequential");
5379 return false;
5380 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005381 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005382 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005383 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005384 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5385 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005386 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005387 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005388 "source operands must be sequential");
5389 return false;
5390 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005391 case ARM::SBFX:
5392 case ARM::UBFX: {
5393 // width must be in range [1, 32-lsb]
5394 unsigned lsb = Inst.getOperand(2).getImm();
5395 unsigned widthm1 = Inst.getOperand(3).getImm();
5396 if (widthm1 >= 32 - lsb)
5397 return Error(Operands[5]->getStartLoc(),
5398 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005399 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005400 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005401 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005402 // If we're parsing Thumb2, the .w variant is available and handles
5403 // most cases that are normally illegal for a Thumb1 LDM
5404 // instruction. We'll make the transformation in processInstruction()
5405 // if necessary.
5406 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005407 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005408 // in the register list.
5409 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005410 bool hasWritebackToken =
5411 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5412 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005413 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005414 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005415 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5416 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005417 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005418 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005419 return Error(Operands[2]->getStartLoc(),
5420 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005421 // If we should not have writeback, there must not be a '!'. This is
5422 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005423 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005424 return Error(Operands[3]->getStartLoc(),
5425 "writeback operator '!' not allowed when base register "
5426 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005427
5428 break;
5429 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005430 case ARM::t2LDMIA_UPD: {
5431 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5432 return Error(Operands[4]->getStartLoc(),
5433 "writeback operator '!' not allowed when base register "
5434 "in register list");
5435 break;
5436 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005437 case ARM::tMUL: {
5438 // The second source operand must be the same register as the destination
5439 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005440 //
5441 // In this case, we must directly check the parsed operands because the
5442 // cvtThumbMultiply() function is written in such a way that it guarantees
5443 // this first statement is always true for the new Inst. Essentially, the
5444 // destination is unconditionally copied into the second source operand
5445 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005446 if (Operands.size() == 6 &&
5447 (((ARMOperand*)Operands[3])->getReg() !=
5448 ((ARMOperand*)Operands[5])->getReg()) &&
5449 (((ARMOperand*)Operands[3])->getReg() !=
5450 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005451 return Error(Operands[3]->getStartLoc(),
5452 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005453 }
5454 break;
5455 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005456 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5457 // so only issue a diagnostic for thumb1. The instructions will be
5458 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005459 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005460 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005461 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5462 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005463 return Error(Operands[2]->getStartLoc(),
5464 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005465 break;
5466 }
5467 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005468 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005469 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5470 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005471 return Error(Operands[2]->getStartLoc(),
5472 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005473 break;
5474 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005475 case ARM::tSTMIA_UPD: {
5476 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005477 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005478 return Error(Operands[4]->getStartLoc(),
5479 "registers must be in range r0-r7");
5480 break;
5481 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005482 case ARM::tADDrSP: {
5483 // If the non-SP source operand and the destination operand are not the
5484 // same, we need thumb2 (for the wide encoding), or we have an error.
5485 if (!isThumbTwo() &&
5486 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5487 return Error(Operands[4]->getStartLoc(),
5488 "source register must be the same as destination");
5489 }
5490 break;
5491 }
Mihai Popaad18d3c2013-08-09 10:38:32 +00005492 // final range checking for Thumb unconditional branch instructions
5493 case ARM::tB:
5494 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5495 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5496 break;
5497 case ARM::t2B: {
5498 int op = (Operands[2]->isImm()) ? 2 : 3;
5499 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5500 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5501 break;
5502 }
5503 // final range checking for Thumb conditional branch instructions
5504 case ARM::tBcc:
5505 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5506 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5507 break;
5508 case ARM::t2Bcc: {
5509 int op = (Operands[2]->isImm()) ? 2 : 3;
5510 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<20, 1>())
5511 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5512 break;
5513 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005514 }
5515
Joey Gouly5d0564d2013-08-02 19:18:12 +00005516 StringRef DepInfo;
5517 if (isDeprecated(Inst, DepInfo))
5518 Warning(Loc, "deprecated on " + DepInfo);
5519
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005520 return false;
5521}
5522
Jim Grosbach1a747242012-01-23 23:45:44 +00005523static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005524 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005525 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005526 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005527 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5528 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5529 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5530 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5531 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5532 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5533 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5534 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5535 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005536
5537 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005538 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5539 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5540 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5541 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5542 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005543
Jim Grosbach1e946a42012-01-24 00:43:12 +00005544 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5545 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5546 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5547 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5548 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005549
Jim Grosbach1e946a42012-01-24 00:43:12 +00005550 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5551 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5552 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5553 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5554 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005555
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005556 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005557 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5558 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5559 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5560 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5561 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5562 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5563 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5564 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5565 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5566 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5567 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5568 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5569 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5570 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5571 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005572
Jim Grosbach1a747242012-01-23 23:45:44 +00005573 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005574 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5575 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5576 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5577 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5578 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5579 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5580 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5581 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5582 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5583 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5584 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5585 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5586 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5587 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5588 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5589 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5590 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5591 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005592
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005593 // VST4LN
5594 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5595 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5596 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5597 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5598 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5599 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5600 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5601 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5602 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5603 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5604 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5605 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5606 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5607 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5608 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5609
Jim Grosbachda70eac2012-01-24 00:58:13 +00005610 // VST4
5611 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5612 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5613 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5614 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5615 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5616 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5617 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5618 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5619 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5620 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5621 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5622 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5623 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5624 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5625 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5626 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5627 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5628 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005629 }
5630}
5631
Jim Grosbach1a747242012-01-23 23:45:44 +00005632static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005633 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005634 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005635 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005636 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5637 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5638 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5639 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5640 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5641 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5642 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5643 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5644 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005645
5646 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005647 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5648 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5649 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5650 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5651 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5652 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5653 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5654 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5655 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5656 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5657 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5658 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5659 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5660 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5661 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005662
Jim Grosbachb78403c2012-01-24 23:47:04 +00005663 // VLD3DUP
5664 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5665 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5666 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5667 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5668 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5669 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5670 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5671 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5672 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5673 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5674 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5675 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5676 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5677 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5678 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5679 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5680 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5681 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5682
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005683 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005684 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5685 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5686 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5687 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5688 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5689 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5690 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5691 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5692 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5693 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5694 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5695 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5696 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5697 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5698 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005699
5700 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005701 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5702 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5703 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5704 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5705 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5706 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5707 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5708 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5709 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5710 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5711 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5712 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5713 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5714 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5715 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5716 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5717 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5718 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005719
Jim Grosbach14952a02012-01-24 18:37:25 +00005720 // VLD4LN
5721 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5722 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5723 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5724 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5725 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5726 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5727 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5728 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5729 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5730 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5731 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5732 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5733 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5734 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5735 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5736
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005737 // VLD4DUP
5738 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5739 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5740 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5741 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5742 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5743 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5744 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5745 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5746 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5747 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5748 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5749 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5750 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5751 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5752 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5753 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5754 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5755 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5756
Jim Grosbached561fc2012-01-24 00:43:17 +00005757 // VLD4
5758 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5759 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5760 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5761 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5762 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5763 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5764 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5765 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5766 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5767 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5768 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5769 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5770 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5771 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5772 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5773 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5774 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5775 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005776 }
5777}
5778
Jim Grosbachafad0532011-11-10 23:42:14 +00005779bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005780processInstruction(MCInst &Inst,
5781 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5782 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005783 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5784 case ARM::ADDri: {
5785 if (Inst.getOperand(1).getReg() != ARM::PC ||
5786 Inst.getOperand(5).getReg() != 0)
5787 return false;
5788 MCInst TmpInst;
5789 TmpInst.setOpcode(ARM::ADR);
5790 TmpInst.addOperand(Inst.getOperand(0));
5791 TmpInst.addOperand(Inst.getOperand(2));
5792 TmpInst.addOperand(Inst.getOperand(3));
5793 TmpInst.addOperand(Inst.getOperand(4));
5794 Inst = TmpInst;
5795 return true;
5796 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005797 // Aliases for alternate PC+imm syntax of LDR instructions.
5798 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005799 // Select the narrow version if the immediate will fit.
5800 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005801 Inst.getOperand(1).getImm() <= 0xff &&
5802 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5803 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005804 Inst.setOpcode(ARM::tLDRpci);
5805 else
5806 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005807 return true;
5808 case ARM::t2LDRBpcrel:
5809 Inst.setOpcode(ARM::t2LDRBpci);
5810 return true;
5811 case ARM::t2LDRHpcrel:
5812 Inst.setOpcode(ARM::t2LDRHpci);
5813 return true;
5814 case ARM::t2LDRSBpcrel:
5815 Inst.setOpcode(ARM::t2LDRSBpci);
5816 return true;
5817 case ARM::t2LDRSHpcrel:
5818 Inst.setOpcode(ARM::t2LDRSHpci);
5819 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005820 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005821 case ARM::VST1LNdWB_register_Asm_8:
5822 case ARM::VST1LNdWB_register_Asm_16:
5823 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005824 MCInst TmpInst;
5825 // Shuffle the operands around so the lane index operand is in the
5826 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005827 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005828 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005829 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5830 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5831 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5832 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5833 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5834 TmpInst.addOperand(Inst.getOperand(1)); // lane
5835 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5836 TmpInst.addOperand(Inst.getOperand(6));
5837 Inst = TmpInst;
5838 return true;
5839 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005840
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005841 case ARM::VST2LNdWB_register_Asm_8:
5842 case ARM::VST2LNdWB_register_Asm_16:
5843 case ARM::VST2LNdWB_register_Asm_32:
5844 case ARM::VST2LNqWB_register_Asm_16:
5845 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005846 MCInst TmpInst;
5847 // Shuffle the operands around so the lane index operand is in the
5848 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005849 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005850 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005851 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5852 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5853 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5854 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5855 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5857 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005858 TmpInst.addOperand(Inst.getOperand(1)); // lane
5859 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5860 TmpInst.addOperand(Inst.getOperand(6));
5861 Inst = TmpInst;
5862 return true;
5863 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005864
5865 case ARM::VST3LNdWB_register_Asm_8:
5866 case ARM::VST3LNdWB_register_Asm_16:
5867 case ARM::VST3LNdWB_register_Asm_32:
5868 case ARM::VST3LNqWB_register_Asm_16:
5869 case ARM::VST3LNqWB_register_Asm_32: {
5870 MCInst TmpInst;
5871 // Shuffle the operands around so the lane index operand is in the
5872 // right place.
5873 unsigned Spacing;
5874 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5875 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5876 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5877 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5878 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5879 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5881 Spacing));
5882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5883 Spacing * 2));
5884 TmpInst.addOperand(Inst.getOperand(1)); // lane
5885 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5886 TmpInst.addOperand(Inst.getOperand(6));
5887 Inst = TmpInst;
5888 return true;
5889 }
5890
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005891 case ARM::VST4LNdWB_register_Asm_8:
5892 case ARM::VST4LNdWB_register_Asm_16:
5893 case ARM::VST4LNdWB_register_Asm_32:
5894 case ARM::VST4LNqWB_register_Asm_16:
5895 case ARM::VST4LNqWB_register_Asm_32: {
5896 MCInst TmpInst;
5897 // Shuffle the operands around so the lane index operand is in the
5898 // right place.
5899 unsigned Spacing;
5900 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5901 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5902 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5903 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5904 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5905 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5906 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5907 Spacing));
5908 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5909 Spacing * 2));
5910 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5911 Spacing * 3));
5912 TmpInst.addOperand(Inst.getOperand(1)); // lane
5913 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5914 TmpInst.addOperand(Inst.getOperand(6));
5915 Inst = TmpInst;
5916 return true;
5917 }
5918
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005919 case ARM::VST1LNdWB_fixed_Asm_8:
5920 case ARM::VST1LNdWB_fixed_Asm_16:
5921 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005922 MCInst TmpInst;
5923 // Shuffle the operands around so the lane index operand is in the
5924 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005925 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005926 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005927 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5928 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5929 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5930 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5931 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5932 TmpInst.addOperand(Inst.getOperand(1)); // lane
5933 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5934 TmpInst.addOperand(Inst.getOperand(5));
5935 Inst = TmpInst;
5936 return true;
5937 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005938
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005939 case ARM::VST2LNdWB_fixed_Asm_8:
5940 case ARM::VST2LNdWB_fixed_Asm_16:
5941 case ARM::VST2LNdWB_fixed_Asm_32:
5942 case ARM::VST2LNqWB_fixed_Asm_16:
5943 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005944 MCInst TmpInst;
5945 // Shuffle the operands around so the lane index operand is in the
5946 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005947 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005948 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005949 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5950 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5951 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5952 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5953 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005954 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5955 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005956 TmpInst.addOperand(Inst.getOperand(1)); // lane
5957 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5958 TmpInst.addOperand(Inst.getOperand(5));
5959 Inst = TmpInst;
5960 return true;
5961 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005962
5963 case ARM::VST3LNdWB_fixed_Asm_8:
5964 case ARM::VST3LNdWB_fixed_Asm_16:
5965 case ARM::VST3LNdWB_fixed_Asm_32:
5966 case ARM::VST3LNqWB_fixed_Asm_16:
5967 case ARM::VST3LNqWB_fixed_Asm_32: {
5968 MCInst TmpInst;
5969 // Shuffle the operands around so the lane index operand is in the
5970 // right place.
5971 unsigned Spacing;
5972 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5973 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5974 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5975 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5976 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5977 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5978 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5979 Spacing));
5980 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5981 Spacing * 2));
5982 TmpInst.addOperand(Inst.getOperand(1)); // lane
5983 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5984 TmpInst.addOperand(Inst.getOperand(5));
5985 Inst = TmpInst;
5986 return true;
5987 }
5988
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005989 case ARM::VST4LNdWB_fixed_Asm_8:
5990 case ARM::VST4LNdWB_fixed_Asm_16:
5991 case ARM::VST4LNdWB_fixed_Asm_32:
5992 case ARM::VST4LNqWB_fixed_Asm_16:
5993 case ARM::VST4LNqWB_fixed_Asm_32: {
5994 MCInst TmpInst;
5995 // Shuffle the operands around so the lane index operand is in the
5996 // right place.
5997 unsigned Spacing;
5998 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5999 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6000 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6001 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6002 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6003 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6004 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6005 Spacing));
6006 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6007 Spacing * 2));
6008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6009 Spacing * 3));
6010 TmpInst.addOperand(Inst.getOperand(1)); // lane
6011 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6012 TmpInst.addOperand(Inst.getOperand(5));
6013 Inst = TmpInst;
6014 return true;
6015 }
6016
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006017 case ARM::VST1LNdAsm_8:
6018 case ARM::VST1LNdAsm_16:
6019 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006020 MCInst TmpInst;
6021 // Shuffle the operands around so the lane index operand is in the
6022 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006023 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006024 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006025 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6026 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6027 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6028 TmpInst.addOperand(Inst.getOperand(1)); // lane
6029 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6030 TmpInst.addOperand(Inst.getOperand(5));
6031 Inst = TmpInst;
6032 return true;
6033 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006034
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006035 case ARM::VST2LNdAsm_8:
6036 case ARM::VST2LNdAsm_16:
6037 case ARM::VST2LNdAsm_32:
6038 case ARM::VST2LNqAsm_16:
6039 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006040 MCInst TmpInst;
6041 // Shuffle the operands around so the lane index operand is in the
6042 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006043 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006044 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006045 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6046 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6047 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006050 TmpInst.addOperand(Inst.getOperand(1)); // lane
6051 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6052 TmpInst.addOperand(Inst.getOperand(5));
6053 Inst = TmpInst;
6054 return true;
6055 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006056
6057 case ARM::VST3LNdAsm_8:
6058 case ARM::VST3LNdAsm_16:
6059 case ARM::VST3LNdAsm_32:
6060 case ARM::VST3LNqAsm_16:
6061 case ARM::VST3LNqAsm_32: {
6062 MCInst TmpInst;
6063 // Shuffle the operands around so the lane index operand is in the
6064 // right place.
6065 unsigned Spacing;
6066 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6067 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6068 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6071 Spacing));
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing * 2));
6074 TmpInst.addOperand(Inst.getOperand(1)); // lane
6075 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6076 TmpInst.addOperand(Inst.getOperand(5));
6077 Inst = TmpInst;
6078 return true;
6079 }
6080
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006081 case ARM::VST4LNdAsm_8:
6082 case ARM::VST4LNdAsm_16:
6083 case ARM::VST4LNdAsm_32:
6084 case ARM::VST4LNqAsm_16:
6085 case ARM::VST4LNqAsm_32: {
6086 MCInst TmpInst;
6087 // Shuffle the operands around so the lane index operand is in the
6088 // right place.
6089 unsigned Spacing;
6090 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6091 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6092 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6093 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6094 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6095 Spacing));
6096 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6097 Spacing * 2));
6098 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6099 Spacing * 3));
6100 TmpInst.addOperand(Inst.getOperand(1)); // lane
6101 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6102 TmpInst.addOperand(Inst.getOperand(5));
6103 Inst = TmpInst;
6104 return true;
6105 }
6106
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006107 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006108 case ARM::VLD1LNdWB_register_Asm_8:
6109 case ARM::VLD1LNdWB_register_Asm_16:
6110 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006111 MCInst TmpInst;
6112 // Shuffle the operands around so the lane index operand is in the
6113 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006114 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006115 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006116 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6117 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6118 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6119 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6120 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6121 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6122 TmpInst.addOperand(Inst.getOperand(1)); // lane
6123 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6124 TmpInst.addOperand(Inst.getOperand(6));
6125 Inst = TmpInst;
6126 return true;
6127 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006128
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006129 case ARM::VLD2LNdWB_register_Asm_8:
6130 case ARM::VLD2LNdWB_register_Asm_16:
6131 case ARM::VLD2LNdWB_register_Asm_32:
6132 case ARM::VLD2LNqWB_register_Asm_16:
6133 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006134 MCInst TmpInst;
6135 // Shuffle the operands around so the lane index operand is in the
6136 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006137 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006138 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006139 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6141 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006142 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6143 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6144 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6145 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6146 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6148 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006149 TmpInst.addOperand(Inst.getOperand(1)); // lane
6150 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6151 TmpInst.addOperand(Inst.getOperand(6));
6152 Inst = TmpInst;
6153 return true;
6154 }
6155
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006156 case ARM::VLD3LNdWB_register_Asm_8:
6157 case ARM::VLD3LNdWB_register_Asm_16:
6158 case ARM::VLD3LNdWB_register_Asm_32:
6159 case ARM::VLD3LNqWB_register_Asm_16:
6160 case ARM::VLD3LNqWB_register_Asm_32: {
6161 MCInst TmpInst;
6162 // Shuffle the operands around so the lane index operand is in the
6163 // right place.
6164 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006165 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006166 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6168 Spacing));
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006170 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006171 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6172 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6173 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6174 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6175 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6176 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6177 Spacing));
6178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006179 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006180 TmpInst.addOperand(Inst.getOperand(1)); // lane
6181 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6182 TmpInst.addOperand(Inst.getOperand(6));
6183 Inst = TmpInst;
6184 return true;
6185 }
6186
Jim Grosbach14952a02012-01-24 18:37:25 +00006187 case ARM::VLD4LNdWB_register_Asm_8:
6188 case ARM::VLD4LNdWB_register_Asm_16:
6189 case ARM::VLD4LNdWB_register_Asm_32:
6190 case ARM::VLD4LNqWB_register_Asm_16:
6191 case ARM::VLD4LNqWB_register_Asm_32: {
6192 MCInst TmpInst;
6193 // Shuffle the operands around so the lane index operand is in the
6194 // right place.
6195 unsigned Spacing;
6196 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6197 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 Spacing));
6200 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 Spacing * 2));
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 Spacing * 3));
6204 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6205 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6206 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6207 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6208 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 Spacing));
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 Spacing * 2));
6213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 Spacing * 3));
6215 TmpInst.addOperand(Inst.getOperand(1)); // lane
6216 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6217 TmpInst.addOperand(Inst.getOperand(6));
6218 Inst = TmpInst;
6219 return true;
6220 }
6221
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006222 case ARM::VLD1LNdWB_fixed_Asm_8:
6223 case ARM::VLD1LNdWB_fixed_Asm_16:
6224 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006225 MCInst TmpInst;
6226 // Shuffle the operands around so the lane index operand is in the
6227 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006228 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006229 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006230 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6231 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6232 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6233 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6234 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6235 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6236 TmpInst.addOperand(Inst.getOperand(1)); // lane
6237 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6238 TmpInst.addOperand(Inst.getOperand(5));
6239 Inst = TmpInst;
6240 return true;
6241 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006242
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006243 case ARM::VLD2LNdWB_fixed_Asm_8:
6244 case ARM::VLD2LNdWB_fixed_Asm_16:
6245 case ARM::VLD2LNdWB_fixed_Asm_32:
6246 case ARM::VLD2LNqWB_fixed_Asm_16:
6247 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006248 MCInst TmpInst;
6249 // Shuffle the operands around so the lane index operand is in the
6250 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006251 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006252 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006253 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006256 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6257 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6258 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6259 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6260 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006261 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6262 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006263 TmpInst.addOperand(Inst.getOperand(1)); // lane
6264 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6265 TmpInst.addOperand(Inst.getOperand(5));
6266 Inst = TmpInst;
6267 return true;
6268 }
6269
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006270 case ARM::VLD3LNdWB_fixed_Asm_8:
6271 case ARM::VLD3LNdWB_fixed_Asm_16:
6272 case ARM::VLD3LNdWB_fixed_Asm_32:
6273 case ARM::VLD3LNqWB_fixed_Asm_16:
6274 case ARM::VLD3LNqWB_fixed_Asm_32: {
6275 MCInst TmpInst;
6276 // Shuffle the operands around so the lane index operand is in the
6277 // right place.
6278 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006279 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006280 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6282 Spacing));
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006284 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006285 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6286 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6287 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6288 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6289 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6291 Spacing));
6292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006293 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006294 TmpInst.addOperand(Inst.getOperand(1)); // lane
6295 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6296 TmpInst.addOperand(Inst.getOperand(5));
6297 Inst = TmpInst;
6298 return true;
6299 }
6300
Jim Grosbach14952a02012-01-24 18:37:25 +00006301 case ARM::VLD4LNdWB_fixed_Asm_8:
6302 case ARM::VLD4LNdWB_fixed_Asm_16:
6303 case ARM::VLD4LNdWB_fixed_Asm_32:
6304 case ARM::VLD4LNqWB_fixed_Asm_16:
6305 case ARM::VLD4LNqWB_fixed_Asm_32: {
6306 MCInst TmpInst;
6307 // Shuffle the operands around so the lane index operand is in the
6308 // right place.
6309 unsigned Spacing;
6310 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6311 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6312 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 Spacing));
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 Spacing * 2));
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 Spacing * 3));
6318 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6319 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6320 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6321 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6322 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 Spacing));
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6326 Spacing * 2));
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6328 Spacing * 3));
6329 TmpInst.addOperand(Inst.getOperand(1)); // lane
6330 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6331 TmpInst.addOperand(Inst.getOperand(5));
6332 Inst = TmpInst;
6333 return true;
6334 }
6335
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006336 case ARM::VLD1LNdAsm_8:
6337 case ARM::VLD1LNdAsm_16:
6338 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006339 MCInst TmpInst;
6340 // Shuffle the operands around so the lane index operand is in the
6341 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006342 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006343 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6346 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6347 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6348 TmpInst.addOperand(Inst.getOperand(1)); // lane
6349 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6350 TmpInst.addOperand(Inst.getOperand(5));
6351 Inst = TmpInst;
6352 return true;
6353 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006354
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006355 case ARM::VLD2LNdAsm_8:
6356 case ARM::VLD2LNdAsm_16:
6357 case ARM::VLD2LNdAsm_32:
6358 case ARM::VLD2LNqAsm_16:
6359 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006360 MCInst TmpInst;
6361 // Shuffle the operands around so the lane index operand is in the
6362 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006363 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006364 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006365 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006368 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6369 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6370 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006373 TmpInst.addOperand(Inst.getOperand(1)); // lane
6374 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6375 TmpInst.addOperand(Inst.getOperand(5));
6376 Inst = TmpInst;
6377 return true;
6378 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006379
6380 case ARM::VLD3LNdAsm_8:
6381 case ARM::VLD3LNdAsm_16:
6382 case ARM::VLD3LNdAsm_32:
6383 case ARM::VLD3LNqAsm_16:
6384 case ARM::VLD3LNqAsm_32: {
6385 MCInst TmpInst;
6386 // Shuffle the operands around so the lane index operand is in the
6387 // right place.
6388 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006389 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006390 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6391 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6392 Spacing));
6393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006394 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006395 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6396 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6397 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing));
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006401 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006402 TmpInst.addOperand(Inst.getOperand(1)); // lane
6403 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6404 TmpInst.addOperand(Inst.getOperand(5));
6405 Inst = TmpInst;
6406 return true;
6407 }
6408
Jim Grosbach14952a02012-01-24 18:37:25 +00006409 case ARM::VLD4LNdAsm_8:
6410 case ARM::VLD4LNdAsm_16:
6411 case ARM::VLD4LNdAsm_32:
6412 case ARM::VLD4LNqAsm_16:
6413 case ARM::VLD4LNqAsm_32: {
6414 MCInst TmpInst;
6415 // Shuffle the operands around so the lane index operand is in the
6416 // right place.
6417 unsigned Spacing;
6418 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6419 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 Spacing));
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 Spacing * 2));
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing * 3));
6426 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6427 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6428 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6429 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 Spacing));
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 Spacing * 2));
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6434 Spacing * 3));
6435 TmpInst.addOperand(Inst.getOperand(1)); // lane
6436 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6437 TmpInst.addOperand(Inst.getOperand(5));
6438 Inst = TmpInst;
6439 return true;
6440 }
6441
Jim Grosbachb78403c2012-01-24 23:47:04 +00006442 // VLD3DUP single 3-element structure to all lanes instructions.
6443 case ARM::VLD3DUPdAsm_8:
6444 case ARM::VLD3DUPdAsm_16:
6445 case ARM::VLD3DUPdAsm_32:
6446 case ARM::VLD3DUPqAsm_8:
6447 case ARM::VLD3DUPqAsm_16:
6448 case ARM::VLD3DUPqAsm_32: {
6449 MCInst TmpInst;
6450 unsigned Spacing;
6451 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 Spacing));
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 Spacing * 2));
6457 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6458 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6459 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6460 TmpInst.addOperand(Inst.getOperand(4));
6461 Inst = TmpInst;
6462 return true;
6463 }
6464
6465 case ARM::VLD3DUPdWB_fixed_Asm_8:
6466 case ARM::VLD3DUPdWB_fixed_Asm_16:
6467 case ARM::VLD3DUPdWB_fixed_Asm_32:
6468 case ARM::VLD3DUPqWB_fixed_Asm_8:
6469 case ARM::VLD3DUPqWB_fixed_Asm_16:
6470 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6471 MCInst TmpInst;
6472 unsigned Spacing;
6473 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6474 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing));
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 Spacing * 2));
6479 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6480 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6481 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6482 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6483 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6484 TmpInst.addOperand(Inst.getOperand(4));
6485 Inst = TmpInst;
6486 return true;
6487 }
6488
6489 case ARM::VLD3DUPdWB_register_Asm_8:
6490 case ARM::VLD3DUPdWB_register_Asm_16:
6491 case ARM::VLD3DUPdWB_register_Asm_32:
6492 case ARM::VLD3DUPqWB_register_Asm_8:
6493 case ARM::VLD3DUPqWB_register_Asm_16:
6494 case ARM::VLD3DUPqWB_register_Asm_32: {
6495 MCInst TmpInst;
6496 unsigned Spacing;
6497 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6498 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 Spacing));
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6502 Spacing * 2));
6503 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6504 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6505 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6506 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6507 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6508 TmpInst.addOperand(Inst.getOperand(5));
6509 Inst = TmpInst;
6510 return true;
6511 }
6512
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006513 // VLD3 multiple 3-element structure instructions.
6514 case ARM::VLD3dAsm_8:
6515 case ARM::VLD3dAsm_16:
6516 case ARM::VLD3dAsm_32:
6517 case ARM::VLD3qAsm_8:
6518 case ARM::VLD3qAsm_16:
6519 case ARM::VLD3qAsm_32: {
6520 MCInst TmpInst;
6521 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006522 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006523 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 Spacing));
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 Spacing * 2));
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6531 TmpInst.addOperand(Inst.getOperand(4));
6532 Inst = TmpInst;
6533 return true;
6534 }
6535
6536 case ARM::VLD3dWB_fixed_Asm_8:
6537 case ARM::VLD3dWB_fixed_Asm_16:
6538 case ARM::VLD3dWB_fixed_Asm_32:
6539 case ARM::VLD3qWB_fixed_Asm_8:
6540 case ARM::VLD3qWB_fixed_Asm_16:
6541 case ARM::VLD3qWB_fixed_Asm_32: {
6542 MCInst TmpInst;
6543 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006544 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006545 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing));
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing * 2));
6550 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6551 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6552 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6553 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6554 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6555 TmpInst.addOperand(Inst.getOperand(4));
6556 Inst = TmpInst;
6557 return true;
6558 }
6559
6560 case ARM::VLD3dWB_register_Asm_8:
6561 case ARM::VLD3dWB_register_Asm_16:
6562 case ARM::VLD3dWB_register_Asm_32:
6563 case ARM::VLD3qWB_register_Asm_8:
6564 case ARM::VLD3qWB_register_Asm_16:
6565 case ARM::VLD3qWB_register_Asm_32: {
6566 MCInst TmpInst;
6567 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006568 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006569 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing));
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing * 2));
6574 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6577 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6578 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(5));
6580 Inst = TmpInst;
6581 return true;
6582 }
6583
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006584 // VLD4DUP single 3-element structure to all lanes instructions.
6585 case ARM::VLD4DUPdAsm_8:
6586 case ARM::VLD4DUPdAsm_16:
6587 case ARM::VLD4DUPdAsm_32:
6588 case ARM::VLD4DUPqAsm_8:
6589 case ARM::VLD4DUPqAsm_16:
6590 case ARM::VLD4DUPqAsm_32: {
6591 MCInst TmpInst;
6592 unsigned Spacing;
6593 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6594 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing));
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing * 2));
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6600 Spacing * 3));
6601 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6602 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6603 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6604 TmpInst.addOperand(Inst.getOperand(4));
6605 Inst = TmpInst;
6606 return true;
6607 }
6608
6609 case ARM::VLD4DUPdWB_fixed_Asm_8:
6610 case ARM::VLD4DUPdWB_fixed_Asm_16:
6611 case ARM::VLD4DUPdWB_fixed_Asm_32:
6612 case ARM::VLD4DUPqWB_fixed_Asm_8:
6613 case ARM::VLD4DUPqWB_fixed_Asm_16:
6614 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6615 MCInst TmpInst;
6616 unsigned Spacing;
6617 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6618 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing));
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing * 2));
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing * 3));
6625 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6626 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6627 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6628 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6629 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6630 TmpInst.addOperand(Inst.getOperand(4));
6631 Inst = TmpInst;
6632 return true;
6633 }
6634
6635 case ARM::VLD4DUPdWB_register_Asm_8:
6636 case ARM::VLD4DUPdWB_register_Asm_16:
6637 case ARM::VLD4DUPdWB_register_Asm_32:
6638 case ARM::VLD4DUPqWB_register_Asm_8:
6639 case ARM::VLD4DUPqWB_register_Asm_16:
6640 case ARM::VLD4DUPqWB_register_Asm_32: {
6641 MCInst TmpInst;
6642 unsigned Spacing;
6643 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6644 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6646 Spacing));
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing * 2));
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 Spacing * 3));
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6653 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6654 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6655 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6656 TmpInst.addOperand(Inst.getOperand(5));
6657 Inst = TmpInst;
6658 return true;
6659 }
6660
6661 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006662 case ARM::VLD4dAsm_8:
6663 case ARM::VLD4dAsm_16:
6664 case ARM::VLD4dAsm_32:
6665 case ARM::VLD4qAsm_8:
6666 case ARM::VLD4qAsm_16:
6667 case ARM::VLD4qAsm_32: {
6668 MCInst TmpInst;
6669 unsigned Spacing;
6670 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6671 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6673 Spacing));
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing * 2));
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing * 3));
6678 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6679 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6680 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6681 TmpInst.addOperand(Inst.getOperand(4));
6682 Inst = TmpInst;
6683 return true;
6684 }
6685
6686 case ARM::VLD4dWB_fixed_Asm_8:
6687 case ARM::VLD4dWB_fixed_Asm_16:
6688 case ARM::VLD4dWB_fixed_Asm_32:
6689 case ARM::VLD4qWB_fixed_Asm_8:
6690 case ARM::VLD4qWB_fixed_Asm_16:
6691 case ARM::VLD4qWB_fixed_Asm_32: {
6692 MCInst TmpInst;
6693 unsigned Spacing;
6694 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6697 Spacing));
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing * 2));
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6701 Spacing * 3));
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6703 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6704 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6705 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6706 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6707 TmpInst.addOperand(Inst.getOperand(4));
6708 Inst = TmpInst;
6709 return true;
6710 }
6711
6712 case ARM::VLD4dWB_register_Asm_8:
6713 case ARM::VLD4dWB_register_Asm_16:
6714 case ARM::VLD4dWB_register_Asm_32:
6715 case ARM::VLD4qWB_register_Asm_8:
6716 case ARM::VLD4qWB_register_Asm_16:
6717 case ARM::VLD4qWB_register_Asm_32: {
6718 MCInst TmpInst;
6719 unsigned Spacing;
6720 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6721 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6723 Spacing));
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing * 2));
6726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 Spacing * 3));
6728 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6729 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6730 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6731 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6732 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6733 TmpInst.addOperand(Inst.getOperand(5));
6734 Inst = TmpInst;
6735 return true;
6736 }
6737
Jim Grosbach1a747242012-01-23 23:45:44 +00006738 // VST3 multiple 3-element structure instructions.
6739 case ARM::VST3dAsm_8:
6740 case ARM::VST3dAsm_16:
6741 case ARM::VST3dAsm_32:
6742 case ARM::VST3qAsm_8:
6743 case ARM::VST3qAsm_16:
6744 case ARM::VST3qAsm_32: {
6745 MCInst TmpInst;
6746 unsigned Spacing;
6747 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6748 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6749 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6750 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6752 Spacing));
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 Spacing * 2));
6755 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6756 TmpInst.addOperand(Inst.getOperand(4));
6757 Inst = TmpInst;
6758 return true;
6759 }
6760
6761 case ARM::VST3dWB_fixed_Asm_8:
6762 case ARM::VST3dWB_fixed_Asm_16:
6763 case ARM::VST3dWB_fixed_Asm_32:
6764 case ARM::VST3qWB_fixed_Asm_8:
6765 case ARM::VST3qWB_fixed_Asm_16:
6766 case ARM::VST3qWB_fixed_Asm_32: {
6767 MCInst TmpInst;
6768 unsigned Spacing;
6769 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6770 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6771 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6772 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6773 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6774 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6776 Spacing));
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 Spacing * 2));
6779 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6780 TmpInst.addOperand(Inst.getOperand(4));
6781 Inst = TmpInst;
6782 return true;
6783 }
6784
6785 case ARM::VST3dWB_register_Asm_8:
6786 case ARM::VST3dWB_register_Asm_16:
6787 case ARM::VST3dWB_register_Asm_32:
6788 case ARM::VST3qWB_register_Asm_8:
6789 case ARM::VST3qWB_register_Asm_16:
6790 case ARM::VST3qWB_register_Asm_32: {
6791 MCInst TmpInst;
6792 unsigned Spacing;
6793 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6794 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6795 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6796 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6797 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6799 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6800 Spacing));
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6802 Spacing * 2));
6803 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6804 TmpInst.addOperand(Inst.getOperand(5));
6805 Inst = TmpInst;
6806 return true;
6807 }
6808
Jim Grosbachda70eac2012-01-24 00:58:13 +00006809 // VST4 multiple 3-element structure instructions.
6810 case ARM::VST4dAsm_8:
6811 case ARM::VST4dAsm_16:
6812 case ARM::VST4dAsm_32:
6813 case ARM::VST4qAsm_8:
6814 case ARM::VST4qAsm_16:
6815 case ARM::VST4qAsm_32: {
6816 MCInst TmpInst;
6817 unsigned Spacing;
6818 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6819 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6820 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 Spacing));
6824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6825 Spacing * 2));
6826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6827 Spacing * 3));
6828 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6829 TmpInst.addOperand(Inst.getOperand(4));
6830 Inst = TmpInst;
6831 return true;
6832 }
6833
6834 case ARM::VST4dWB_fixed_Asm_8:
6835 case ARM::VST4dWB_fixed_Asm_16:
6836 case ARM::VST4dWB_fixed_Asm_32:
6837 case ARM::VST4qWB_fixed_Asm_8:
6838 case ARM::VST4qWB_fixed_Asm_16:
6839 case ARM::VST4qWB_fixed_Asm_32: {
6840 MCInst TmpInst;
6841 unsigned Spacing;
6842 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6843 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6844 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6845 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6846 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6847 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6848 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6849 Spacing));
6850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6851 Spacing * 2));
6852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6853 Spacing * 3));
6854 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(4));
6856 Inst = TmpInst;
6857 return true;
6858 }
6859
6860 case ARM::VST4dWB_register_Asm_8:
6861 case ARM::VST4dWB_register_Asm_16:
6862 case ARM::VST4dWB_register_Asm_32:
6863 case ARM::VST4qWB_register_Asm_8:
6864 case ARM::VST4qWB_register_Asm_16:
6865 case ARM::VST4qWB_register_Asm_32: {
6866 MCInst TmpInst;
6867 unsigned Spacing;
6868 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6869 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6870 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6871 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6872 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6873 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 Spacing));
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 Spacing * 2));
6878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6879 Spacing * 3));
6880 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6881 TmpInst.addOperand(Inst.getOperand(5));
6882 Inst = TmpInst;
6883 return true;
6884 }
6885
Jim Grosbachad66de12012-04-11 00:15:16 +00006886 // Handle encoding choice for the shift-immediate instructions.
6887 case ARM::t2LSLri:
6888 case ARM::t2LSRri:
6889 case ARM::t2ASRri: {
6890 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6891 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6892 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6893 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6894 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6895 unsigned NewOpc;
6896 switch (Inst.getOpcode()) {
6897 default: llvm_unreachable("unexpected opcode");
6898 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6899 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6900 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6901 }
6902 // The Thumb1 operands aren't in the same order. Awesome, eh?
6903 MCInst TmpInst;
6904 TmpInst.setOpcode(NewOpc);
6905 TmpInst.addOperand(Inst.getOperand(0));
6906 TmpInst.addOperand(Inst.getOperand(5));
6907 TmpInst.addOperand(Inst.getOperand(1));
6908 TmpInst.addOperand(Inst.getOperand(2));
6909 TmpInst.addOperand(Inst.getOperand(3));
6910 TmpInst.addOperand(Inst.getOperand(4));
6911 Inst = TmpInst;
6912 return true;
6913 }
6914 return false;
6915 }
6916
Jim Grosbach485e5622011-12-13 22:45:11 +00006917 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006918 case ARM::t2MOVsr:
6919 case ARM::t2MOVSsr: {
6920 // Which instruction to expand to depends on the CCOut operand and
6921 // whether we're in an IT block if the register operands are low
6922 // registers.
6923 bool isNarrow = false;
6924 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6925 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6926 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6927 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6928 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6929 isNarrow = true;
6930 MCInst TmpInst;
6931 unsigned newOpc;
6932 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6933 default: llvm_unreachable("unexpected opcode!");
6934 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6935 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6936 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6937 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6938 }
6939 TmpInst.setOpcode(newOpc);
6940 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6941 if (isNarrow)
6942 TmpInst.addOperand(MCOperand::CreateReg(
6943 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6944 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6945 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6946 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6947 TmpInst.addOperand(Inst.getOperand(5));
6948 if (!isNarrow)
6949 TmpInst.addOperand(MCOperand::CreateReg(
6950 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6951 Inst = TmpInst;
6952 return true;
6953 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006954 case ARM::t2MOVsi:
6955 case ARM::t2MOVSsi: {
6956 // Which instruction to expand to depends on the CCOut operand and
6957 // whether we're in an IT block if the register operands are low
6958 // registers.
6959 bool isNarrow = false;
6960 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6961 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6962 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6963 isNarrow = true;
6964 MCInst TmpInst;
6965 unsigned newOpc;
6966 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6967 default: llvm_unreachable("unexpected opcode!");
6968 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6969 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6970 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6971 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006972 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006973 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006974 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6975 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006976 TmpInst.setOpcode(newOpc);
6977 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6978 if (isNarrow)
6979 TmpInst.addOperand(MCOperand::CreateReg(
6980 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6981 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006982 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006983 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006984 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6985 TmpInst.addOperand(Inst.getOperand(4));
6986 if (!isNarrow)
6987 TmpInst.addOperand(MCOperand::CreateReg(
6988 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6989 Inst = TmpInst;
6990 return true;
6991 }
6992 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006993 case ARM::ASRr:
6994 case ARM::LSRr:
6995 case ARM::LSLr:
6996 case ARM::RORr: {
6997 ARM_AM::ShiftOpc ShiftTy;
6998 switch(Inst.getOpcode()) {
6999 default: llvm_unreachable("unexpected opcode!");
7000 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7001 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7002 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7003 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7004 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007005 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7006 MCInst TmpInst;
7007 TmpInst.setOpcode(ARM::MOVsr);
7008 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7009 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7010 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7011 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7012 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7013 TmpInst.addOperand(Inst.getOperand(4));
7014 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7015 Inst = TmpInst;
7016 return true;
7017 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007018 case ARM::ASRi:
7019 case ARM::LSRi:
7020 case ARM::LSLi:
7021 case ARM::RORi: {
7022 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007023 switch(Inst.getOpcode()) {
7024 default: llvm_unreachable("unexpected opcode!");
7025 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7026 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7027 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7028 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7029 }
7030 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007031 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007032 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007033 // A shift by 32 should be encoded as 0 when permitted
7034 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7035 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007036 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007037 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007038 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007039 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7040 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007041 if (Opc == ARM::MOVsi)
7042 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007043 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7044 TmpInst.addOperand(Inst.getOperand(4));
7045 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7046 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007047 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007048 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007049 case ARM::RRXi: {
7050 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7051 MCInst TmpInst;
7052 TmpInst.setOpcode(ARM::MOVsi);
7053 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7054 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7055 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7056 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7057 TmpInst.addOperand(Inst.getOperand(3));
7058 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7059 Inst = TmpInst;
7060 return true;
7061 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007062 case ARM::t2LDMIA_UPD: {
7063 // If this is a load of a single register, then we should use
7064 // a post-indexed LDR instruction instead, per the ARM ARM.
7065 if (Inst.getNumOperands() != 5)
7066 return false;
7067 MCInst TmpInst;
7068 TmpInst.setOpcode(ARM::t2LDR_POST);
7069 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7070 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7071 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7072 TmpInst.addOperand(MCOperand::CreateImm(4));
7073 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7074 TmpInst.addOperand(Inst.getOperand(3));
7075 Inst = TmpInst;
7076 return true;
7077 }
7078 case ARM::t2STMDB_UPD: {
7079 // If this is a store of a single register, then we should use
7080 // a pre-indexed STR instruction instead, per the ARM ARM.
7081 if (Inst.getNumOperands() != 5)
7082 return false;
7083 MCInst TmpInst;
7084 TmpInst.setOpcode(ARM::t2STR_PRE);
7085 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7086 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7087 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7088 TmpInst.addOperand(MCOperand::CreateImm(-4));
7089 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7090 TmpInst.addOperand(Inst.getOperand(3));
7091 Inst = TmpInst;
7092 return true;
7093 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007094 case ARM::LDMIA_UPD:
7095 // If this is a load of a single register via a 'pop', then we should use
7096 // a post-indexed LDR instruction instead, per the ARM ARM.
7097 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7098 Inst.getNumOperands() == 5) {
7099 MCInst TmpInst;
7100 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7101 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7102 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7103 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7104 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7105 TmpInst.addOperand(MCOperand::CreateImm(4));
7106 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7107 TmpInst.addOperand(Inst.getOperand(3));
7108 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007109 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007110 }
7111 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007112 case ARM::STMDB_UPD:
7113 // If this is a store of a single register via a 'push', then we should use
7114 // a pre-indexed STR instruction instead, per the ARM ARM.
7115 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7116 Inst.getNumOperands() == 5) {
7117 MCInst TmpInst;
7118 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7119 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7120 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7121 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7122 TmpInst.addOperand(MCOperand::CreateImm(-4));
7123 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7124 TmpInst.addOperand(Inst.getOperand(3));
7125 Inst = TmpInst;
7126 }
7127 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007128 case ARM::t2ADDri12:
7129 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7130 // mnemonic was used (not "addw"), encoding T3 is preferred.
7131 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7132 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7133 break;
7134 Inst.setOpcode(ARM::t2ADDri);
7135 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7136 break;
7137 case ARM::t2SUBri12:
7138 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7139 // mnemonic was used (not "subw"), encoding T3 is preferred.
7140 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7141 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7142 break;
7143 Inst.setOpcode(ARM::t2SUBri);
7144 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7145 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007146 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007147 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007148 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7149 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7150 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007151 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007152 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007153 return true;
7154 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007155 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007156 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007157 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007158 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7159 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7160 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007161 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007162 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007163 return true;
7164 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007165 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007166 case ARM::t2ADDri:
7167 case ARM::t2SUBri: {
7168 // If the destination and first source operand are the same, and
7169 // the flags are compatible with the current IT status, use encoding T2
7170 // instead of T3. For compatibility with the system 'as'. Make sure the
7171 // wide encoding wasn't explicit.
7172 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007173 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007174 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7175 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7176 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7177 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7178 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7179 break;
7180 MCInst TmpInst;
7181 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7182 ARM::tADDi8 : ARM::tSUBi8);
7183 TmpInst.addOperand(Inst.getOperand(0));
7184 TmpInst.addOperand(Inst.getOperand(5));
7185 TmpInst.addOperand(Inst.getOperand(0));
7186 TmpInst.addOperand(Inst.getOperand(2));
7187 TmpInst.addOperand(Inst.getOperand(3));
7188 TmpInst.addOperand(Inst.getOperand(4));
7189 Inst = TmpInst;
7190 return true;
7191 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007192 case ARM::t2ADDrr: {
7193 // If the destination and first source operand are the same, and
7194 // there's no setting of the flags, use encoding T2 instead of T3.
7195 // Note that this is only for ADD, not SUB. This mirrors the system
7196 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7197 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7198 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007199 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7200 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007201 break;
7202 MCInst TmpInst;
7203 TmpInst.setOpcode(ARM::tADDhirr);
7204 TmpInst.addOperand(Inst.getOperand(0));
7205 TmpInst.addOperand(Inst.getOperand(0));
7206 TmpInst.addOperand(Inst.getOperand(2));
7207 TmpInst.addOperand(Inst.getOperand(3));
7208 TmpInst.addOperand(Inst.getOperand(4));
7209 Inst = TmpInst;
7210 return true;
7211 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007212 case ARM::tADDrSP: {
7213 // If the non-SP source operand and the destination operand are not the
7214 // same, we need to use the 32-bit encoding if it's available.
7215 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7216 Inst.setOpcode(ARM::t2ADDrr);
7217 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7218 return true;
7219 }
7220 break;
7221 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007222 case ARM::tB:
7223 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007224 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007225 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007226 return true;
7227 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007228 break;
7229 case ARM::t2B:
7230 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007231 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007232 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007233 return true;
7234 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007235 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007236 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007237 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007238 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007239 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007240 return true;
7241 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007242 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007243 case ARM::tBcc:
7244 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007245 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007246 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007247 return true;
7248 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007249 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007250 case ARM::tLDMIA: {
7251 // If the register list contains any high registers, or if the writeback
7252 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7253 // instead if we're in Thumb2. Otherwise, this should have generated
7254 // an error in validateInstruction().
7255 unsigned Rn = Inst.getOperand(0).getReg();
7256 bool hasWritebackToken =
7257 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7258 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7259 bool listContainsBase;
7260 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7261 (!listContainsBase && !hasWritebackToken) ||
7262 (listContainsBase && hasWritebackToken)) {
7263 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7264 assert (isThumbTwo());
7265 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7266 // If we're switching to the updating version, we need to insert
7267 // the writeback tied operand.
7268 if (hasWritebackToken)
7269 Inst.insert(Inst.begin(),
7270 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007271 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007272 }
7273 break;
7274 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007275 case ARM::tSTMIA_UPD: {
7276 // If the register list contains any high registers, we need to use
7277 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7278 // should have generated an error in validateInstruction().
7279 unsigned Rn = Inst.getOperand(0).getReg();
7280 bool listContainsBase;
7281 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7282 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7283 assert (isThumbTwo());
7284 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007285 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007286 }
7287 break;
7288 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007289 case ARM::tPOP: {
7290 bool listContainsBase;
7291 // If the register list contains any high registers, we need to use
7292 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7293 // should have generated an error in validateInstruction().
7294 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007295 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007296 assert (isThumbTwo());
7297 Inst.setOpcode(ARM::t2LDMIA_UPD);
7298 // Add the base register and writeback operands.
7299 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7300 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007301 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007302 }
7303 case ARM::tPUSH: {
7304 bool listContainsBase;
7305 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007306 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007307 assert (isThumbTwo());
7308 Inst.setOpcode(ARM::t2STMDB_UPD);
7309 // Add the base register and writeback operands.
7310 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7311 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007312 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007313 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007314 case ARM::t2MOVi: {
7315 // If we can use the 16-bit encoding and the user didn't explicitly
7316 // request the 32-bit variant, transform it here.
7317 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007318 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007319 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7320 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7321 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007322 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7323 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7324 // The operands aren't in the same order for tMOVi8...
7325 MCInst TmpInst;
7326 TmpInst.setOpcode(ARM::tMOVi8);
7327 TmpInst.addOperand(Inst.getOperand(0));
7328 TmpInst.addOperand(Inst.getOperand(4));
7329 TmpInst.addOperand(Inst.getOperand(1));
7330 TmpInst.addOperand(Inst.getOperand(2));
7331 TmpInst.addOperand(Inst.getOperand(3));
7332 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007333 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007334 }
7335 break;
7336 }
7337 case ARM::t2MOVr: {
7338 // If we can use the 16-bit encoding and the user didn't explicitly
7339 // request the 32-bit variant, transform it here.
7340 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7341 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7342 Inst.getOperand(2).getImm() == ARMCC::AL &&
7343 Inst.getOperand(4).getReg() == ARM::CPSR &&
7344 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7345 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7346 // The operands aren't the same for tMOV[S]r... (no cc_out)
7347 MCInst TmpInst;
7348 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7349 TmpInst.addOperand(Inst.getOperand(0));
7350 TmpInst.addOperand(Inst.getOperand(1));
7351 TmpInst.addOperand(Inst.getOperand(2));
7352 TmpInst.addOperand(Inst.getOperand(3));
7353 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007354 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007355 }
7356 break;
7357 }
Jim Grosbach82213192011-09-19 20:29:33 +00007358 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007359 case ARM::t2SXTB:
7360 case ARM::t2UXTH:
7361 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007362 // If we can use the 16-bit encoding and the user didn't explicitly
7363 // request the 32-bit variant, transform it here.
7364 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7365 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7366 Inst.getOperand(2).getImm() == 0 &&
7367 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7368 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007369 unsigned NewOpc;
7370 switch (Inst.getOpcode()) {
7371 default: llvm_unreachable("Illegal opcode!");
7372 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7373 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7374 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7375 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7376 }
Jim Grosbach82213192011-09-19 20:29:33 +00007377 // The operands aren't the same for thumb1 (no rotate operand).
7378 MCInst TmpInst;
7379 TmpInst.setOpcode(NewOpc);
7380 TmpInst.addOperand(Inst.getOperand(0));
7381 TmpInst.addOperand(Inst.getOperand(1));
7382 TmpInst.addOperand(Inst.getOperand(3));
7383 TmpInst.addOperand(Inst.getOperand(4));
7384 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007385 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007386 }
7387 break;
7388 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007389 case ARM::MOVsi: {
7390 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007391 // rrx shifts and asr/lsr of #32 is encoded as 0
7392 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7393 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007394 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7395 // Shifting by zero is accepted as a vanilla 'MOVr'
7396 MCInst TmpInst;
7397 TmpInst.setOpcode(ARM::MOVr);
7398 TmpInst.addOperand(Inst.getOperand(0));
7399 TmpInst.addOperand(Inst.getOperand(1));
7400 TmpInst.addOperand(Inst.getOperand(3));
7401 TmpInst.addOperand(Inst.getOperand(4));
7402 TmpInst.addOperand(Inst.getOperand(5));
7403 Inst = TmpInst;
7404 return true;
7405 }
7406 return false;
7407 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007408 case ARM::ANDrsi:
7409 case ARM::ORRrsi:
7410 case ARM::EORrsi:
7411 case ARM::BICrsi:
7412 case ARM::SUBrsi:
7413 case ARM::ADDrsi: {
7414 unsigned newOpc;
7415 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7416 if (SOpc == ARM_AM::rrx) return false;
7417 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007418 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007419 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7420 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7421 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7422 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7423 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7424 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7425 }
7426 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007427 // The exception is for right shifts, where 0 == 32
7428 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7429 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007430 MCInst TmpInst;
7431 TmpInst.setOpcode(newOpc);
7432 TmpInst.addOperand(Inst.getOperand(0));
7433 TmpInst.addOperand(Inst.getOperand(1));
7434 TmpInst.addOperand(Inst.getOperand(2));
7435 TmpInst.addOperand(Inst.getOperand(4));
7436 TmpInst.addOperand(Inst.getOperand(5));
7437 TmpInst.addOperand(Inst.getOperand(6));
7438 Inst = TmpInst;
7439 return true;
7440 }
7441 return false;
7442 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007443 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007444 case ARM::t2IT: {
7445 // The mask bits for all but the first condition are represented as
7446 // the low bit of the condition code value implies 't'. We currently
7447 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007448 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007449 MCOperand &MO = Inst.getOperand(1);
7450 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007451 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007452 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007453 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007454 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007455 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007456 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007457 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007458
7459 // Set up the IT block state according to the IT instruction we just
7460 // matched.
7461 assert(!inITBlock() && "nested IT blocks?!");
7462 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7463 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7464 ITState.CurPosition = 0;
7465 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007466 break;
7467 }
Richard Bartona39625e2012-07-09 16:12:24 +00007468 case ARM::t2LSLrr:
7469 case ARM::t2LSRrr:
7470 case ARM::t2ASRrr:
7471 case ARM::t2SBCrr:
7472 case ARM::t2RORrr:
7473 case ARM::t2BICrr:
7474 {
Richard Bartond5660372012-07-09 16:14:28 +00007475 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007476 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7477 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7478 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007479 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7480 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007481 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7482 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7483 unsigned NewOpc;
7484 switch (Inst.getOpcode()) {
7485 default: llvm_unreachable("unexpected opcode");
7486 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7487 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7488 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7489 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7490 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7491 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7492 }
7493 MCInst TmpInst;
7494 TmpInst.setOpcode(NewOpc);
7495 TmpInst.addOperand(Inst.getOperand(0));
7496 TmpInst.addOperand(Inst.getOperand(5));
7497 TmpInst.addOperand(Inst.getOperand(1));
7498 TmpInst.addOperand(Inst.getOperand(2));
7499 TmpInst.addOperand(Inst.getOperand(3));
7500 TmpInst.addOperand(Inst.getOperand(4));
7501 Inst = TmpInst;
7502 return true;
7503 }
7504 return false;
7505 }
7506 case ARM::t2ANDrr:
7507 case ARM::t2EORrr:
7508 case ARM::t2ADCrr:
7509 case ARM::t2ORRrr:
7510 {
Richard Bartond5660372012-07-09 16:14:28 +00007511 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007512 // These instructions are special in that they are commutable, so shorter encodings
7513 // are available more often.
7514 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7515 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7516 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7517 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007518 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7519 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007520 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7521 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7522 unsigned NewOpc;
7523 switch (Inst.getOpcode()) {
7524 default: llvm_unreachable("unexpected opcode");
7525 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7526 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7527 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7528 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7529 }
7530 MCInst TmpInst;
7531 TmpInst.setOpcode(NewOpc);
7532 TmpInst.addOperand(Inst.getOperand(0));
7533 TmpInst.addOperand(Inst.getOperand(5));
7534 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7535 TmpInst.addOperand(Inst.getOperand(1));
7536 TmpInst.addOperand(Inst.getOperand(2));
7537 } else {
7538 TmpInst.addOperand(Inst.getOperand(2));
7539 TmpInst.addOperand(Inst.getOperand(1));
7540 }
7541 TmpInst.addOperand(Inst.getOperand(3));
7542 TmpInst.addOperand(Inst.getOperand(4));
7543 Inst = TmpInst;
7544 return true;
7545 }
7546 return false;
7547 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007548 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007549 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007550}
7551
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007552unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7553 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7554 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007555 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007556 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007557 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7558 assert(MCID.hasOptionalDef() &&
7559 "optionally flag setting instruction missing optional def operand");
7560 assert(MCID.NumOperands == Inst.getNumOperands() &&
7561 "operand count mismatch!");
7562 // Find the optional-def operand (cc_out).
7563 unsigned OpNo;
7564 for (OpNo = 0;
7565 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7566 ++OpNo)
7567 ;
7568 // If we're parsing Thumb1, reject it completely.
7569 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7570 return Match_MnemonicFail;
7571 // If we're parsing Thumb2, which form is legal depends on whether we're
7572 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007573 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7574 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007575 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007576 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7577 inITBlock())
7578 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007579 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007580 // Some high-register supporting Thumb1 encodings only allow both registers
7581 // to be from r0-r7 when in Thumb2.
7582 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7583 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7584 isARMLowRegister(Inst.getOperand(2).getReg()))
7585 return Match_RequiresThumb2;
7586 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007587 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007588 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7589 isARMLowRegister(Inst.getOperand(1).getReg()))
7590 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007591 return Match_Success;
7592}
7593
Jim Grosbach5117ef72012-04-24 22:40:08 +00007594static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007595bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007596MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007597 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007598 MCStreamer &Out, unsigned &ErrorInfo,
7599 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007600 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007601 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007602
Chad Rosier2f480a82012-10-12 22:53:36 +00007603 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007604 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007605 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007606 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007607 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007608 // Context sensitive operand constraints aren't handled by the matcher,
7609 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007610 if (validateInstruction(Inst, Operands)) {
7611 // Still progress the IT block, otherwise one wrong condition causes
7612 // nasty cascading errors.
7613 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007614 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007615 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007616
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007617 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007618 // encoding is selected. Loop on it while changes happen so the
7619 // individual transformations can chain off each other. E.g.,
7620 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7621 while (processInstruction(Inst, Operands))
7622 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007623
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007624 // Only move forward at the very end so that everything in validate
7625 // and process gets a consistent answer about whether we're in an IT
7626 // block.
7627 forwardITPosition();
7628
Jim Grosbach82f76d12012-01-25 19:52:01 +00007629 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7630 // doesn't actually encode.
7631 if (Inst.getOpcode() == ARM::ITasm)
7632 return false;
7633
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007634 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007635 Out.EmitInstruction(Inst);
7636 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007637 case Match_MissingFeature: {
7638 assert(ErrorInfo && "Unknown missing feature!");
7639 // Special case the error message for the very common case where only
7640 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7641 std::string Msg = "instruction requires:";
7642 unsigned Mask = 1;
7643 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7644 if (ErrorInfo & Mask) {
7645 Msg += " ";
7646 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7647 }
7648 Mask <<= 1;
7649 }
7650 return Error(IDLoc, Msg);
7651 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007652 case Match_InvalidOperand: {
7653 SMLoc ErrorLoc = IDLoc;
7654 if (ErrorInfo != ~0U) {
7655 if (ErrorInfo >= Operands.size())
7656 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007657
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007658 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7659 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7660 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007661
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007662 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007663 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007664 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007665 return Error(IDLoc, "invalid instruction",
7666 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007667 case Match_RequiresNotITBlock:
7668 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007669 case Match_RequiresITBlock:
7670 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007671 case Match_RequiresV6:
7672 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7673 case Match_RequiresThumb2:
7674 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007675 case Match_ImmRange0_4: {
7676 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7677 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7678 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7679 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007680 case Match_ImmRange0_15: {
7681 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7682 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7683 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7684 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007685 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007686
Eric Christopher91d7b902010-10-29 09:26:59 +00007687 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007688}
7689
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007690/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007691bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7692 StringRef IDVal = DirectiveID.getIdentifier();
7693 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007694 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007695 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007696 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007697 else if (IDVal == ".arm")
7698 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007699 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007700 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007701 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007702 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007703 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007704 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007705 else if (IDVal == ".unreq")
7706 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007707 else if (IDVal == ".arch")
7708 return parseDirectiveArch(DirectiveID.getLoc());
7709 else if (IDVal == ".eabi_attribute")
7710 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007711 else if (IDVal == ".fnstart")
7712 return parseDirectiveFnStart(DirectiveID.getLoc());
7713 else if (IDVal == ".fnend")
7714 return parseDirectiveFnEnd(DirectiveID.getLoc());
7715 else if (IDVal == ".cantunwind")
7716 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7717 else if (IDVal == ".personality")
7718 return parseDirectivePersonality(DirectiveID.getLoc());
7719 else if (IDVal == ".handlerdata")
7720 return parseDirectiveHandlerData(DirectiveID.getLoc());
7721 else if (IDVal == ".setfp")
7722 return parseDirectiveSetFP(DirectiveID.getLoc());
7723 else if (IDVal == ".pad")
7724 return parseDirectivePad(DirectiveID.getLoc());
7725 else if (IDVal == ".save")
7726 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7727 else if (IDVal == ".vsave")
7728 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007729 return true;
7730}
7731
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007732/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007733/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007734bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007735 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7736 for (;;) {
7737 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007738 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007739 return true;
7740
Eric Christopherbf7bc492013-01-09 03:52:05 +00007741 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007742
7743 if (getLexer().is(AsmToken::EndOfStatement))
7744 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007745
Kevin Enderbyccab3172009-09-15 00:27:25 +00007746 // FIXME: Improve diagnostic.
7747 if (getLexer().isNot(AsmToken::Comma))
7748 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007749 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007750 }
7751 }
7752
Sean Callanana83fd7d2010-01-19 20:27:46 +00007753 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007754 return false;
7755}
7756
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007757/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007758/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007759bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007760 if (getLexer().isNot(AsmToken::EndOfStatement))
7761 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007762 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007763
Tim Northovera2292d02013-06-10 23:20:58 +00007764 if (!hasThumb())
7765 return Error(L, "target does not support Thumb mode");
7766
Jim Grosbach7f882392011-12-07 18:04:19 +00007767 if (!isThumb())
7768 SwitchMode();
7769 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7770 return false;
7771}
7772
7773/// parseDirectiveARM
7774/// ::= .arm
7775bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7776 if (getLexer().isNot(AsmToken::EndOfStatement))
7777 return Error(L, "unexpected token in directive");
7778 Parser.Lex();
7779
Tim Northovera2292d02013-06-10 23:20:58 +00007780 if (!hasARM())
7781 return Error(L, "target does not support ARM mode");
7782
Jim Grosbach7f882392011-12-07 18:04:19 +00007783 if (isThumb())
7784 SwitchMode();
7785 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007786 return false;
7787}
7788
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007789/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007790/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007791bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007792 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7793 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007794 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007795 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007796
Jim Grosbach1152cc02011-12-21 22:30:16 +00007797 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007798 // ELF doesn't
7799 if (isMachO) {
7800 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007801 if (Tok.isNot(AsmToken::EndOfStatement)) {
7802 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7803 return Error(L, "unexpected token in .thumb_func directive");
7804 Name = Tok.getIdentifier();
7805 Parser.Lex(); // Consume the identifier token.
7806 needFuncName = false;
7807 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007808 }
7809
Jim Grosbach1152cc02011-12-21 22:30:16 +00007810 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007811 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007812
7813 // Eat the end of statement and any blank lines that follow.
7814 while (getLexer().is(AsmToken::EndOfStatement))
7815 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007816
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007817 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007818 // We really should be checking the next symbol definition even if there's
7819 // stuff in between.
7820 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007821 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007822 }
7823
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007824 // Mark symbol as a thumb symbol.
7825 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7826 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007827 return false;
7828}
7829
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007830/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007831/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007832bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007833 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007834 if (Tok.isNot(AsmToken::Identifier))
7835 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007836 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007837 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007838 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007839 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007840 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007841 else
7842 return Error(L, "unrecognized syntax mode in .syntax directive");
7843
7844 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007845 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007846 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007847
7848 // TODO tell the MC streamer the mode
7849 // getParser().getStreamer().Emit???();
7850 return false;
7851}
7852
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007853/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007854/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007855bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007856 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007857 if (Tok.isNot(AsmToken::Integer))
7858 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007859 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007860 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007861 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007862 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007863 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007864 else
7865 return Error(L, "invalid operand to .code directive");
7866
7867 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007868 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007869 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007870
Evan Cheng284b4672011-07-08 22:36:29 +00007871 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007872 if (!hasThumb())
7873 return Error(L, "target does not support Thumb mode");
7874
Jim Grosbachf471ac32011-09-06 18:46:23 +00007875 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007876 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007877 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007878 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007879 if (!hasARM())
7880 return Error(L, "target does not support ARM mode");
7881
Jim Grosbachf471ac32011-09-06 18:46:23 +00007882 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007883 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007884 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007885 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007886
Kevin Enderby146dcf22009-10-15 20:48:48 +00007887 return false;
7888}
7889
Jim Grosbachab5830e2011-12-14 02:16:11 +00007890/// parseDirectiveReq
7891/// ::= name .req registername
7892bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7893 Parser.Lex(); // Eat the '.req' token.
7894 unsigned Reg;
7895 SMLoc SRegLoc, ERegLoc;
7896 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007897 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007898 return Error(SRegLoc, "register name expected");
7899 }
7900
7901 // Shouldn't be anything else.
7902 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007903 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007904 return Error(Parser.getTok().getLoc(),
7905 "unexpected input in .req directive.");
7906 }
7907
7908 Parser.Lex(); // Consume the EndOfStatement
7909
7910 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7911 return Error(SRegLoc, "redefinition of '" + Name +
7912 "' does not match original.");
7913
7914 return false;
7915}
7916
7917/// parseDirectiveUneq
7918/// ::= .unreq registername
7919bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7920 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007921 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007922 return Error(L, "unexpected input in .unreq directive.");
7923 }
7924 RegisterReqs.erase(Parser.getTok().getIdentifier());
7925 Parser.Lex(); // Eat the identifier.
7926 return false;
7927}
7928
Jason W Kim135d2442011-12-20 17:38:12 +00007929/// parseDirectiveArch
7930/// ::= .arch token
7931bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7932 return true;
7933}
7934
7935/// parseDirectiveEabiAttr
7936/// ::= .eabi_attribute int, int
7937bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7938 return true;
7939}
7940
Logan Chien4ea23b52013-05-10 16:17:24 +00007941/// parseDirectiveFnStart
7942/// ::= .fnstart
7943bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7944 if (FnStartLoc.isValid()) {
7945 Error(L, ".fnstart starts before the end of previous one");
7946 Error(FnStartLoc, "previous .fnstart starts here");
7947 return true;
7948 }
7949
7950 FnStartLoc = L;
7951 getParser().getStreamer().EmitFnStart();
7952 return false;
7953}
7954
7955/// parseDirectiveFnEnd
7956/// ::= .fnend
7957bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7958 // Check the ordering of unwind directives
7959 if (!FnStartLoc.isValid())
7960 return Error(L, ".fnstart must precede .fnend directive");
7961
7962 // Reset the unwind directives parser state
7963 resetUnwindDirectiveParserState();
7964
7965 getParser().getStreamer().EmitFnEnd();
7966 return false;
7967}
7968
7969/// parseDirectiveCantUnwind
7970/// ::= .cantunwind
7971bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7972 // Check the ordering of unwind directives
7973 CantUnwindLoc = L;
7974 if (!FnStartLoc.isValid())
7975 return Error(L, ".fnstart must precede .cantunwind directive");
7976 if (HandlerDataLoc.isValid()) {
7977 Error(L, ".cantunwind can't be used with .handlerdata directive");
7978 Error(HandlerDataLoc, ".handlerdata was specified here");
7979 return true;
7980 }
7981 if (PersonalityLoc.isValid()) {
7982 Error(L, ".cantunwind can't be used with .personality directive");
7983 Error(PersonalityLoc, ".personality was specified here");
7984 return true;
7985 }
7986
7987 getParser().getStreamer().EmitCantUnwind();
7988 return false;
7989}
7990
7991/// parseDirectivePersonality
7992/// ::= .personality name
7993bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7994 // Check the ordering of unwind directives
7995 PersonalityLoc = L;
7996 if (!FnStartLoc.isValid())
7997 return Error(L, ".fnstart must precede .personality directive");
7998 if (CantUnwindLoc.isValid()) {
7999 Error(L, ".personality can't be used with .cantunwind directive");
8000 Error(CantUnwindLoc, ".cantunwind was specified here");
8001 return true;
8002 }
8003 if (HandlerDataLoc.isValid()) {
8004 Error(L, ".personality must precede .handlerdata directive");
8005 Error(HandlerDataLoc, ".handlerdata was specified here");
8006 return true;
8007 }
8008
8009 // Parse the name of the personality routine
8010 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8011 Parser.eatToEndOfStatement();
8012 return Error(L, "unexpected input in .personality directive.");
8013 }
8014 StringRef Name(Parser.getTok().getIdentifier());
8015 Parser.Lex();
8016
8017 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8018 getParser().getStreamer().EmitPersonality(PR);
8019 return false;
8020}
8021
8022/// parseDirectiveHandlerData
8023/// ::= .handlerdata
8024bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8025 // Check the ordering of unwind directives
8026 HandlerDataLoc = L;
8027 if (!FnStartLoc.isValid())
8028 return Error(L, ".fnstart must precede .personality directive");
8029 if (CantUnwindLoc.isValid()) {
8030 Error(L, ".handlerdata can't be used with .cantunwind directive");
8031 Error(CantUnwindLoc, ".cantunwind was specified here");
8032 return true;
8033 }
8034
8035 getParser().getStreamer().EmitHandlerData();
8036 return false;
8037}
8038
8039/// parseDirectiveSetFP
8040/// ::= .setfp fpreg, spreg [, offset]
8041bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8042 // Check the ordering of unwind directives
8043 if (!FnStartLoc.isValid())
8044 return Error(L, ".fnstart must precede .setfp directive");
8045 if (HandlerDataLoc.isValid())
8046 return Error(L, ".setfp must precede .handlerdata directive");
8047
8048 // Parse fpreg
8049 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8050 int NewFPReg = tryParseRegister();
8051 if (NewFPReg == -1)
8052 return Error(NewFPRegLoc, "frame pointer register expected");
8053
8054 // Consume comma
8055 if (!Parser.getTok().is(AsmToken::Comma))
8056 return Error(Parser.getTok().getLoc(), "comma expected");
8057 Parser.Lex(); // skip comma
8058
8059 // Parse spreg
8060 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8061 int NewSPReg = tryParseRegister();
8062 if (NewSPReg == -1)
8063 return Error(NewSPRegLoc, "stack pointer register expected");
8064
8065 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8066 return Error(NewSPRegLoc,
8067 "register should be either $sp or the latest fp register");
8068
8069 // Update the frame pointer register
8070 FPReg = NewFPReg;
8071
8072 // Parse offset
8073 int64_t Offset = 0;
8074 if (Parser.getTok().is(AsmToken::Comma)) {
8075 Parser.Lex(); // skip comma
8076
8077 if (Parser.getTok().isNot(AsmToken::Hash) &&
8078 Parser.getTok().isNot(AsmToken::Dollar)) {
8079 return Error(Parser.getTok().getLoc(), "'#' expected");
8080 }
8081 Parser.Lex(); // skip hash token.
8082
8083 const MCExpr *OffsetExpr;
8084 SMLoc ExLoc = Parser.getTok().getLoc();
8085 SMLoc EndLoc;
8086 if (getParser().parseExpression(OffsetExpr, EndLoc))
8087 return Error(ExLoc, "malformed setfp offset");
8088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8089 if (!CE)
8090 return Error(ExLoc, "setfp offset must be an immediate");
8091
8092 Offset = CE->getValue();
8093 }
8094
8095 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8096 static_cast<unsigned>(NewSPReg),
8097 Offset);
8098 return false;
8099}
8100
8101/// parseDirective
8102/// ::= .pad offset
8103bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8104 // Check the ordering of unwind directives
8105 if (!FnStartLoc.isValid())
8106 return Error(L, ".fnstart must precede .pad directive");
8107 if (HandlerDataLoc.isValid())
8108 return Error(L, ".pad must precede .handlerdata directive");
8109
8110 // Parse the offset
8111 if (Parser.getTok().isNot(AsmToken::Hash) &&
8112 Parser.getTok().isNot(AsmToken::Dollar)) {
8113 return Error(Parser.getTok().getLoc(), "'#' expected");
8114 }
8115 Parser.Lex(); // skip hash token.
8116
8117 const MCExpr *OffsetExpr;
8118 SMLoc ExLoc = Parser.getTok().getLoc();
8119 SMLoc EndLoc;
8120 if (getParser().parseExpression(OffsetExpr, EndLoc))
8121 return Error(ExLoc, "malformed pad offset");
8122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8123 if (!CE)
8124 return Error(ExLoc, "pad offset must be an immediate");
8125
8126 getParser().getStreamer().EmitPad(CE->getValue());
8127 return false;
8128}
8129
8130/// parseDirectiveRegSave
8131/// ::= .save { registers }
8132/// ::= .vsave { registers }
8133bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8134 // Check the ordering of unwind directives
8135 if (!FnStartLoc.isValid())
8136 return Error(L, ".fnstart must precede .save or .vsave directives");
8137 if (HandlerDataLoc.isValid())
8138 return Error(L, ".save or .vsave must precede .handlerdata directive");
8139
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008140 // RAII object to make sure parsed operands are deleted.
8141 struct CleanupObject {
8142 SmallVector<MCParsedAsmOperand *, 1> Operands;
8143 ~CleanupObject() {
8144 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8145 delete Operands[I];
8146 }
8147 } CO;
8148
Logan Chien4ea23b52013-05-10 16:17:24 +00008149 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008150 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008151 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008152 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008153 if (!IsVector && !Op->isRegList())
8154 return Error(L, ".save expects GPR registers");
8155 if (IsVector && !Op->isDPRRegList())
8156 return Error(L, ".vsave expects DPR registers");
8157
8158 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8159 return false;
8160}
8161
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008162/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008163extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008164 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8165 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008166}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008167
Chris Lattner3e4582a2010-09-06 19:11:01 +00008168#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008169#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008170#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008171#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008172
8173// Define this matcher function after the auto-generated include so we
8174// have the match class enum definitions.
8175unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8176 unsigned Kind) {
8177 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8178 // If the kind is a token for a literal immediate, check if our asm
8179 // operand matches. This is for InstAliases which have a fixed-value
8180 // immediate in the syntax.
8181 if (Kind == MCK__35_0 && Op->isImm()) {
8182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8183 if (!CE)
8184 return Match_InvalidOperand;
8185 if (CE->getValue() == 0)
8186 return Match_Success;
8187 }
8188 return Match_InvalidOperand;
8189}