blob: fc1faffd0bb4cfc999decc777b5ee555fe177386 [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000093 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000094 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Tim Northovera2292d02013-06-10 23:20:58 +0000155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
157 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
160 }
James Molloy21efa7d2011-09-28 14:21:38 +0000161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
163 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
166 }
Tim Northovera2292d02013-06-10 23:20:58 +0000167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
169 }
170
Evan Cheng284b4672011-07-08 22:36:29 +0000171 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000174 }
James Molloy21efa7d2011-09-28 14:21:38 +0000175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
177 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000178
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000179 /// @name Auto-generated Match Functions
180 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000181
Chris Lattner3e4582a2010-09-06 19:11:01 +0000182#define GET_ASSEMBLER_HEADER
183#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000184
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000185 /// }
186
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000194 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000195 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000198 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
206 }
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
209 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
219 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000220
221 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000224 bool validateInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000226 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000228 bool shouldOmitCCOutOperand(StringRef Mnemonic,
229 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000230 bool shouldOmitPredicateOperand(StringRef Mnemonic,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000232
Kevin Enderbyccab3172009-09-15 00:27:25 +0000233public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000234 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000235 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000236 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000237 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000238 Match_RequiresThumb2,
239#define GET_OPERAND_DIAGNOSTIC_TYPES
240#include "ARMGenAsmMatcher.inc"
241
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000242 };
243
Evan Cheng91111d22011-07-09 05:47:46 +0000244 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000245 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000247
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000248 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000249 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000250
Evan Cheng4d1ca962011-07-08 01:53:10 +0000251 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000252 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000253
254 // Not in an ITBlock to start with.
255 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000256
257 // Set ELF header flags.
258 // FIXME: This should eventually end up somewhere else where more
259 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000260 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
261 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
262 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000263 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000264
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000265 // Implementation of the MCTargetAsmParser interface:
266 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000267 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
268 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000269 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000270 bool ParseDirective(AsmToken DirectiveID);
271
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000272 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000273 unsigned checkTargetMatchPredicate(MCInst &Inst);
274
Chad Rosier49963552012-10-13 00:26:04 +0000275 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000276 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000277 MCStreamer &Out, unsigned &ErrorInfo,
278 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000279};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000280} // end anonymous namespace
281
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000282namespace {
283
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000284/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000285/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000286class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000287 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000288 k_CondCode,
289 k_CCOut,
290 k_ITCondMask,
291 k_CoprocNum,
292 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000293 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000294 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000295 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000296 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000297 k_Memory,
298 k_PostIndexRegister,
299 k_MSRMask,
300 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000301 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000302 k_Register,
303 k_RegisterList,
304 k_DPRRegisterList,
305 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000306 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000307 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000308 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000309 k_ShiftedRegister,
310 k_ShiftedImmediate,
311 k_ShifterImmediate,
312 k_RotateImmediate,
313 k_BitfieldDescriptor,
314 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000315 } Kind;
316
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000317 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000318 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000319
Eric Christopher8996c5d2013-03-15 00:42:55 +0000320 struct CCOp {
321 ARMCC::CondCodes Val;
322 };
323
324 struct CopOp {
325 unsigned Val;
326 };
327
328 struct CoprocOptionOp {
329 unsigned Val;
330 };
331
332 struct ITMaskOp {
333 unsigned Mask:4;
334 };
335
336 struct MBOptOp {
337 ARM_MB::MemBOpt Val;
338 };
339
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000340 struct ISBOptOp {
341 ARM_ISB::InstSyncBOpt Val;
342 };
343
Eric Christopher8996c5d2013-03-15 00:42:55 +0000344 struct IFlagsOp {
345 ARM_PROC::IFlags Val;
346 };
347
348 struct MMaskOp {
349 unsigned Val;
350 };
351
352 struct TokOp {
353 const char *Data;
354 unsigned Length;
355 };
356
357 struct RegOp {
358 unsigned RegNum;
359 };
360
361 // A vector register list is a sequential list of 1 to 4 registers.
362 struct VectorListOp {
363 unsigned RegNum;
364 unsigned Count;
365 unsigned LaneIndex;
366 bool isDoubleSpaced;
367 };
368
369 struct VectorIndexOp {
370 unsigned Val;
371 };
372
373 struct ImmOp {
374 const MCExpr *Val;
375 };
376
377 /// Combined record for all forms of ARM address expressions.
378 struct MemoryOp {
379 unsigned BaseRegNum;
380 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
381 // was specified.
382 const MCConstantExpr *OffsetImm; // Offset immediate value
383 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
384 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
385 unsigned ShiftImm; // shift for OffsetReg.
386 unsigned Alignment; // 0 = no alignment specified
387 // n = alignment in bytes (2, 4, 8, 16, or 32)
388 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
389 };
390
391 struct PostIdxRegOp {
392 unsigned RegNum;
393 bool isAdd;
394 ARM_AM::ShiftOpc ShiftTy;
395 unsigned ShiftImm;
396 };
397
398 struct ShifterImmOp {
399 bool isASR;
400 unsigned Imm;
401 };
402
403 struct RegShiftedRegOp {
404 ARM_AM::ShiftOpc ShiftTy;
405 unsigned SrcReg;
406 unsigned ShiftReg;
407 unsigned ShiftImm;
408 };
409
410 struct RegShiftedImmOp {
411 ARM_AM::ShiftOpc ShiftTy;
412 unsigned SrcReg;
413 unsigned ShiftImm;
414 };
415
416 struct RotImmOp {
417 unsigned Imm;
418 };
419
420 struct BitfieldOp {
421 unsigned LSB;
422 unsigned Width;
423 };
424
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000425 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000426 struct CCOp CC;
427 struct CopOp Cop;
428 struct CoprocOptionOp CoprocOption;
429 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000430 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000431 struct ITMaskOp ITMask;
432 struct IFlagsOp IFlags;
433 struct MMaskOp MMask;
434 struct TokOp Tok;
435 struct RegOp Reg;
436 struct VectorListOp VectorList;
437 struct VectorIndexOp VectorIndex;
438 struct ImmOp Imm;
439 struct MemoryOp Memory;
440 struct PostIdxRegOp PostIdxReg;
441 struct ShifterImmOp ShifterImm;
442 struct RegShiftedRegOp RegShiftedReg;
443 struct RegShiftedImmOp RegShiftedImm;
444 struct RotImmOp RotImm;
445 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000446 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000447
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000448 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
449public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000450 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
451 Kind = o.Kind;
452 StartLoc = o.StartLoc;
453 EndLoc = o.EndLoc;
454 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000455 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000456 CC = o.CC;
457 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000458 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000459 ITMask = o.ITMask;
460 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000462 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_CCOut:
465 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000466 Reg = o.Reg;
467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000468 case k_RegisterList:
469 case k_DPRRegisterList:
470 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000471 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000472 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000473 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000474 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000475 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000476 VectorList = o.VectorList;
477 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000478 case k_CoprocNum:
479 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000480 Cop = o.Cop;
481 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000482 case k_CoprocOption:
483 CoprocOption = o.CoprocOption;
484 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000485 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000486 Imm = o.Imm;
487 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000488 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000489 MBOpt = o.MBOpt;
490 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000491 case k_InstSyncBarrierOpt:
492 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000493 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000494 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000496 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000497 PostIdxReg = o.PostIdxReg;
498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000500 MMask = o.MMask;
501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000503 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000505 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000506 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000508 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000509 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000510 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000511 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000512 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000514 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000515 RotImm = o.RotImm;
516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000517 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000518 Bitfield = o.Bitfield;
519 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000520 case k_VectorIndex:
521 VectorIndex = o.VectorIndex;
522 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000523 }
524 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000525
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000526 /// getStartLoc - Get the location of the first token of this operand.
527 SMLoc getStartLoc() const { return StartLoc; }
528 /// getEndLoc - Get the location of the last token of this operand.
529 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000530 /// getLocRange - Get the range between the first and last token of this
531 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000532 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
533
Daniel Dunbard8042b72010-08-11 06:36:53 +0000534 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000535 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000536 return CC.Val;
537 }
538
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000539 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000540 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000541 return Cop.Val;
542 }
543
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000544 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000546 return StringRef(Tok.Data, Tok.Length);
547 }
548
549 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000550 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000551 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000552 }
553
Bill Wendlingbed94652010-11-09 23:28:44 +0000554 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000555 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
556 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000557 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000558 }
559
Kevin Enderbyf5079942009-10-13 22:19:02 +0000560 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000561 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000562 return Imm.Val;
563 }
564
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000565 unsigned getVectorIndex() const {
566 assert(Kind == k_VectorIndex && "Invalid access!");
567 return VectorIndex.Val;
568 }
569
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000570 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000572 return MBOpt.Val;
573 }
574
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000575 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
576 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
577 return ISBOpt.Val;
578 }
579
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000580 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000582 return IFlags.Val;
583 }
584
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000585 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000586 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000587 return MMask.Val;
588 }
589
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 bool isCoprocNum() const { return Kind == k_CoprocNum; }
591 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000592 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000593 bool isCondCode() const { return Kind == k_CondCode; }
594 bool isCCOut() const { return Kind == k_CCOut; }
595 bool isITMask() const { return Kind == k_ITCondMask; }
596 bool isITCondCode() const { return Kind == k_CondCode; }
597 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000598 // checks whether this operand is an unsigned offset which fits is a field
599 // of specified width and scaled by a specific number of bits
600 template<unsigned width, unsigned scale>
601 bool isUnsignedOffset() const {
602 if (!isImm()) return false;
603 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
604 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
605 int64_t Val = CE->getValue();
606 int64_t Align = 1LL << scale;
607 int64_t Max = Align * ((1LL << width) - 1);
608 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
609 }
610 return false;
611 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000612 bool isFPImm() const {
613 if (!isImm()) return false;
614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
615 if (!CE) return false;
616 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
617 return Val != -1;
618 }
Jim Grosbachea231912011-12-22 22:19:05 +0000619 bool isFBits16() const {
620 if (!isImm()) return false;
621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
622 if (!CE) return false;
623 int64_t Value = CE->getValue();
624 return Value >= 0 && Value <= 16;
625 }
626 bool isFBits32() const {
627 if (!isImm()) return false;
628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
629 if (!CE) return false;
630 int64_t Value = CE->getValue();
631 return Value >= 1 && Value <= 32;
632 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000633 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000634 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int64_t Value = CE->getValue();
638 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
639 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000640 bool isImm0_4() const {
641 if (!isImm()) return false;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value < 5;
646 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000647 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000648 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
653 }
654 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000655 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
660 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000661 bool isImm0_508s4Neg() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = -CE->getValue();
666 // explicitly exclude zero. we want that to use the normal 0_508 version.
667 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
668 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000669 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000670 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int64_t Value = CE->getValue();
674 return Value >= 0 && Value < 256;
675 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000676 bool isImm0_4095() const {
677 if (!isImm()) return false;
678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
679 if (!CE) return false;
680 int64_t Value = CE->getValue();
681 return Value >= 0 && Value < 4096;
682 }
683 bool isImm0_4095Neg() const {
684 if (!isImm()) return false;
685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
686 if (!CE) return false;
687 int64_t Value = -CE->getValue();
688 return Value > 0 && Value < 4096;
689 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000690 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000691 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return Value >= 0 && Value < 2;
696 }
697 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000698 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return Value >= 0 && Value < 4;
703 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000704 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000705 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = CE->getValue();
709 return Value >= 0 && Value < 8;
710 }
711 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value >= 0 && Value < 16;
717 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000718 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000719 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 32;
724 }
Jim Grosbach00326402011-12-08 01:30:04 +0000725 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000726 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = CE->getValue();
730 return Value >= 0 && Value < 64;
731 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000732 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000733 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value == 8;
738 }
739 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000740 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value == 16;
745 }
746 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000747 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value == 32;
752 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000753 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000754 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value > 0 && Value <= 8;
759 }
760 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000761 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value > 0 && Value <= 16;
766 }
767 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value > 0 && Value <= 32;
773 }
774 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value > 0 && Value <= 64;
780 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000781 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value > 0 && Value < 8;
787 }
788 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value < 16;
794 }
795 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000796 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value > 0 && Value < 32;
801 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000802 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value < 17;
808 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000809 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000810 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return Value > 0 && Value < 33;
815 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000816 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return Value >= 0 && Value < 33;
822 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000823 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000824 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return Value >= 0 && Value < 65536;
829 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000830 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000831 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 // If it's not a constant expression, it'll generate a fixup and be
834 // handled later.
835 if (!CE) return true;
836 int64_t Value = CE->getValue();
837 return Value >= 0 && Value < 65536;
838 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000839 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000840 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value >= 0 && Value <= 0xffffff;
845 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000846 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value > 0 && Value < 33;
852 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000853 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 32;
859 }
860 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value > 0 && Value <= 32;
866 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000867 bool isAdrLabel() const {
868 // If we have an immediate that's not a constant, treat it as a label
869 // reference needing a fixup. If it is a constant, but it can't fit
870 // into shift immediate encoding, we reject it.
871 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
872 else return (isARMSOImm() || isARMSOImmNeg());
873 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000874 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000875 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return ARM_AM::getSOImmVal(Value) != -1;
880 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000881 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return ARM_AM::getSOImmVal(~Value) != -1;
887 }
Jim Grosbach30506252011-12-08 00:31:07 +0000888 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000889 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000893 // Only use this when not representable as a plain so_imm.
894 return ARM_AM::getSOImmVal(Value) == -1 &&
895 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000896 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000897 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000898 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
900 if (!CE) return false;
901 int64_t Value = CE->getValue();
902 return ARM_AM::getT2SOImmVal(Value) != -1;
903 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000904 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000905 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Value = CE->getValue();
909 return ARM_AM::getT2SOImmVal(~Value) != -1;
910 }
Jim Grosbach30506252011-12-08 00:31:07 +0000911 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000912 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
914 if (!CE) return false;
915 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000916 // Only use this when not representable as a plain so_imm.
917 return ARM_AM::getT2SOImmVal(Value) == -1 &&
918 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000919 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000920 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000921 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return Value == 1 || Value == 0;
926 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000927 bool isReg() const { return Kind == k_Register; }
928 bool isRegList() const { return Kind == k_RegisterList; }
929 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
930 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
931 bool isToken() const { return Kind == k_Token; }
932 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000933 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000934 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000935 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
936 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
937 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
938 bool isRotImm() const { return Kind == k_RotateImmediate; }
939 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
940 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000941 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000942 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000943 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000944 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000945 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000946 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000947 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000948 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
949 (alignOK || Memory.Alignment == 0);
950 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000951 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000952 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000953 return false;
954 // Base register must be PC.
955 if (Memory.BaseRegNum != ARM::PC)
956 return false;
957 // Immediate offset in range [-4095, 4095].
958 if (!Memory.OffsetImm) return true;
959 int64_t Val = Memory.OffsetImm->getValue();
960 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
961 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000962 bool isAlignedMemory() const {
963 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000964 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000965 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000966 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000967 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000968 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000969 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000970 if (!Memory.OffsetImm) return true;
971 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000972 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000973 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000974 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000975 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000976 // Immediate offset in range [-4095, 4095].
977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
978 if (!CE) return false;
979 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +0000980 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +0000981 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000982 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000983 // If we have an immediate that's not a constant, treat it as a label
984 // reference needing a fixup. If it is a constant, it's something else
985 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000986 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000987 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000988 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000989 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000990 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000991 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000992 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000993 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000994 if (!Memory.OffsetImm) return true;
995 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000996 // The #-0 offset is encoded as INT32_MIN, and we have to check
997 // for this too.
998 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000999 }
1000 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001001 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001002 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001003 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001004 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1005 // Immediate offset in range [-255, 255].
1006 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1007 if (!CE) return false;
1008 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001009 // Special case, #-0 is INT32_MIN.
1010 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001011 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001012 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001013 // If we have an immediate that's not a constant, treat it as a label
1014 // reference needing a fixup. If it is a constant, it's something else
1015 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001016 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001017 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001018 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001019 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001020 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001021 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001022 if (!Memory.OffsetImm) return true;
1023 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001024 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001025 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001026 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001027 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001028 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001029 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001030 return false;
1031 return true;
1032 }
1033 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001034 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001035 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1036 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001037 return false;
1038 return true;
1039 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001040 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001041 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001042 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001043 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001044 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001045 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001046 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001047 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001048 return false;
1049 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001050 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001051 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001052 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001053 return false;
1054 return true;
1055 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001056 bool isMemThumbRR() const {
1057 // Thumb reg+reg addressing is simple. Just two registers, a base and
1058 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001059 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001060 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001061 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001062 return isARMLowRegister(Memory.BaseRegNum) &&
1063 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001064 }
1065 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001066 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001067 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001068 return false;
1069 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001070 if (!Memory.OffsetImm) return true;
1071 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001072 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1073 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001074 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001075 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001076 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001077 return false;
1078 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001079 if (!Memory.OffsetImm) return true;
1080 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001081 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1082 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001083 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001084 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001085 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001086 return false;
1087 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001088 if (!Memory.OffsetImm) return true;
1089 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001090 return Val >= 0 && Val <= 31;
1091 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001092 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001094 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001095 return false;
1096 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001097 if (!Memory.OffsetImm) return true;
1098 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001099 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001100 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001101 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001102 // If we have an immediate that's not a constant, treat it as a label
1103 // reference needing a fixup. If it is a constant, it's something else
1104 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001105 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001106 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001107 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001108 return false;
1109 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001110 if (!Memory.OffsetImm) return true;
1111 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001112 // Special case, #-0 is INT32_MIN.
1113 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001114 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001115 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001116 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001117 return false;
1118 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001119 if (!Memory.OffsetImm) return true;
1120 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001121 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1122 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001123 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001124 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001125 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001126 // Base reg of PC isn't allowed for these encodings.
1127 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001128 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001129 if (!Memory.OffsetImm) return true;
1130 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001131 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001132 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001133 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001134 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001135 return false;
1136 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001137 if (!Memory.OffsetImm) return true;
1138 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001139 return Val >= 0 && Val < 256;
1140 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001141 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001142 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001143 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001144 // Base reg of PC isn't allowed for these encodings.
1145 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001146 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001147 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001148 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001149 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001150 }
1151 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001152 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001153 return false;
1154 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001155 if (!Memory.OffsetImm) return true;
1156 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001157 return (Val >= 0 && Val < 4096);
1158 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001159 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001160 // If we have an immediate that's not a constant, treat it as a label
1161 // reference needing a fixup. If it is a constant, it's something else
1162 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001163 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001164 return true;
1165
Chad Rosier41099832012-09-11 23:02:35 +00001166 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001167 return false;
1168 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001169 if (!Memory.OffsetImm) return true;
1170 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001171 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001172 }
1173 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001174 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001175 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1176 if (!CE) return false;
1177 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001178 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001179 }
Jim Grosbach93981412011-10-11 21:55:36 +00001180 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001181 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1183 if (!CE) return false;
1184 int64_t Val = CE->getValue();
1185 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1186 (Val == INT32_MIN);
1187 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001188
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001189 bool isMSRMask() const { return Kind == k_MSRMask; }
1190 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001191
Jim Grosbach741cd732011-10-17 22:26:03 +00001192 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001193 bool isSingleSpacedVectorList() const {
1194 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1195 }
1196 bool isDoubleSpacedVectorList() const {
1197 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1198 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001199 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001200 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001201 return VectorList.Count == 1;
1202 }
1203
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001204 bool isVecListDPair() const {
1205 if (!isSingleSpacedVectorList()) return false;
1206 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1207 .contains(VectorList.RegNum));
1208 }
1209
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001210 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001211 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001212 return VectorList.Count == 3;
1213 }
1214
Jim Grosbach846bcff2011-10-21 20:35:01 +00001215 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001216 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001217 return VectorList.Count == 4;
1218 }
1219
Jim Grosbache5307f92012-03-05 21:43:40 +00001220 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001221 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001222 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1223 .contains(VectorList.RegNum));
1224 }
1225
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001226 bool isVecListThreeQ() const {
1227 if (!isDoubleSpacedVectorList()) return false;
1228 return VectorList.Count == 3;
1229 }
1230
Jim Grosbach1e946a42012-01-24 00:43:12 +00001231 bool isVecListFourQ() const {
1232 if (!isDoubleSpacedVectorList()) return false;
1233 return VectorList.Count == 4;
1234 }
1235
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001236 bool isSingleSpacedVectorAllLanes() const {
1237 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1238 }
1239 bool isDoubleSpacedVectorAllLanes() const {
1240 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1241 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001242 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001243 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001244 return VectorList.Count == 1;
1245 }
1246
Jim Grosbach13a292c2012-03-06 22:01:44 +00001247 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001248 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001249 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1250 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001251 }
1252
Jim Grosbached428bc2012-03-06 23:10:38 +00001253 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001254 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001255 return VectorList.Count == 2;
1256 }
1257
Jim Grosbachb78403c2012-01-24 23:47:04 +00001258 bool isVecListThreeDAllLanes() const {
1259 if (!isSingleSpacedVectorAllLanes()) return false;
1260 return VectorList.Count == 3;
1261 }
1262
1263 bool isVecListThreeQAllLanes() const {
1264 if (!isDoubleSpacedVectorAllLanes()) return false;
1265 return VectorList.Count == 3;
1266 }
1267
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001268 bool isVecListFourDAllLanes() const {
1269 if (!isSingleSpacedVectorAllLanes()) return false;
1270 return VectorList.Count == 4;
1271 }
1272
1273 bool isVecListFourQAllLanes() const {
1274 if (!isDoubleSpacedVectorAllLanes()) return false;
1275 return VectorList.Count == 4;
1276 }
1277
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001278 bool isSingleSpacedVectorIndexed() const {
1279 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1280 }
1281 bool isDoubleSpacedVectorIndexed() const {
1282 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1283 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001284 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001285 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001286 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1287 }
1288
Jim Grosbachda511042011-12-14 23:35:06 +00001289 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001290 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001291 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1292 }
1293
1294 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001295 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001296 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1297 }
1298
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001299 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001300 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001301 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1302 }
1303
Jim Grosbachda511042011-12-14 23:35:06 +00001304 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001305 if (!isSingleSpacedVectorIndexed()) return false;
1306 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1307 }
1308
1309 bool isVecListTwoQWordIndexed() const {
1310 if (!isDoubleSpacedVectorIndexed()) return false;
1311 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1312 }
1313
1314 bool isVecListTwoQHWordIndexed() const {
1315 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001316 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1317 }
1318
1319 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001320 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001321 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1322 }
1323
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001324 bool isVecListThreeDByteIndexed() const {
1325 if (!isSingleSpacedVectorIndexed()) return false;
1326 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1327 }
1328
1329 bool isVecListThreeDHWordIndexed() const {
1330 if (!isSingleSpacedVectorIndexed()) return false;
1331 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1332 }
1333
1334 bool isVecListThreeQWordIndexed() const {
1335 if (!isDoubleSpacedVectorIndexed()) return false;
1336 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1337 }
1338
1339 bool isVecListThreeQHWordIndexed() const {
1340 if (!isDoubleSpacedVectorIndexed()) return false;
1341 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1342 }
1343
1344 bool isVecListThreeDWordIndexed() const {
1345 if (!isSingleSpacedVectorIndexed()) return false;
1346 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1347 }
1348
Jim Grosbach14952a02012-01-24 18:37:25 +00001349 bool isVecListFourDByteIndexed() const {
1350 if (!isSingleSpacedVectorIndexed()) return false;
1351 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1352 }
1353
1354 bool isVecListFourDHWordIndexed() const {
1355 if (!isSingleSpacedVectorIndexed()) return false;
1356 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1357 }
1358
1359 bool isVecListFourQWordIndexed() const {
1360 if (!isDoubleSpacedVectorIndexed()) return false;
1361 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1362 }
1363
1364 bool isVecListFourQHWordIndexed() const {
1365 if (!isDoubleSpacedVectorIndexed()) return false;
1366 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1367 }
1368
1369 bool isVecListFourDWordIndexed() const {
1370 if (!isSingleSpacedVectorIndexed()) return false;
1371 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1372 }
1373
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001374 bool isVectorIndex8() const {
1375 if (Kind != k_VectorIndex) return false;
1376 return VectorIndex.Val < 8;
1377 }
1378 bool isVectorIndex16() const {
1379 if (Kind != k_VectorIndex) return false;
1380 return VectorIndex.Val < 4;
1381 }
1382 bool isVectorIndex32() const {
1383 if (Kind != k_VectorIndex) return false;
1384 return VectorIndex.Val < 2;
1385 }
1386
Jim Grosbach741cd732011-10-17 22:26:03 +00001387 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001388 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001389 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1390 // Must be a constant.
1391 if (!CE) return false;
1392 int64_t Value = CE->getValue();
1393 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1394 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001395 return Value >= 0 && Value < 256;
1396 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001397
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001398 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001399 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001400 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1401 // Must be a constant.
1402 if (!CE) return false;
1403 int64_t Value = CE->getValue();
1404 // i16 value in the range [0,255] or [0x0100, 0xff00]
1405 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1406 }
1407
Jim Grosbach8211c052011-10-18 00:22:00 +00001408 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001409 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1411 // Must be a constant.
1412 if (!CE) return false;
1413 int64_t Value = CE->getValue();
1414 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1415 return (Value >= 0 && Value < 256) ||
1416 (Value >= 0x0100 && Value <= 0xff00) ||
1417 (Value >= 0x010000 && Value <= 0xff0000) ||
1418 (Value >= 0x01000000 && Value <= 0xff000000);
1419 }
1420
1421 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001422 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 // Must be a constant.
1425 if (!CE) return false;
1426 int64_t Value = CE->getValue();
1427 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1428 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1429 return (Value >= 0 && Value < 256) ||
1430 (Value >= 0x0100 && Value <= 0xff00) ||
1431 (Value >= 0x010000 && Value <= 0xff0000) ||
1432 (Value >= 0x01000000 && Value <= 0xff000000) ||
1433 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1434 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1435 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001436 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001437 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001438 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1439 // Must be a constant.
1440 if (!CE) return false;
1441 int64_t Value = ~CE->getValue();
1442 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1443 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1444 return (Value >= 0 && Value < 256) ||
1445 (Value >= 0x0100 && Value <= 0xff00) ||
1446 (Value >= 0x010000 && Value <= 0xff0000) ||
1447 (Value >= 0x01000000 && Value <= 0xff000000) ||
1448 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1449 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1450 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001451
Jim Grosbache4454e02011-10-18 16:18:11 +00001452 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001453 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001454 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1455 // Must be a constant.
1456 if (!CE) return false;
1457 uint64_t Value = CE->getValue();
1458 // i64 value with each byte being either 0 or 0xff.
1459 for (unsigned i = 0; i < 8; ++i)
1460 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1461 return true;
1462 }
1463
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001464 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001465 // Add as immediates when possible. Null MCExpr = 0.
1466 if (Expr == 0)
1467 Inst.addOperand(MCOperand::CreateImm(0));
1468 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001469 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1470 else
1471 Inst.addOperand(MCOperand::CreateExpr(Expr));
1472 }
1473
Daniel Dunbard8042b72010-08-11 06:36:53 +00001474 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001475 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001476 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001477 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1478 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001479 }
1480
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001481 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1482 assert(N == 1 && "Invalid number of operands!");
1483 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1484 }
1485
Jim Grosbach48399582011-10-12 17:34:41 +00001486 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1487 assert(N == 1 && "Invalid number of operands!");
1488 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1489 }
1490
1491 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1492 assert(N == 1 && "Invalid number of operands!");
1493 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1494 }
1495
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001496 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1499 }
1500
1501 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1502 assert(N == 1 && "Invalid number of operands!");
1503 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1504 }
1505
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001506 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 Inst.addOperand(MCOperand::CreateReg(getReg()));
1509 }
1510
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001511 void addRegOperands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 Inst.addOperand(MCOperand::CreateReg(getReg()));
1514 }
1515
Jim Grosbachac798e12011-07-25 20:49:51 +00001516 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001517 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001518 assert(isRegShiftedReg() &&
1519 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001520 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1521 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001522 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001523 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001524 }
1525
Jim Grosbachac798e12011-07-25 20:49:51 +00001526 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001527 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001528 assert(isRegShiftedImm() &&
1529 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001530 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001531 // Shift of #32 is encoded as 0 where permitted
1532 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001533 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001534 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001535 }
1536
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001537 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001538 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001539 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1540 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001541 }
1542
Bill Wendling8d2aa032010-11-08 23:49:57 +00001543 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001544 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001545 const SmallVectorImpl<unsigned> &RegList = getRegList();
1546 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001547 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1548 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001549 }
1550
Bill Wendling9898ac92010-11-17 04:32:08 +00001551 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1552 addRegListOperands(Inst, N);
1553 }
1554
1555 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1556 addRegListOperands(Inst, N);
1557 }
1558
Jim Grosbach833b9d32011-07-27 20:15:40 +00001559 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1560 assert(N == 1 && "Invalid number of operands!");
1561 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1562 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1563 }
1564
Jim Grosbach864b6092011-07-28 21:34:26 +00001565 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 // Munge the lsb/width into a bitfield mask.
1568 unsigned lsb = Bitfield.LSB;
1569 unsigned width = Bitfield.Width;
1570 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1571 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1572 (32 - (lsb + width)));
1573 Inst.addOperand(MCOperand::CreateImm(Mask));
1574 }
1575
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001576 void addImmOperands(MCInst &Inst, unsigned N) const {
1577 assert(N == 1 && "Invalid number of operands!");
1578 addExpr(Inst, getImm());
1579 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001580
Jim Grosbachea231912011-12-22 22:19:05 +00001581 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1582 assert(N == 1 && "Invalid number of operands!");
1583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1584 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1585 }
1586
1587 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1588 assert(N == 1 && "Invalid number of operands!");
1589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1590 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1591 }
1592
Jim Grosbache7fbce72011-10-03 23:38:36 +00001593 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001595 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1596 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1597 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001598 }
1599
Jim Grosbach7db8d692011-09-08 22:07:06 +00001600 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1601 assert(N == 1 && "Invalid number of operands!");
1602 // FIXME: We really want to scale the value here, but the LDRD/STRD
1603 // instruction don't encode operands that way yet.
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1606 }
1607
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001608 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 // The immediate is scaled by four in the encoding and is stored
1611 // in the MCInst as such. Lop off the low two bits here.
1612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1614 }
1615
Jim Grosbach930f2f62012-04-05 20:57:13 +00001616 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 // The immediate is scaled by four in the encoding and is stored
1619 // in the MCInst as such. Lop off the low two bits here.
1620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1622 }
1623
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001624 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1625 assert(N == 1 && "Invalid number of operands!");
1626 // The immediate is scaled by four in the encoding and is stored
1627 // in the MCInst as such. Lop off the low two bits here.
1628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1629 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1630 }
1631
Jim Grosbach475c6db2011-07-25 23:09:14 +00001632 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 // The constant encodes as the immediate-1, and we store in the instruction
1635 // the bits as encoded, so subtract off one here.
1636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1637 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1638 }
1639
Jim Grosbach801e0a32011-07-22 23:16:18 +00001640 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 // The constant encodes as the immediate-1, and we store in the instruction
1643 // the bits as encoded, so subtract off one here.
1644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1645 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1646 }
1647
Jim Grosbach46dd4132011-08-17 21:51:27 +00001648 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 // The constant encodes as the immediate, except for 32, which encodes as
1651 // zero.
1652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1653 unsigned Imm = CE->getValue();
1654 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1655 }
1656
Jim Grosbach27c1e252011-07-21 17:23:04 +00001657 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1660 // the instruction as well.
1661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1662 int Val = CE->getValue();
1663 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1664 }
1665
Jim Grosbachb009a872011-10-28 22:36:30 +00001666 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The operand is actually a t2_so_imm, but we have its bitwise
1669 // negation in the assembly source, so twiddle it here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1672 }
1673
Jim Grosbach30506252011-12-08 00:31:07 +00001674 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The operand is actually a t2_so_imm, but we have its
1677 // negation in the assembly source, so twiddle it here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1680 }
1681
Jim Grosbach930f2f62012-04-05 20:57:13 +00001682 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The operand is actually an imm0_4095, but we have its
1685 // negation in the assembly source, so twiddle it here.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1688 }
1689
Mihai Popad36cbaa2013-07-03 09:21:44 +00001690 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1691 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1692 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1693 return;
1694 }
1695
1696 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1697 assert(SR && "Unknown value type!");
1698 Inst.addOperand(MCOperand::CreateExpr(SR));
1699 }
1700
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001701 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1702 assert(N == 1 && "Invalid number of operands!");
1703 // The operand is actually a so_imm, but we have its bitwise
1704 // negation in the assembly source, so twiddle it here.
1705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1706 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1707 }
1708
Jim Grosbach30506252011-12-08 00:31:07 +00001709 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 1 && "Invalid number of operands!");
1711 // The operand is actually a so_imm, but we have its
1712 // negation in the assembly source, so twiddle it here.
1713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1714 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1715 }
1716
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001717 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1718 assert(N == 1 && "Invalid number of operands!");
1719 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1720 }
1721
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001722 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 1 && "Invalid number of operands!");
1724 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1725 }
1726
Jim Grosbachd3595712011-08-03 23:50:40 +00001727 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1728 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001729 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001730 }
1731
Jim Grosbach94298a92012-01-18 22:46:46 +00001732 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1733 assert(N == 1 && "Invalid number of operands!");
1734 int32_t Imm = Memory.OffsetImm->getValue();
1735 // FIXME: Handle #-0
1736 if (Imm == INT32_MIN) Imm = 0;
1737 Inst.addOperand(MCOperand::CreateImm(Imm));
1738 }
1739
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001740 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1741 assert(N == 1 && "Invalid number of operands!");
1742 assert(isImm() && "Not an immediate!");
1743
1744 // If we have an immediate that's not a constant, treat it as a label
1745 // reference needing a fixup.
1746 if (!isa<MCConstantExpr>(getImm())) {
1747 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1748 return;
1749 }
1750
1751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1752 int Val = CE->getValue();
1753 Inst.addOperand(MCOperand::CreateImm(Val));
1754 }
1755
Jim Grosbacha95ec992011-10-11 17:29:55 +00001756 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1757 assert(N == 2 && "Invalid number of operands!");
1758 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1759 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1760 }
1761
Jim Grosbachd3595712011-08-03 23:50:40 +00001762 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1763 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001764 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1765 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001766 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1767 // Special case for #-0
1768 if (Val == INT32_MIN) Val = 0;
1769 if (Val < 0) Val = -Val;
1770 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1771 } else {
1772 // For register offset, we encode the shift type and negation flag
1773 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001774 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1775 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001776 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001777 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1778 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001779 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001780 }
1781
Jim Grosbachcd17c122011-08-04 23:01:30 +00001782 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 2 && "Invalid number of operands!");
1784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1785 assert(CE && "non-constant AM2OffsetImm operand!");
1786 int32_t Val = CE->getValue();
1787 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1788 // Special case for #-0
1789 if (Val == INT32_MIN) Val = 0;
1790 if (Val < 0) Val = -Val;
1791 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1792 Inst.addOperand(MCOperand::CreateReg(0));
1793 Inst.addOperand(MCOperand::CreateImm(Val));
1794 }
1795
Jim Grosbach5b96b802011-08-10 20:29:19 +00001796 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1797 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001798 // If we have an immediate that's not a constant, treat it as a label
1799 // reference needing a fixup. If it is a constant, it's something else
1800 // and we reject it.
1801 if (isImm()) {
1802 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1803 Inst.addOperand(MCOperand::CreateReg(0));
1804 Inst.addOperand(MCOperand::CreateImm(0));
1805 return;
1806 }
1807
Jim Grosbach871dff72011-10-11 15:59:20 +00001808 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1809 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001810 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1811 // Special case for #-0
1812 if (Val == INT32_MIN) Val = 0;
1813 if (Val < 0) Val = -Val;
1814 Val = ARM_AM::getAM3Opc(AddSub, Val);
1815 } else {
1816 // For register offset, we encode the shift type and negation flag
1817 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001818 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001819 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001820 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1821 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001822 Inst.addOperand(MCOperand::CreateImm(Val));
1823 }
1824
1825 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001827 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001828 int32_t Val =
1829 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1830 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1831 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001832 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001833 }
1834
1835 // Constant offset.
1836 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1837 int32_t Val = CE->getValue();
1838 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1839 // Special case for #-0
1840 if (Val == INT32_MIN) Val = 0;
1841 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001842 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001843 Inst.addOperand(MCOperand::CreateReg(0));
1844 Inst.addOperand(MCOperand::CreateImm(Val));
1845 }
1846
Jim Grosbachd3595712011-08-03 23:50:40 +00001847 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1848 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001849 // If we have an immediate that's not a constant, treat it as a label
1850 // reference needing a fixup. If it is a constant, it's something else
1851 // and we reject it.
1852 if (isImm()) {
1853 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1854 Inst.addOperand(MCOperand::CreateImm(0));
1855 return;
1856 }
1857
Jim Grosbachd3595712011-08-03 23:50:40 +00001858 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001859 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001860 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1861 // Special case for #-0
1862 if (Val == INT32_MIN) Val = 0;
1863 if (Val < 0) Val = -Val;
1864 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001865 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001866 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001867 }
1868
Jim Grosbach7db8d692011-09-08 22:07:06 +00001869 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1870 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001871 // If we have an immediate that's not a constant, treat it as a label
1872 // reference needing a fixup. If it is a constant, it's something else
1873 // and we reject it.
1874 if (isImm()) {
1875 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1876 Inst.addOperand(MCOperand::CreateImm(0));
1877 return;
1878 }
1879
Jim Grosbach871dff72011-10-11 15:59:20 +00001880 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1881 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001882 Inst.addOperand(MCOperand::CreateImm(Val));
1883 }
1884
Jim Grosbacha05627e2011-09-09 18:37:27 +00001885 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 2 && "Invalid number of operands!");
1887 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001888 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1889 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001890 Inst.addOperand(MCOperand::CreateImm(Val));
1891 }
1892
Jim Grosbachd3595712011-08-03 23:50:40 +00001893 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1894 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001895 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1896 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001897 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001898 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001899
Jim Grosbach2392c532011-09-07 23:39:14 +00001900 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1901 addMemImm8OffsetOperands(Inst, N);
1902 }
1903
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001904 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001905 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001906 }
1907
1908 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1909 assert(N == 2 && "Invalid number of operands!");
1910 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001911 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001912 addExpr(Inst, getImm());
1913 Inst.addOperand(MCOperand::CreateImm(0));
1914 return;
1915 }
1916
1917 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001918 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1919 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001920 Inst.addOperand(MCOperand::CreateImm(Val));
1921 }
1922
Jim Grosbachd3595712011-08-03 23:50:40 +00001923 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1924 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001925 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001926 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001927 addExpr(Inst, getImm());
1928 Inst.addOperand(MCOperand::CreateImm(0));
1929 return;
1930 }
1931
1932 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001933 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1934 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001935 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001936 }
Bill Wendling811c9362010-11-30 07:44:32 +00001937
Jim Grosbach05541f42011-09-19 22:21:13 +00001938 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001940 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1941 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001942 }
1943
1944 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001946 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1947 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001948 }
1949
Jim Grosbachd3595712011-08-03 23:50:40 +00001950 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1951 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001952 unsigned Val =
1953 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1954 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001955 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1956 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001957 Inst.addOperand(MCOperand::CreateImm(Val));
1958 }
1959
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001960 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1961 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001962 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1963 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1964 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001965 }
1966
Jim Grosbachd3595712011-08-03 23:50:40 +00001967 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001969 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1970 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001971 }
1972
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001973 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1974 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001975 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1976 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001977 Inst.addOperand(MCOperand::CreateImm(Val));
1978 }
1979
Jim Grosbach26d35872011-08-19 18:55:51 +00001980 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1981 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001982 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1983 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001984 Inst.addOperand(MCOperand::CreateImm(Val));
1985 }
1986
Jim Grosbacha32c7532011-08-19 18:49:59 +00001987 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1988 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001989 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1990 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001991 Inst.addOperand(MCOperand::CreateImm(Val));
1992 }
1993
Jim Grosbach23983d62011-08-19 18:13:48 +00001994 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1995 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001996 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1997 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001998 Inst.addOperand(MCOperand::CreateImm(Val));
1999 }
2000
Jim Grosbachd3595712011-08-03 23:50:40 +00002001 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2002 assert(N == 1 && "Invalid number of operands!");
2003 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2004 assert(CE && "non-constant post-idx-imm8 operand!");
2005 int Imm = CE->getValue();
2006 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002007 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002008 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2009 Inst.addOperand(MCOperand::CreateImm(Imm));
2010 }
2011
Jim Grosbach93981412011-10-11 21:55:36 +00002012 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2013 assert(N == 1 && "Invalid number of operands!");
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 assert(CE && "non-constant post-idx-imm8s4 operand!");
2016 int Imm = CE->getValue();
2017 bool isAdd = Imm >= 0;
2018 if (Imm == INT32_MIN) Imm = 0;
2019 // Immediate is scaled by 4.
2020 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2021 Inst.addOperand(MCOperand::CreateImm(Imm));
2022 }
2023
Jim Grosbachd3595712011-08-03 23:50:40 +00002024 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2025 assert(N == 2 && "Invalid number of operands!");
2026 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002027 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2028 }
2029
2030 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 2 && "Invalid number of operands!");
2032 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2033 // The sign, shift type, and shift amount are encoded in a single operand
2034 // using the AM2 encoding helpers.
2035 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2036 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2037 PostIdxReg.ShiftTy);
2038 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002039 }
2040
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002041 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2042 assert(N == 1 && "Invalid number of operands!");
2043 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2044 }
2045
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002046 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2049 }
2050
Jim Grosbach182b6a02011-11-29 23:51:09 +00002051 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002052 assert(N == 1 && "Invalid number of operands!");
2053 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2054 }
2055
Jim Grosbach04945c42011-12-02 00:35:16 +00002056 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2057 assert(N == 2 && "Invalid number of operands!");
2058 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2059 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2060 }
2061
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002062 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2063 assert(N == 1 && "Invalid number of operands!");
2064 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2065 }
2066
2067 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2068 assert(N == 1 && "Invalid number of operands!");
2069 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2070 }
2071
2072 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 1 && "Invalid number of operands!");
2074 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2075 }
2076
Jim Grosbach741cd732011-10-17 22:26:03 +00002077 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2078 assert(N == 1 && "Invalid number of operands!");
2079 // The immediate encodes the type of constant as well as the value.
2080 // Mask in that this is an i8 splat.
2081 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2082 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2083 }
2084
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002085 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2086 assert(N == 1 && "Invalid number of operands!");
2087 // The immediate encodes the type of constant as well as the value.
2088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2089 unsigned Value = CE->getValue();
2090 if (Value >= 256)
2091 Value = (Value >> 8) | 0xa00;
2092 else
2093 Value |= 0x800;
2094 Inst.addOperand(MCOperand::CreateImm(Value));
2095 }
2096
Jim Grosbach8211c052011-10-18 00:22:00 +00002097 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2098 assert(N == 1 && "Invalid number of operands!");
2099 // The immediate encodes the type of constant as well as the value.
2100 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2101 unsigned Value = CE->getValue();
2102 if (Value >= 256 && Value <= 0xff00)
2103 Value = (Value >> 8) | 0x200;
2104 else if (Value > 0xffff && Value <= 0xff0000)
2105 Value = (Value >> 16) | 0x400;
2106 else if (Value > 0xffffff)
2107 Value = (Value >> 24) | 0x600;
2108 Inst.addOperand(MCOperand::CreateImm(Value));
2109 }
2110
2111 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 // The immediate encodes the type of constant as well as the value.
2114 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2115 unsigned Value = CE->getValue();
2116 if (Value >= 256 && Value <= 0xffff)
2117 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2118 else if (Value > 0xffff && Value <= 0xffffff)
2119 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2120 else if (Value > 0xffffff)
2121 Value = (Value >> 24) | 0x600;
2122 Inst.addOperand(MCOperand::CreateImm(Value));
2123 }
2124
Jim Grosbach045b6c72011-12-19 23:51:07 +00002125 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2126 assert(N == 1 && "Invalid number of operands!");
2127 // The immediate encodes the type of constant as well as the value.
2128 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2129 unsigned Value = ~CE->getValue();
2130 if (Value >= 256 && Value <= 0xffff)
2131 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2132 else if (Value > 0xffff && Value <= 0xffffff)
2133 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2134 else if (Value > 0xffffff)
2135 Value = (Value >> 24) | 0x600;
2136 Inst.addOperand(MCOperand::CreateImm(Value));
2137 }
2138
Jim Grosbache4454e02011-10-18 16:18:11 +00002139 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2140 assert(N == 1 && "Invalid number of operands!");
2141 // The immediate encodes the type of constant as well as the value.
2142 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2143 uint64_t Value = CE->getValue();
2144 unsigned Imm = 0;
2145 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2146 Imm |= (Value & 1) << i;
2147 }
2148 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2149 }
2150
Jim Grosbach602aa902011-07-13 15:34:57 +00002151 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002152
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002153 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002154 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002155 Op->ITMask.Mask = Mask;
2156 Op->StartLoc = S;
2157 Op->EndLoc = S;
2158 return Op;
2159 }
2160
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002161 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002162 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002163 Op->CC.Val = CC;
2164 Op->StartLoc = S;
2165 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002166 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002167 }
2168
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002169 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002170 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002171 Op->Cop.Val = CopVal;
2172 Op->StartLoc = S;
2173 Op->EndLoc = S;
2174 return Op;
2175 }
2176
2177 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002178 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002179 Op->Cop.Val = CopVal;
2180 Op->StartLoc = S;
2181 Op->EndLoc = S;
2182 return Op;
2183 }
2184
Jim Grosbach48399582011-10-12 17:34:41 +00002185 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2186 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2187 Op->Cop.Val = Val;
2188 Op->StartLoc = S;
2189 Op->EndLoc = E;
2190 return Op;
2191 }
2192
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002193 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002194 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002195 Op->Reg.RegNum = RegNum;
2196 Op->StartLoc = S;
2197 Op->EndLoc = S;
2198 return Op;
2199 }
2200
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002201 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002202 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002203 Op->Tok.Data = Str.data();
2204 Op->Tok.Length = Str.size();
2205 Op->StartLoc = S;
2206 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002207 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002208 }
2209
Bill Wendling2063b842010-11-18 23:43:05 +00002210 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002211 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002212 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002213 Op->StartLoc = S;
2214 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002215 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002216 }
2217
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002218 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2219 unsigned SrcReg,
2220 unsigned ShiftReg,
2221 unsigned ShiftImm,
2222 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002223 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002224 Op->RegShiftedReg.ShiftTy = ShTy;
2225 Op->RegShiftedReg.SrcReg = SrcReg;
2226 Op->RegShiftedReg.ShiftReg = ShiftReg;
2227 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002228 Op->StartLoc = S;
2229 Op->EndLoc = E;
2230 return Op;
2231 }
2232
Owen Andersonb595ed02011-07-21 18:54:16 +00002233 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2234 unsigned SrcReg,
2235 unsigned ShiftImm,
2236 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002237 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002238 Op->RegShiftedImm.ShiftTy = ShTy;
2239 Op->RegShiftedImm.SrcReg = SrcReg;
2240 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002241 Op->StartLoc = S;
2242 Op->EndLoc = E;
2243 return Op;
2244 }
2245
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002246 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002247 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002248 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002249 Op->ShifterImm.isASR = isASR;
2250 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002251 Op->StartLoc = S;
2252 Op->EndLoc = E;
2253 return Op;
2254 }
2255
Jim Grosbach833b9d32011-07-27 20:15:40 +00002256 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002257 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002258 Op->RotImm.Imm = Imm;
2259 Op->StartLoc = S;
2260 Op->EndLoc = E;
2261 return Op;
2262 }
2263
Jim Grosbach864b6092011-07-28 21:34:26 +00002264 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2265 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002266 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002267 Op->Bitfield.LSB = LSB;
2268 Op->Bitfield.Width = Width;
2269 Op->StartLoc = S;
2270 Op->EndLoc = E;
2271 return Op;
2272 }
2273
Bill Wendling2cae3272010-11-09 22:44:22 +00002274 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002275 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002276 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002277 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002278 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002279
Chad Rosierfa705ee2013-07-01 20:49:23 +00002280 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002281 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002282 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002283 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002284 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002285
Chad Rosierfa705ee2013-07-01 20:49:23 +00002286 // Sort based on the register encoding values.
2287 array_pod_sort(Regs.begin(), Regs.end());
2288
Bill Wendling9898ac92010-11-17 04:32:08 +00002289 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002290 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002291 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002292 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002293 Op->StartLoc = StartLoc;
2294 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002295 return Op;
2296 }
2297
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002298 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002299 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002300 ARMOperand *Op = new ARMOperand(k_VectorList);
2301 Op->VectorList.RegNum = RegNum;
2302 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002303 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002304 Op->StartLoc = S;
2305 Op->EndLoc = E;
2306 return Op;
2307 }
2308
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002309 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002310 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002311 SMLoc S, SMLoc E) {
2312 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2313 Op->VectorList.RegNum = RegNum;
2314 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002315 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002316 Op->StartLoc = S;
2317 Op->EndLoc = E;
2318 return Op;
2319 }
2320
Jim Grosbach04945c42011-12-02 00:35:16 +00002321 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002322 unsigned Index,
2323 bool isDoubleSpaced,
2324 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002325 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2326 Op->VectorList.RegNum = RegNum;
2327 Op->VectorList.Count = Count;
2328 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002329 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002330 Op->StartLoc = S;
2331 Op->EndLoc = E;
2332 return Op;
2333 }
2334
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002335 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2336 MCContext &Ctx) {
2337 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2338 Op->VectorIndex.Val = Idx;
2339 Op->StartLoc = S;
2340 Op->EndLoc = E;
2341 return Op;
2342 }
2343
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002344 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002345 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002346 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002347 Op->StartLoc = S;
2348 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002349 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002350 }
2351
Jim Grosbachd3595712011-08-03 23:50:40 +00002352 static ARMOperand *CreateMem(unsigned BaseRegNum,
2353 const MCConstantExpr *OffsetImm,
2354 unsigned OffsetRegNum,
2355 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002356 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002357 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002358 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002359 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002360 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002361 Op->Memory.BaseRegNum = BaseRegNum;
2362 Op->Memory.OffsetImm = OffsetImm;
2363 Op->Memory.OffsetRegNum = OffsetRegNum;
2364 Op->Memory.ShiftType = ShiftType;
2365 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002366 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002367 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002368 Op->StartLoc = S;
2369 Op->EndLoc = E;
2370 return Op;
2371 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002372
Jim Grosbachc320c852011-08-05 21:28:30 +00002373 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2374 ARM_AM::ShiftOpc ShiftTy,
2375 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002376 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002377 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002378 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002379 Op->PostIdxReg.isAdd = isAdd;
2380 Op->PostIdxReg.ShiftTy = ShiftTy;
2381 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002382 Op->StartLoc = S;
2383 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002384 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002385 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002386
2387 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002388 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002389 Op->MBOpt.Val = Opt;
2390 Op->StartLoc = S;
2391 Op->EndLoc = S;
2392 return Op;
2393 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002394
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002395 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2396 SMLoc S) {
2397 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2398 Op->ISBOpt.Val = Opt;
2399 Op->StartLoc = S;
2400 Op->EndLoc = S;
2401 return Op;
2402 }
2403
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002404 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002405 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002406 Op->IFlags.Val = IFlags;
2407 Op->StartLoc = S;
2408 Op->EndLoc = S;
2409 return Op;
2410 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002411
2412 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002413 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002414 Op->MMask.Val = MMask;
2415 Op->StartLoc = S;
2416 Op->EndLoc = S;
2417 return Op;
2418 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002419};
2420
2421} // end anonymous namespace.
2422
Jim Grosbach602aa902011-07-13 15:34:57 +00002423void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002424 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002425 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002426 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002427 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002428 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002429 OS << "<ccout " << getReg() << ">";
2430 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002431 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002432 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002433 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2434 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2435 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002436 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2437 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2438 break;
2439 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002440 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002441 OS << "<coprocessor number: " << getCoproc() << ">";
2442 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002443 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002444 OS << "<coprocessor register: " << getCoproc() << ">";
2445 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002446 case k_CoprocOption:
2447 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2448 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002449 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002450 OS << "<mask: " << getMSRMask() << ">";
2451 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002452 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002453 getImm()->print(OS);
2454 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002455 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002456 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2457 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002458 case k_InstSyncBarrierOpt:
2459 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2460 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002461 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002462 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002463 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002464 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002465 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002466 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002467 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2468 << PostIdxReg.RegNum;
2469 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2470 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2471 << PostIdxReg.ShiftImm;
2472 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002473 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002474 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002475 OS << "<ARM_PROC::";
2476 unsigned IFlags = getProcIFlags();
2477 for (int i=2; i >= 0; --i)
2478 if (IFlags & (1 << i))
2479 OS << ARM_PROC::IFlagsToString(1 << i);
2480 OS << ">";
2481 break;
2482 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002483 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002484 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002485 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002486 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002487 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2488 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002489 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002490 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002491 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002492 << RegShiftedReg.SrcReg << " "
2493 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2494 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002496 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002497 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002498 << RegShiftedImm.SrcReg << " "
2499 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2500 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002502 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002503 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002505 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002506 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2507 << ", width: " << Bitfield.Width << ">";
2508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002509 case k_RegisterList:
2510 case k_DPRRegisterList:
2511 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002512 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002513
Bill Wendlingbed94652010-11-09 23:28:44 +00002514 const SmallVectorImpl<unsigned> &RegList = getRegList();
2515 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002516 I = RegList.begin(), E = RegList.end(); I != E; ) {
2517 OS << *I;
2518 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002519 }
2520
2521 OS << ">";
2522 break;
2523 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002524 case k_VectorList:
2525 OS << "<vector_list " << VectorList.Count << " * "
2526 << VectorList.RegNum << ">";
2527 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002528 case k_VectorListAllLanes:
2529 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2530 << VectorList.RegNum << ">";
2531 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002532 case k_VectorListIndexed:
2533 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2534 << VectorList.Count << " * " << VectorList.RegNum << ">";
2535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002536 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002537 OS << "'" << getToken() << "'";
2538 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002539 case k_VectorIndex:
2540 OS << "<vectorindex " << getVectorIndex() << ">";
2541 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002542 }
2543}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002544
2545/// @name Auto-generated Match Functions
2546/// {
2547
2548static unsigned MatchRegisterName(StringRef Name);
2549
2550/// }
2551
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002552bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2553 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002554 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002555 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002556 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002557
2558 return (RegNo == (unsigned)-1);
2559}
2560
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002561/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002562/// and if it is a register name the token is eaten and the register number is
2563/// returned. Otherwise return -1.
2564///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002565int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002566 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002567 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002568
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002569 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002570 unsigned RegNum = MatchRegisterName(lowerCase);
2571 if (!RegNum) {
2572 RegNum = StringSwitch<unsigned>(lowerCase)
2573 .Case("r13", ARM::SP)
2574 .Case("r14", ARM::LR)
2575 .Case("r15", ARM::PC)
2576 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002577 // Additional register name aliases for 'gas' compatibility.
2578 .Case("a1", ARM::R0)
2579 .Case("a2", ARM::R1)
2580 .Case("a3", ARM::R2)
2581 .Case("a4", ARM::R3)
2582 .Case("v1", ARM::R4)
2583 .Case("v2", ARM::R5)
2584 .Case("v3", ARM::R6)
2585 .Case("v4", ARM::R7)
2586 .Case("v5", ARM::R8)
2587 .Case("v6", ARM::R9)
2588 .Case("v7", ARM::R10)
2589 .Case("v8", ARM::R11)
2590 .Case("sb", ARM::R9)
2591 .Case("sl", ARM::R10)
2592 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002593 .Default(0);
2594 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002595 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002596 // Check for aliases registered via .req. Canonicalize to lower case.
2597 // That's more consistent since register names are case insensitive, and
2598 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2599 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002600 // If no match, return failure.
2601 if (Entry == RegisterReqs.end())
2602 return -1;
2603 Parser.Lex(); // Eat identifier token.
2604 return Entry->getValue();
2605 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002606
Chris Lattner44e5981c2010-10-30 04:09:10 +00002607 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002608
Chris Lattner44e5981c2010-10-30 04:09:10 +00002609 return RegNum;
2610}
Jim Grosbach99710a82010-11-01 16:44:21 +00002611
Jim Grosbachbb24c592011-07-13 18:49:30 +00002612// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2613// If a recoverable error occurs, return 1. If an irrecoverable error
2614// occurs, return -1. An irrecoverable error is one where tokens have been
2615// consumed in the process of trying to parse the shifter (i.e., when it is
2616// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002617int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002618 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2619 SMLoc S = Parser.getTok().getLoc();
2620 const AsmToken &Tok = Parser.getTok();
2621 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2622
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002623 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002624 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002625 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002626 .Case("lsl", ARM_AM::lsl)
2627 .Case("lsr", ARM_AM::lsr)
2628 .Case("asr", ARM_AM::asr)
2629 .Case("ror", ARM_AM::ror)
2630 .Case("rrx", ARM_AM::rrx)
2631 .Default(ARM_AM::no_shift);
2632
2633 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002634 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002635
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002636 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002637
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002638 // The source register for the shift has already been added to the
2639 // operand list, so we need to pop it off and combine it into the shifted
2640 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002641 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002642 if (!PrevOp->isReg())
2643 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2644 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002645
2646 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002647 int64_t Imm = 0;
2648 int ShiftReg = 0;
2649 if (ShiftTy == ARM_AM::rrx) {
2650 // RRX Doesn't have an explicit shift amount. The encoder expects
2651 // the shift register to be the same as the source register. Seems odd,
2652 // but OK.
2653 ShiftReg = SrcReg;
2654 } else {
2655 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002656 if (Parser.getTok().is(AsmToken::Hash) ||
2657 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002658 Parser.Lex(); // Eat hash.
2659 SMLoc ImmLoc = Parser.getTok().getLoc();
2660 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002661 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002662 Error(ImmLoc, "invalid immediate shift value");
2663 return -1;
2664 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002665 // The expression must be evaluatable as an immediate.
2666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002667 if (!CE) {
2668 Error(ImmLoc, "invalid immediate shift value");
2669 return -1;
2670 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002671 // Range check the immediate.
2672 // lsl, ror: 0 <= imm <= 31
2673 // lsr, asr: 0 <= imm <= 32
2674 Imm = CE->getValue();
2675 if (Imm < 0 ||
2676 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2677 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002678 Error(ImmLoc, "immediate shift value out of range");
2679 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002680 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002681 // shift by zero is a nop. Always send it through as lsl.
2682 // ('as' compatibility)
2683 if (Imm == 0)
2684 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002685 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002686 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002687 EndLoc = Parser.getTok().getEndLoc();
2688 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002689 if (ShiftReg == -1) {
2690 Error (L, "expected immediate or register in shift operand");
2691 return -1;
2692 }
2693 } else {
2694 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002695 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002696 return -1;
2697 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002698 }
2699
Owen Andersonb595ed02011-07-21 18:54:16 +00002700 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2701 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002702 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002703 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002704 else
2705 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002706 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002707
Jim Grosbachbb24c592011-07-13 18:49:30 +00002708 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002709}
2710
2711
Bill Wendling2063b842010-11-18 23:43:05 +00002712/// Try to parse a register name. The token must be an Identifier when called.
2713/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2714/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002715///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002716/// TODO this is likely to change to allow different register types and or to
2717/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002718bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002719tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002720 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002721 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002722 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002723 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002724
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002725 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2726 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002727
Chris Lattner44e5981c2010-10-30 04:09:10 +00002728 const AsmToken &ExclaimTok = Parser.getTok();
2729 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002730 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2731 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002732 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002733 return false;
2734 }
2735
2736 // Also check for an index operand. This is only legal for vector registers,
2737 // but that'll get caught OK in operand matching, so we don't need to
2738 // explicitly filter everything else out here.
2739 if (Parser.getTok().is(AsmToken::LBrac)) {
2740 SMLoc SIdx = Parser.getTok().getLoc();
2741 Parser.Lex(); // Eat left bracket token.
2742
2743 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002744 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002745 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002746 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002747 if (!MCE)
2748 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002749
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002750 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002751 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002752
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002753 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002754 Parser.Lex(); // Eat right bracket token.
2755
2756 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2757 SIdx, E,
2758 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002759 }
2760
Bill Wendling2063b842010-11-18 23:43:05 +00002761 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002762}
2763
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002764/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2765/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2766/// "c5", ...
2767static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002768 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2769 // but efficient.
2770 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002771 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002772 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002773 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002774 return -1;
2775 switch (Name[1]) {
2776 default: return -1;
2777 case '0': return 0;
2778 case '1': return 1;
2779 case '2': return 2;
2780 case '3': return 3;
2781 case '4': return 4;
2782 case '5': return 5;
2783 case '6': return 6;
2784 case '7': return 7;
2785 case '8': return 8;
2786 case '9': return 9;
2787 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002788 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002789 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002790 return -1;
2791 switch (Name[2]) {
2792 default: return -1;
2793 case '0': return 10;
2794 case '1': return 11;
2795 case '2': return 12;
2796 case '3': return 13;
2797 case '4': return 14;
2798 case '5': return 15;
2799 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002800 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002801}
2802
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002803/// parseITCondCode - Try to parse a condition code for an IT instruction.
2804ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2805parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2806 SMLoc S = Parser.getTok().getLoc();
2807 const AsmToken &Tok = Parser.getTok();
2808 if (!Tok.is(AsmToken::Identifier))
2809 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002810 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002811 .Case("eq", ARMCC::EQ)
2812 .Case("ne", ARMCC::NE)
2813 .Case("hs", ARMCC::HS)
2814 .Case("cs", ARMCC::HS)
2815 .Case("lo", ARMCC::LO)
2816 .Case("cc", ARMCC::LO)
2817 .Case("mi", ARMCC::MI)
2818 .Case("pl", ARMCC::PL)
2819 .Case("vs", ARMCC::VS)
2820 .Case("vc", ARMCC::VC)
2821 .Case("hi", ARMCC::HI)
2822 .Case("ls", ARMCC::LS)
2823 .Case("ge", ARMCC::GE)
2824 .Case("lt", ARMCC::LT)
2825 .Case("gt", ARMCC::GT)
2826 .Case("le", ARMCC::LE)
2827 .Case("al", ARMCC::AL)
2828 .Default(~0U);
2829 if (CC == ~0U)
2830 return MatchOperand_NoMatch;
2831 Parser.Lex(); // Eat the token.
2832
2833 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2834
2835 return MatchOperand_Success;
2836}
2837
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002838/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002839/// token must be an Identifier when called, and if it is a coprocessor
2840/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002841ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002842parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002843 SMLoc S = Parser.getTok().getLoc();
2844 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002845 if (Tok.isNot(AsmToken::Identifier))
2846 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002847
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002848 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002849 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002850 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002851
2852 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002853 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002854 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002855}
2856
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002857/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002858/// token must be an Identifier when called, and if it is a coprocessor
2859/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002860ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002861parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002862 SMLoc S = Parser.getTok().getLoc();
2863 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002864 if (Tok.isNot(AsmToken::Identifier))
2865 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002866
2867 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2868 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002869 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002870
2871 Parser.Lex(); // Eat identifier token.
2872 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002873 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002874}
2875
Jim Grosbach48399582011-10-12 17:34:41 +00002876/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2877/// coproc_option : '{' imm0_255 '}'
2878ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2879parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2880 SMLoc S = Parser.getTok().getLoc();
2881
2882 // If this isn't a '{', this isn't a coprocessor immediate operand.
2883 if (Parser.getTok().isNot(AsmToken::LCurly))
2884 return MatchOperand_NoMatch;
2885 Parser.Lex(); // Eat the '{'
2886
2887 const MCExpr *Expr;
2888 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002889 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002890 Error(Loc, "illegal expression");
2891 return MatchOperand_ParseFail;
2892 }
2893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2894 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2895 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2896 return MatchOperand_ParseFail;
2897 }
2898 int Val = CE->getValue();
2899
2900 // Check for and consume the closing '}'
2901 if (Parser.getTok().isNot(AsmToken::RCurly))
2902 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002903 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002904 Parser.Lex(); // Eat the '}'
2905
2906 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2907 return MatchOperand_Success;
2908}
2909
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002910// For register list parsing, we need to map from raw GPR register numbering
2911// to the enumeration values. The enumeration values aren't sorted by
2912// register number due to our using "sp", "lr" and "pc" as canonical names.
2913static unsigned getNextRegister(unsigned Reg) {
2914 // If this is a GPR, we need to do it manually, otherwise we can rely
2915 // on the sort ordering of the enumeration since the other reg-classes
2916 // are sane.
2917 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2918 return Reg + 1;
2919 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002920 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002921 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2922 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2923 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2924 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2925 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2926 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2927 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2928 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2929 }
2930}
2931
Jim Grosbach85a23432011-11-11 21:27:40 +00002932// Return the low-subreg of a given Q register.
2933static unsigned getDRegFromQReg(unsigned QReg) {
2934 switch (QReg) {
2935 default: llvm_unreachable("expected a Q register!");
2936 case ARM::Q0: return ARM::D0;
2937 case ARM::Q1: return ARM::D2;
2938 case ARM::Q2: return ARM::D4;
2939 case ARM::Q3: return ARM::D6;
2940 case ARM::Q4: return ARM::D8;
2941 case ARM::Q5: return ARM::D10;
2942 case ARM::Q6: return ARM::D12;
2943 case ARM::Q7: return ARM::D14;
2944 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002945 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002946 case ARM::Q10: return ARM::D20;
2947 case ARM::Q11: return ARM::D22;
2948 case ARM::Q12: return ARM::D24;
2949 case ARM::Q13: return ARM::D26;
2950 case ARM::Q14: return ARM::D28;
2951 case ARM::Q15: return ARM::D30;
2952 }
2953}
2954
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002955/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002956bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002957parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002958 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002959 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002960 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002961 Parser.Lex(); // Eat '{' token.
2962 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002963
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002964 // Check the first register in the list to see what register class
2965 // this is a list of.
2966 int Reg = tryParseRegister();
2967 if (Reg == -1)
2968 return Error(RegLoc, "register expected");
2969
Jim Grosbach85a23432011-11-11 21:27:40 +00002970 // The reglist instructions have at most 16 registers, so reserve
2971 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00002972 int EReg = 0;
2973 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00002974
2975 // Allow Q regs and just interpret them as the two D sub-registers.
2976 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2977 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002978 EReg = MRI->getEncodingValue(Reg);
2979 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00002980 ++Reg;
2981 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002982 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002983 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2984 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2985 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2986 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2987 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2988 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2989 else
2990 return Error(RegLoc, "invalid register in register list");
2991
Jim Grosbach85a23432011-11-11 21:27:40 +00002992 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00002993 EReg = MRI->getEncodingValue(Reg);
2994 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002995
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002996 // This starts immediately after the first register token in the list,
2997 // so we can see either a comma or a minus (range separator) as a legal
2998 // next token.
2999 while (Parser.getTok().is(AsmToken::Comma) ||
3000 Parser.getTok().is(AsmToken::Minus)) {
3001 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003002 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003003 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003004 int EndReg = tryParseRegister();
3005 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003006 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003007 // Allow Q regs and just interpret them as the two D sub-registers.
3008 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3009 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003010 // If the register is the same as the start reg, there's nothing
3011 // more to do.
3012 if (Reg == EndReg)
3013 continue;
3014 // The register must be in the same register class as the first.
3015 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003016 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003017 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003018 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003019 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003020
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003021 // Add all the registers in the range to the register list.
3022 while (Reg != EndReg) {
3023 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003024 EReg = MRI->getEncodingValue(Reg);
3025 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003026 }
3027 continue;
3028 }
3029 Parser.Lex(); // Eat the comma.
3030 RegLoc = Parser.getTok().getLoc();
3031 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003032 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003033 Reg = tryParseRegister();
3034 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003035 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003036 // Allow Q regs and just interpret them as the two D sub-registers.
3037 bool isQReg = false;
3038 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3039 Reg = getDRegFromQReg(Reg);
3040 isQReg = true;
3041 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003042 // The register must be in the same register class as the first.
3043 if (!RC->contains(Reg))
3044 return Error(RegLoc, "invalid register in register list");
3045 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003046 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003047 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3048 Warning(RegLoc, "register list not in ascending order");
3049 else
3050 return Error(RegLoc, "register list not in ascending order");
3051 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003052 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003053 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3054 ") in register list");
3055 continue;
3056 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003057 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003058 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3059 Reg != OldReg + 1)
3060 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003061 EReg = MRI->getEncodingValue(Reg);
3062 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3063 if (isQReg) {
3064 EReg = MRI->getEncodingValue(++Reg);
3065 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3066 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003067 }
3068
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003069 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003070 return Error(Parser.getTok().getLoc(), "'}' expected");
3071 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003072 Parser.Lex(); // Eat '}' token.
3073
Jim Grosbach18bf3632011-12-13 21:48:29 +00003074 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003075 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003076
3077 // The ARM system instruction variants for LDM/STM have a '^' token here.
3078 if (Parser.getTok().is(AsmToken::Caret)) {
3079 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3080 Parser.Lex(); // Eat '^' token.
3081 }
3082
Bill Wendling2063b842010-11-18 23:43:05 +00003083 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003084}
3085
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003086// Helper function to parse the lane index for vector lists.
3087ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003088parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003089 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003090 if (Parser.getTok().is(AsmToken::LBrac)) {
3091 Parser.Lex(); // Eat the '['.
3092 if (Parser.getTok().is(AsmToken::RBrac)) {
3093 // "Dn[]" is the 'all lanes' syntax.
3094 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003095 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003096 Parser.Lex(); // Eat the ']'.
3097 return MatchOperand_Success;
3098 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003099
3100 // There's an optional '#' token here. Normally there wouldn't be, but
3101 // inline assemble puts one in, and it's friendly to accept that.
3102 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003103 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003104
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003105 const MCExpr *LaneIndex;
3106 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003107 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003108 Error(Loc, "illegal expression");
3109 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003110 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003111 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3112 if (!CE) {
3113 Error(Loc, "lane index must be empty or an integer");
3114 return MatchOperand_ParseFail;
3115 }
3116 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3117 Error(Parser.getTok().getLoc(), "']' expected");
3118 return MatchOperand_ParseFail;
3119 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003120 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003121 Parser.Lex(); // Eat the ']'.
3122 int64_t Val = CE->getValue();
3123
3124 // FIXME: Make this range check context sensitive for .8, .16, .32.
3125 if (Val < 0 || Val > 7) {
3126 Error(Parser.getTok().getLoc(), "lane index out of range");
3127 return MatchOperand_ParseFail;
3128 }
3129 Index = Val;
3130 LaneKind = IndexedLane;
3131 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003132 }
3133 LaneKind = NoLanes;
3134 return MatchOperand_Success;
3135}
3136
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003137// parse a vector register list
3138ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3139parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003140 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003141 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003142 SMLoc S = Parser.getTok().getLoc();
3143 // As an extension (to match gas), support a plain D register or Q register
3144 // (without encosing curly braces) as a single or double entry list,
3145 // respectively.
3146 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003147 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003148 int Reg = tryParseRegister();
3149 if (Reg == -1)
3150 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003151 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003152 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003153 if (Res != MatchOperand_Success)
3154 return Res;
3155 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003157 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003158 break;
3159 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003160 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3161 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003162 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003163 case IndexedLane:
3164 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003165 LaneIndex,
3166 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003167 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003168 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003169 return MatchOperand_Success;
3170 }
3171 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3172 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003173 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003174 if (Res != MatchOperand_Success)
3175 return Res;
3176 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003177 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003178 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003179 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003180 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003181 break;
3182 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003183 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3184 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003185 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3186 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003187 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003188 case IndexedLane:
3189 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003190 LaneIndex,
3191 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003192 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003193 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003194 return MatchOperand_Success;
3195 }
3196 Error(S, "vector register expected");
3197 return MatchOperand_ParseFail;
3198 }
3199
3200 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003201 return MatchOperand_NoMatch;
3202
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003203 Parser.Lex(); // Eat '{' token.
3204 SMLoc RegLoc = Parser.getTok().getLoc();
3205
3206 int Reg = tryParseRegister();
3207 if (Reg == -1) {
3208 Error(RegLoc, "register expected");
3209 return MatchOperand_ParseFail;
3210 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003211 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003212 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003213 unsigned FirstReg = Reg;
3214 // The list is of D registers, but we also allow Q regs and just interpret
3215 // them as the two D sub-registers.
3216 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3217 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003218 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3219 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003220 ++Reg;
3221 ++Count;
3222 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003223
3224 SMLoc E;
3225 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003227
Jim Grosbache891fe82011-11-15 23:19:15 +00003228 while (Parser.getTok().is(AsmToken::Comma) ||
3229 Parser.getTok().is(AsmToken::Minus)) {
3230 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003231 if (!Spacing)
3232 Spacing = 1; // Register range implies a single spaced list.
3233 else if (Spacing == 2) {
3234 Error(Parser.getTok().getLoc(),
3235 "sequential registers in double spaced list");
3236 return MatchOperand_ParseFail;
3237 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003238 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003239 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003240 int EndReg = tryParseRegister();
3241 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003242 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003243 return MatchOperand_ParseFail;
3244 }
3245 // Allow Q regs and just interpret them as the two D sub-registers.
3246 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3247 EndReg = getDRegFromQReg(EndReg) + 1;
3248 // If the register is the same as the start reg, there's nothing
3249 // more to do.
3250 if (Reg == EndReg)
3251 continue;
3252 // The register must be in the same register class as the first.
3253 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003254 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003255 return MatchOperand_ParseFail;
3256 }
3257 // Ranges must go from low to high.
3258 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003259 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003260 return MatchOperand_ParseFail;
3261 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003262 // Parse the lane specifier if present.
3263 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003264 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003265 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3266 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003267 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003268 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003269 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003270 return MatchOperand_ParseFail;
3271 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003272
3273 // Add all the registers in the range to the register list.
3274 Count += EndReg - Reg;
3275 Reg = EndReg;
3276 continue;
3277 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003278 Parser.Lex(); // Eat the comma.
3279 RegLoc = Parser.getTok().getLoc();
3280 int OldReg = Reg;
3281 Reg = tryParseRegister();
3282 if (Reg == -1) {
3283 Error(RegLoc, "register expected");
3284 return MatchOperand_ParseFail;
3285 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003286 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003287 // It's OK to use the enumeration values directly here rather, as the
3288 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003289 //
3290 // The list is of D registers, but we also allow Q regs and just interpret
3291 // them as the two D sub-registers.
3292 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003293 if (!Spacing)
3294 Spacing = 1; // Register range implies a single spaced list.
3295 else if (Spacing == 2) {
3296 Error(RegLoc,
3297 "invalid register in double-spaced list (must be 'D' register')");
3298 return MatchOperand_ParseFail;
3299 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003300 Reg = getDRegFromQReg(Reg);
3301 if (Reg != OldReg + 1) {
3302 Error(RegLoc, "non-contiguous register range");
3303 return MatchOperand_ParseFail;
3304 }
3305 ++Reg;
3306 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003307 // Parse the lane specifier if present.
3308 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003309 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003310 SMLoc LaneLoc = Parser.getTok().getLoc();
3311 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3312 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003313 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003314 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003315 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003316 return MatchOperand_ParseFail;
3317 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003318 continue;
3319 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003320 // Normal D register.
3321 // Figure out the register spacing (single or double) of the list if
3322 // we don't know it already.
3323 if (!Spacing)
3324 Spacing = 1 + (Reg == OldReg + 2);
3325
3326 // Just check that it's contiguous and keep going.
3327 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003328 Error(RegLoc, "non-contiguous register range");
3329 return MatchOperand_ParseFail;
3330 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003331 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003332 // Parse the lane specifier if present.
3333 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003334 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003335 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003336 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003337 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003338 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003339 Error(EndLoc, "mismatched lane index in register list");
3340 return MatchOperand_ParseFail;
3341 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003342 }
3343
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003344 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003345 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003346 return MatchOperand_ParseFail;
3347 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003348 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003349 Parser.Lex(); // Eat '}' token.
3350
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003351 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003352 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003353 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003354 // composite register classes.
3355 if (Count == 2) {
3356 const MCRegisterClass *RC = (Spacing == 1) ?
3357 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3358 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3359 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3360 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003361
Jim Grosbach2f50e922011-12-15 21:44:33 +00003362 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3363 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003364 break;
3365 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003366 // Two-register operands have been converted to the
3367 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003368 if (Count == 2) {
3369 const MCRegisterClass *RC = (Spacing == 1) ?
3370 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3371 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003372 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3373 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003374 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003375 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 S, E));
3377 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003378 case IndexedLane:
3379 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003380 LaneIndex,
3381 (Spacing == 2),
3382 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003383 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003384 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003385 return MatchOperand_Success;
3386}
3387
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003388/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003389ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003390parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003391 SMLoc S = Parser.getTok().getLoc();
3392 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003393 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003394
Jiangning Liu288e1af2012-08-02 08:21:27 +00003395 if (Tok.is(AsmToken::Identifier)) {
3396 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003397
Jiangning Liu288e1af2012-08-02 08:21:27 +00003398 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3399 .Case("sy", ARM_MB::SY)
3400 .Case("st", ARM_MB::ST)
3401 .Case("sh", ARM_MB::ISH)
3402 .Case("ish", ARM_MB::ISH)
3403 .Case("shst", ARM_MB::ISHST)
3404 .Case("ishst", ARM_MB::ISHST)
3405 .Case("nsh", ARM_MB::NSH)
3406 .Case("un", ARM_MB::NSH)
3407 .Case("nshst", ARM_MB::NSHST)
3408 .Case("unst", ARM_MB::NSHST)
3409 .Case("osh", ARM_MB::OSH)
3410 .Case("oshst", ARM_MB::OSHST)
3411 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003412
Jiangning Liu288e1af2012-08-02 08:21:27 +00003413 if (Opt == ~0U)
3414 return MatchOperand_NoMatch;
3415
3416 Parser.Lex(); // Eat identifier token.
3417 } else if (Tok.is(AsmToken::Hash) ||
3418 Tok.is(AsmToken::Dollar) ||
3419 Tok.is(AsmToken::Integer)) {
3420 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003421 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003422 SMLoc Loc = Parser.getTok().getLoc();
3423
3424 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003425 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003426 Error(Loc, "illegal expression");
3427 return MatchOperand_ParseFail;
3428 }
3429
3430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3431 if (!CE) {
3432 Error(Loc, "constant expression expected");
3433 return MatchOperand_ParseFail;
3434 }
3435
3436 int Val = CE->getValue();
3437 if (Val & ~0xf) {
3438 Error(Loc, "immediate value out of range");
3439 return MatchOperand_ParseFail;
3440 }
3441
3442 Opt = ARM_MB::RESERVED_0 + Val;
3443 } else
3444 return MatchOperand_ParseFail;
3445
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003446 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003447 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003448}
3449
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003450/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3451ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3452parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3453 SMLoc S = Parser.getTok().getLoc();
3454 const AsmToken &Tok = Parser.getTok();
3455 unsigned Opt;
3456
3457 if (Tok.is(AsmToken::Identifier)) {
3458 StringRef OptStr = Tok.getString();
3459
3460 if (OptStr.lower() == "sy")
3461 Opt = ARM_ISB::SY;
3462 else
3463 return MatchOperand_NoMatch;
3464
3465 Parser.Lex(); // Eat identifier token.
3466 } else if (Tok.is(AsmToken::Hash) ||
3467 Tok.is(AsmToken::Dollar) ||
3468 Tok.is(AsmToken::Integer)) {
3469 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003470 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003471 SMLoc Loc = Parser.getTok().getLoc();
3472
3473 const MCExpr *ISBarrierID;
3474 if (getParser().parseExpression(ISBarrierID)) {
3475 Error(Loc, "illegal expression");
3476 return MatchOperand_ParseFail;
3477 }
3478
3479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3480 if (!CE) {
3481 Error(Loc, "constant expression expected");
3482 return MatchOperand_ParseFail;
3483 }
3484
3485 int Val = CE->getValue();
3486 if (Val & ~0xf) {
3487 Error(Loc, "immediate value out of range");
3488 return MatchOperand_ParseFail;
3489 }
3490
3491 Opt = ARM_ISB::RESERVED_0 + Val;
3492 } else
3493 return MatchOperand_ParseFail;
3494
3495 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3496 (ARM_ISB::InstSyncBOpt)Opt, S));
3497 return MatchOperand_Success;
3498}
3499
3500
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003501/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003502ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003503parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003504 SMLoc S = Parser.getTok().getLoc();
3505 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003506 if (!Tok.is(AsmToken::Identifier))
3507 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003508 StringRef IFlagsStr = Tok.getString();
3509
Owen Anderson10c5b122011-10-05 17:16:40 +00003510 // An iflags string of "none" is interpreted to mean that none of the AIF
3511 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003512 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003513 if (IFlagsStr != "none") {
3514 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3515 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3516 .Case("a", ARM_PROC::A)
3517 .Case("i", ARM_PROC::I)
3518 .Case("f", ARM_PROC::F)
3519 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003520
Owen Anderson10c5b122011-10-05 17:16:40 +00003521 // If some specific iflag is already set, it means that some letter is
3522 // present more than once, this is not acceptable.
3523 if (Flag == ~0U || (IFlags & Flag))
3524 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003525
Owen Anderson10c5b122011-10-05 17:16:40 +00003526 IFlags |= Flag;
3527 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003528 }
3529
3530 Parser.Lex(); // Eat identifier token.
3531 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3532 return MatchOperand_Success;
3533}
3534
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003535/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003536ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003537parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003538 SMLoc S = Parser.getTok().getLoc();
3539 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003540 if (!Tok.is(AsmToken::Identifier))
3541 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003542 StringRef Mask = Tok.getString();
3543
James Molloy21efa7d2011-09-28 14:21:38 +00003544 if (isMClass()) {
3545 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003546 std::string Name = Mask.lower();
3547 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003548 // Note: in the documentation:
3549 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3550 // for MSR APSR_nzcvq.
3551 // but we do make it an alias here. This is so to get the "mask encoding"
3552 // bits correct on MSR APSR writes.
3553 //
3554 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3555 // should really only be allowed when writing a special register. Note
3556 // they get dropped in the MRS instruction reading a special register as
3557 // the SYSm field is only 8 bits.
3558 //
3559 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3560 // includes the DSP extension but that is not checked.
3561 .Case("apsr", 0x800)
3562 .Case("apsr_nzcvq", 0x800)
3563 .Case("apsr_g", 0x400)
3564 .Case("apsr_nzcvqg", 0xc00)
3565 .Case("iapsr", 0x801)
3566 .Case("iapsr_nzcvq", 0x801)
3567 .Case("iapsr_g", 0x401)
3568 .Case("iapsr_nzcvqg", 0xc01)
3569 .Case("eapsr", 0x802)
3570 .Case("eapsr_nzcvq", 0x802)
3571 .Case("eapsr_g", 0x402)
3572 .Case("eapsr_nzcvqg", 0xc02)
3573 .Case("xpsr", 0x803)
3574 .Case("xpsr_nzcvq", 0x803)
3575 .Case("xpsr_g", 0x403)
3576 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003577 .Case("ipsr", 0x805)
3578 .Case("epsr", 0x806)
3579 .Case("iepsr", 0x807)
3580 .Case("msp", 0x808)
3581 .Case("psp", 0x809)
3582 .Case("primask", 0x810)
3583 .Case("basepri", 0x811)
3584 .Case("basepri_max", 0x812)
3585 .Case("faultmask", 0x813)
3586 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003587 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003588
James Molloy21efa7d2011-09-28 14:21:38 +00003589 if (FlagsVal == ~0U)
3590 return MatchOperand_NoMatch;
3591
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003592 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003593 // basepri, basepri_max and faultmask only valid for V7m.
3594 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003595
James Molloy21efa7d2011-09-28 14:21:38 +00003596 Parser.Lex(); // Eat identifier token.
3597 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3598 return MatchOperand_Success;
3599 }
3600
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003601 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3602 size_t Start = 0, Next = Mask.find('_');
3603 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003604 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003605 if (Next != StringRef::npos)
3606 Flags = Mask.slice(Next+1, Mask.size());
3607
3608 // FlagsVal contains the complete mask:
3609 // 3-0: Mask
3610 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3611 unsigned FlagsVal = 0;
3612
3613 if (SpecReg == "apsr") {
3614 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003615 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003616 .Case("g", 0x4) // same as CPSR_s
3617 .Case("nzcvqg", 0xc) // same as CPSR_fs
3618 .Default(~0U);
3619
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003620 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003621 if (!Flags.empty())
3622 return MatchOperand_NoMatch;
3623 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003624 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003625 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003626 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003627 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3628 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003629 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003630 for (int i = 0, e = Flags.size(); i != e; ++i) {
3631 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3632 .Case("c", 1)
3633 .Case("x", 2)
3634 .Case("s", 4)
3635 .Case("f", 8)
3636 .Default(~0U);
3637
3638 // If some specific flag is already set, it means that some letter is
3639 // present more than once, this is not acceptable.
3640 if (FlagsVal == ~0U || (FlagsVal & Flag))
3641 return MatchOperand_NoMatch;
3642 FlagsVal |= Flag;
3643 }
3644 } else // No match for special register.
3645 return MatchOperand_NoMatch;
3646
Owen Anderson03a173e2011-10-21 18:43:28 +00003647 // Special register without flags is NOT equivalent to "fc" flags.
3648 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3649 // two lines would enable gas compatibility at the expense of breaking
3650 // round-tripping.
3651 //
3652 // if (!FlagsVal)
3653 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003654
3655 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3656 if (SpecReg == "spsr")
3657 FlagsVal |= 16;
3658
3659 Parser.Lex(); // Eat identifier token.
3660 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3661 return MatchOperand_Success;
3662}
3663
Jim Grosbach27c1e252011-07-21 17:23:04 +00003664ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3665parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3666 int Low, int High) {
3667 const AsmToken &Tok = Parser.getTok();
3668 if (Tok.isNot(AsmToken::Identifier)) {
3669 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3670 return MatchOperand_ParseFail;
3671 }
3672 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003673 std::string LowerOp = Op.lower();
3674 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003675 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3676 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3677 return MatchOperand_ParseFail;
3678 }
3679 Parser.Lex(); // Eat shift type token.
3680
3681 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003682 if (Parser.getTok().isNot(AsmToken::Hash) &&
3683 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003684 Error(Parser.getTok().getLoc(), "'#' expected");
3685 return MatchOperand_ParseFail;
3686 }
3687 Parser.Lex(); // Eat hash token.
3688
3689 const MCExpr *ShiftAmount;
3690 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003691 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003692 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003693 Error(Loc, "illegal expression");
3694 return MatchOperand_ParseFail;
3695 }
3696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3697 if (!CE) {
3698 Error(Loc, "constant expression expected");
3699 return MatchOperand_ParseFail;
3700 }
3701 int Val = CE->getValue();
3702 if (Val < Low || Val > High) {
3703 Error(Loc, "immediate value out of range");
3704 return MatchOperand_ParseFail;
3705 }
3706
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003707 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003708
3709 return MatchOperand_Success;
3710}
3711
Jim Grosbach0a547702011-07-22 17:44:50 +00003712ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3713parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3714 const AsmToken &Tok = Parser.getTok();
3715 SMLoc S = Tok.getLoc();
3716 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003717 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003718 return MatchOperand_ParseFail;
3719 }
Tim Northover4d141442013-05-31 15:58:45 +00003720 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003721 .Case("be", 1)
3722 .Case("le", 0)
3723 .Default(-1);
3724 Parser.Lex(); // Eat the token.
3725
3726 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003727 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003728 return MatchOperand_ParseFail;
3729 }
3730 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3731 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003732 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003733 return MatchOperand_Success;
3734}
3735
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003736/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3737/// instructions. Legal values are:
3738/// lsl #n 'n' in [0,31]
3739/// asr #n 'n' in [1,32]
3740/// n == 32 encoded as n == 0.
3741ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3742parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3743 const AsmToken &Tok = Parser.getTok();
3744 SMLoc S = Tok.getLoc();
3745 if (Tok.isNot(AsmToken::Identifier)) {
3746 Error(S, "shift operator 'asr' or 'lsl' expected");
3747 return MatchOperand_ParseFail;
3748 }
3749 StringRef ShiftName = Tok.getString();
3750 bool isASR;
3751 if (ShiftName == "lsl" || ShiftName == "LSL")
3752 isASR = false;
3753 else if (ShiftName == "asr" || ShiftName == "ASR")
3754 isASR = true;
3755 else {
3756 Error(S, "shift operator 'asr' or 'lsl' expected");
3757 return MatchOperand_ParseFail;
3758 }
3759 Parser.Lex(); // Eat the operator.
3760
3761 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003762 if (Parser.getTok().isNot(AsmToken::Hash) &&
3763 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003764 Error(Parser.getTok().getLoc(), "'#' expected");
3765 return MatchOperand_ParseFail;
3766 }
3767 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003768 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003769
3770 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003771 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003772 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003773 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003774 return MatchOperand_ParseFail;
3775 }
3776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3777 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003778 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003779 return MatchOperand_ParseFail;
3780 }
3781
3782 int64_t Val = CE->getValue();
3783 if (isASR) {
3784 // Shift amount must be in [1,32]
3785 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003786 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003787 return MatchOperand_ParseFail;
3788 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003789 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3790 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003791 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003792 return MatchOperand_ParseFail;
3793 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003794 if (Val == 32) Val = 0;
3795 } else {
3796 // Shift amount must be in [1,32]
3797 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003798 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003799 return MatchOperand_ParseFail;
3800 }
3801 }
3802
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003803 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003804
3805 return MatchOperand_Success;
3806}
3807
Jim Grosbach833b9d32011-07-27 20:15:40 +00003808/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3809/// of instructions. Legal values are:
3810/// ror #n 'n' in {0, 8, 16, 24}
3811ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3812parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3813 const AsmToken &Tok = Parser.getTok();
3814 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003815 if (Tok.isNot(AsmToken::Identifier))
3816 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003817 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003818 if (ShiftName != "ror" && ShiftName != "ROR")
3819 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003820 Parser.Lex(); // Eat the operator.
3821
3822 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003823 if (Parser.getTok().isNot(AsmToken::Hash) &&
3824 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003825 Error(Parser.getTok().getLoc(), "'#' expected");
3826 return MatchOperand_ParseFail;
3827 }
3828 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003829 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003830
3831 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003832 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003833 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003834 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003835 return MatchOperand_ParseFail;
3836 }
3837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3838 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003839 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003840 return MatchOperand_ParseFail;
3841 }
3842
3843 int64_t Val = CE->getValue();
3844 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3845 // normally, zero is represented in asm by omitting the rotate operand
3846 // entirely.
3847 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003848 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003849 return MatchOperand_ParseFail;
3850 }
3851
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003852 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003853
3854 return MatchOperand_Success;
3855}
3856
Jim Grosbach864b6092011-07-28 21:34:26 +00003857ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3858parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3859 SMLoc S = Parser.getTok().getLoc();
3860 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003861 if (Parser.getTok().isNot(AsmToken::Hash) &&
3862 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003863 Error(Parser.getTok().getLoc(), "'#' expected");
3864 return MatchOperand_ParseFail;
3865 }
3866 Parser.Lex(); // Eat hash token.
3867
3868 const MCExpr *LSBExpr;
3869 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003870 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003871 Error(E, "malformed immediate expression");
3872 return MatchOperand_ParseFail;
3873 }
3874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3875 if (!CE) {
3876 Error(E, "'lsb' operand must be an immediate");
3877 return MatchOperand_ParseFail;
3878 }
3879
3880 int64_t LSB = CE->getValue();
3881 // The LSB must be in the range [0,31]
3882 if (LSB < 0 || LSB > 31) {
3883 Error(E, "'lsb' operand must be in the range [0,31]");
3884 return MatchOperand_ParseFail;
3885 }
3886 E = Parser.getTok().getLoc();
3887
3888 // Expect another immediate operand.
3889 if (Parser.getTok().isNot(AsmToken::Comma)) {
3890 Error(Parser.getTok().getLoc(), "too few operands");
3891 return MatchOperand_ParseFail;
3892 }
3893 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003894 if (Parser.getTok().isNot(AsmToken::Hash) &&
3895 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003896 Error(Parser.getTok().getLoc(), "'#' expected");
3897 return MatchOperand_ParseFail;
3898 }
3899 Parser.Lex(); // Eat hash token.
3900
3901 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003902 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003903 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003904 Error(E, "malformed immediate expression");
3905 return MatchOperand_ParseFail;
3906 }
3907 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3908 if (!CE) {
3909 Error(E, "'width' operand must be an immediate");
3910 return MatchOperand_ParseFail;
3911 }
3912
3913 int64_t Width = CE->getValue();
3914 // The LSB must be in the range [1,32-lsb]
3915 if (Width < 1 || Width > 32 - LSB) {
3916 Error(E, "'width' operand must be in the range [1,32-lsb]");
3917 return MatchOperand_ParseFail;
3918 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003919
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003920 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003921
3922 return MatchOperand_Success;
3923}
3924
Jim Grosbachd3595712011-08-03 23:50:40 +00003925ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3926parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3927 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003928 // postidx_reg := '+' register {, shift}
3929 // | '-' register {, shift}
3930 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003931
3932 // This method must return MatchOperand_NoMatch without consuming any tokens
3933 // in the case where there is no match, as other alternatives take other
3934 // parse methods.
3935 AsmToken Tok = Parser.getTok();
3936 SMLoc S = Tok.getLoc();
3937 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003938 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003939 if (Tok.is(AsmToken::Plus)) {
3940 Parser.Lex(); // Eat the '+' token.
3941 haveEaten = true;
3942 } else if (Tok.is(AsmToken::Minus)) {
3943 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003944 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003945 haveEaten = true;
3946 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003947
3948 SMLoc E = Parser.getTok().getEndLoc();
3949 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003950 if (Reg == -1) {
3951 if (!haveEaten)
3952 return MatchOperand_NoMatch;
3953 Error(Parser.getTok().getLoc(), "register expected");
3954 return MatchOperand_ParseFail;
3955 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003956
Jim Grosbachc320c852011-08-05 21:28:30 +00003957 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3958 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003959 if (Parser.getTok().is(AsmToken::Comma)) {
3960 Parser.Lex(); // Eat the ','.
3961 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3962 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003963
3964 // FIXME: Only approximates end...may include intervening whitespace.
3965 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003966 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003967
3968 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3969 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003970
3971 return MatchOperand_Success;
3972}
3973
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003974ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3975parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3976 // Check for a post-index addressing register operand. Specifically:
3977 // am3offset := '+' register
3978 // | '-' register
3979 // | register
3980 // | # imm
3981 // | # + imm
3982 // | # - imm
3983
3984 // This method must return MatchOperand_NoMatch without consuming any tokens
3985 // in the case where there is no match, as other alternatives take other
3986 // parse methods.
3987 AsmToken Tok = Parser.getTok();
3988 SMLoc S = Tok.getLoc();
3989
3990 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003991 if (Parser.getTok().is(AsmToken::Hash) ||
3992 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003993 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003994 // Explicitly look for a '-', as we need to encode negative zero
3995 // differently.
3996 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3997 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003998 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003999 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004000 return MatchOperand_ParseFail;
4001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4002 if (!CE) {
4003 Error(S, "constant expression expected");
4004 return MatchOperand_ParseFail;
4005 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004006 // Negative zero is encoded as the flag value INT32_MIN.
4007 int32_t Val = CE->getValue();
4008 if (isNegative && Val == 0)
4009 Val = INT32_MIN;
4010
4011 Operands.push_back(
4012 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4013
4014 return MatchOperand_Success;
4015 }
4016
4017
4018 bool haveEaten = false;
4019 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004020 if (Tok.is(AsmToken::Plus)) {
4021 Parser.Lex(); // Eat the '+' token.
4022 haveEaten = true;
4023 } else if (Tok.is(AsmToken::Minus)) {
4024 Parser.Lex(); // Eat the '-' token.
4025 isAdd = false;
4026 haveEaten = true;
4027 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004028
4029 Tok = Parser.getTok();
4030 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004031 if (Reg == -1) {
4032 if (!haveEaten)
4033 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004034 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004035 return MatchOperand_ParseFail;
4036 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004037
4038 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004039 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004040
4041 return MatchOperand_Success;
4042}
4043
Tim Northovereb5e4d52013-07-22 09:06:12 +00004044/// Convert parsed operands to MCInst. Needed here because this instruction
4045/// only has two register operands, but multiplication is commutative so
4046/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004047void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004048cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004049 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004050 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4051 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004052 // If we have a three-operand form, make sure to set Rn to be the operand
4053 // that isn't the same as Rd.
4054 unsigned RegOp = 4;
4055 if (Operands.size() == 6 &&
4056 ((ARMOperand*)Operands[4])->getReg() ==
4057 ((ARMOperand*)Operands[3])->getReg())
4058 RegOp = 5;
4059 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4060 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004061 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004062}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004063
Bill Wendlinge18980a2010-11-06 22:36:58 +00004064/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004065/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004066bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004067parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004068 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004069 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004070 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004071 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004072 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004073
Sean Callanan936b0d32010-01-19 21:44:56 +00004074 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004075 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004076 if (BaseRegNum == -1)
4077 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004078
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004079 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004080 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004081 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4082 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004083 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004084
Jim Grosbachd3595712011-08-03 23:50:40 +00004085 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004086 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004087 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004088
Jim Grosbachd3595712011-08-03 23:50:40 +00004089 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004090 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004091
Jim Grosbach40700e02011-09-19 18:42:21 +00004092 // If there's a pre-indexing writeback marker, '!', just add it as a token
4093 // operand. It's rather odd, but syntactically valid.
4094 if (Parser.getTok().is(AsmToken::Exclaim)) {
4095 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4096 Parser.Lex(); // Eat the '!'.
4097 }
4098
Jim Grosbachd3595712011-08-03 23:50:40 +00004099 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004100 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004101
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004102 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4103 "Lost colon or comma in memory operand?!");
4104 if (Tok.is(AsmToken::Comma)) {
4105 Parser.Lex(); // Eat the comma.
4106 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004107
Jim Grosbacha95ec992011-10-11 17:29:55 +00004108 // If we have a ':', it's an alignment specifier.
4109 if (Parser.getTok().is(AsmToken::Colon)) {
4110 Parser.Lex(); // Eat the ':'.
4111 E = Parser.getTok().getLoc();
4112
4113 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004114 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004115 return true;
4116
4117 // The expression has to be a constant. Memory references with relocations
4118 // don't come through here, as they use the <label> forms of the relevant
4119 // instructions.
4120 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4121 if (!CE)
4122 return Error (E, "constant expression expected");
4123
4124 unsigned Align = 0;
4125 switch (CE->getValue()) {
4126 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004127 return Error(E,
4128 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4129 case 16: Align = 2; break;
4130 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004131 case 64: Align = 8; break;
4132 case 128: Align = 16; break;
4133 case 256: Align = 32; break;
4134 }
4135
4136 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004137 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004138 return Error(Parser.getTok().getLoc(), "']' expected");
4139 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004140 Parser.Lex(); // Eat right bracket token.
4141
4142 // Don't worry about range checking the value here. That's handled by
4143 // the is*() predicates.
4144 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4145 ARM_AM::no_shift, 0, Align,
4146 false, S, E));
4147
4148 // If there's a pre-indexing writeback marker, '!', just add it as a token
4149 // operand.
4150 if (Parser.getTok().is(AsmToken::Exclaim)) {
4151 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4152 Parser.Lex(); // Eat the '!'.
4153 }
4154
4155 return false;
4156 }
4157
4158 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004159 // offset. Be friendly and also accept a plain integer (without a leading
4160 // hash) for gas compatibility.
4161 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004162 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004163 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004164 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004165 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004166 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004167
Owen Anderson967674d2011-08-29 19:36:44 +00004168 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004169 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004170 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004171 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004172
4173 // The expression has to be a constant. Memory references with relocations
4174 // don't come through here, as they use the <label> forms of the relevant
4175 // instructions.
4176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4177 if (!CE)
4178 return Error (E, "constant expression expected");
4179
Owen Anderson967674d2011-08-29 19:36:44 +00004180 // If the constant was #-0, represent it as INT32_MIN.
4181 int32_t Val = CE->getValue();
4182 if (isNegative && Val == 0)
4183 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4184
Jim Grosbachd3595712011-08-03 23:50:40 +00004185 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004186 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004187 return Error(Parser.getTok().getLoc(), "']' expected");
4188 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004189 Parser.Lex(); // Eat right bracket token.
4190
4191 // Don't worry about range checking the value here. That's handled by
4192 // the is*() predicates.
4193 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004194 ARM_AM::no_shift, 0, 0,
4195 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004196
4197 // If there's a pre-indexing writeback marker, '!', just add it as a token
4198 // operand.
4199 if (Parser.getTok().is(AsmToken::Exclaim)) {
4200 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4201 Parser.Lex(); // Eat the '!'.
4202 }
4203
4204 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004205 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004206
4207 // The register offset is optionally preceded by a '+' or '-'
4208 bool isNegative = false;
4209 if (Parser.getTok().is(AsmToken::Minus)) {
4210 isNegative = true;
4211 Parser.Lex(); // Eat the '-'.
4212 } else if (Parser.getTok().is(AsmToken::Plus)) {
4213 // Nothing to do.
4214 Parser.Lex(); // Eat the '+'.
4215 }
4216
4217 E = Parser.getTok().getLoc();
4218 int OffsetRegNum = tryParseRegister();
4219 if (OffsetRegNum == -1)
4220 return Error(E, "register expected");
4221
4222 // If there's a shift operator, handle it.
4223 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004224 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004225 if (Parser.getTok().is(AsmToken::Comma)) {
4226 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004227 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004228 return true;
4229 }
4230
4231 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004232 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004233 return Error(Parser.getTok().getLoc(), "']' expected");
4234 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004235 Parser.Lex(); // Eat right bracket token.
4236
4237 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004238 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004239 S, E));
4240
Jim Grosbachc320c852011-08-05 21:28:30 +00004241 // If there's a pre-indexing writeback marker, '!', just add it as a token
4242 // operand.
4243 if (Parser.getTok().is(AsmToken::Exclaim)) {
4244 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4245 Parser.Lex(); // Eat the '!'.
4246 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004247
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004248 return false;
4249}
4250
Jim Grosbachd3595712011-08-03 23:50:40 +00004251/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004252/// ( lsl | lsr | asr | ror ) , # shift_amount
4253/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004254/// return true if it parses a shift otherwise it returns false.
4255bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4256 unsigned &Amount) {
4257 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004258 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004259 if (Tok.isNot(AsmToken::Identifier))
4260 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004261 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004262 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4263 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004264 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004265 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004266 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004267 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004268 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004269 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004270 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004271 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004272 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004273 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004274 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004275 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004276
Jim Grosbachd3595712011-08-03 23:50:40 +00004277 // rrx stands alone.
4278 Amount = 0;
4279 if (St != ARM_AM::rrx) {
4280 Loc = Parser.getTok().getLoc();
4281 // A '#' and a shift amount.
4282 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004283 if (HashTok.isNot(AsmToken::Hash) &&
4284 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004285 return Error(HashTok.getLoc(), "'#' expected");
4286 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004287
Jim Grosbachd3595712011-08-03 23:50:40 +00004288 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004289 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004290 return true;
4291 // Range check the immediate.
4292 // lsl, ror: 0 <= imm <= 31
4293 // lsr, asr: 0 <= imm <= 32
4294 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4295 if (!CE)
4296 return Error(Loc, "shift amount must be an immediate");
4297 int64_t Imm = CE->getValue();
4298 if (Imm < 0 ||
4299 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4300 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4301 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004302 // If <ShiftTy> #0, turn it into a no_shift.
4303 if (Imm == 0)
4304 St = ARM_AM::lsl;
4305 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4306 if (Imm == 32)
4307 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004308 Amount = Imm;
4309 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004310
4311 return false;
4312}
4313
Jim Grosbache7fbce72011-10-03 23:38:36 +00004314/// parseFPImm - A floating point immediate expression operand.
4315ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4316parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004317 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004318 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004319 // integer only.
4320 //
4321 // This routine still creates a generic Immediate operand, containing
4322 // a bitcast of the 64-bit floating point value. The various operands
4323 // that accept floats can check whether the value is valid for them
4324 // via the standard is*() predicates.
4325
Jim Grosbache7fbce72011-10-03 23:38:36 +00004326 SMLoc S = Parser.getTok().getLoc();
4327
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004328 if (Parser.getTok().isNot(AsmToken::Hash) &&
4329 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004330 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004331
4332 // Disambiguate the VMOV forms that can accept an FP immediate.
4333 // vmov.f32 <sreg>, #imm
4334 // vmov.f64 <dreg>, #imm
4335 // vmov.f32 <dreg>, #imm @ vector f32x2
4336 // vmov.f32 <qreg>, #imm @ vector f32x4
4337 //
4338 // There are also the NEON VMOV instructions which expect an
4339 // integer constant. Make sure we don't try to parse an FPImm
4340 // for these:
4341 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4342 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4343 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4344 TyOp->getToken() != ".f64"))
4345 return MatchOperand_NoMatch;
4346
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004347 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004348
4349 // Handle negation, as that still comes through as a separate token.
4350 bool isNegative = false;
4351 if (Parser.getTok().is(AsmToken::Minus)) {
4352 isNegative = true;
4353 Parser.Lex();
4354 }
4355 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004356 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004357 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004358 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004359 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4360 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004361 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004362 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004363 Operands.push_back(ARMOperand::CreateImm(
4364 MCConstantExpr::Create(IntVal, getContext()),
4365 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004366 return MatchOperand_Success;
4367 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004368 // Also handle plain integers. Instructions which allow floating point
4369 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004370 if (Tok.is(AsmToken::Integer)) {
4371 int64_t Val = Tok.getIntVal();
4372 Parser.Lex(); // Eat the token.
4373 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004374 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004375 return MatchOperand_ParseFail;
4376 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004377 double RealVal = ARM_AM::getFPImmFloat(Val);
4378 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4379 Operands.push_back(ARMOperand::CreateImm(
4380 MCConstantExpr::Create(Val, getContext()), S,
4381 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004382 return MatchOperand_Success;
4383 }
4384
Jim Grosbach235c8d22012-01-19 02:47:30 +00004385 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004386 return MatchOperand_ParseFail;
4387}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004388
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004389/// Parse a arm instruction operand. For now this parses the operand regardless
4390/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004391bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004392 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004393 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004394
4395 // Check if the current operand has a custom associated parser, if so, try to
4396 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004397 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4398 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004399 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004400 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4401 // there was a match, but an error occurred, in which case, just return that
4402 // the operand parsing failed.
4403 if (ResTy == MatchOperand_ParseFail)
4404 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004405
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004406 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004407 default:
4408 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004409 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004410 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004411 // If we've seen a branch mnemonic, the next operand must be a label. This
4412 // is true even if the label is a register name. So "br r1" means branch to
4413 // label "r1".
4414 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4415 if (!ExpectLabel) {
4416 if (!tryParseRegisterWithWriteBack(Operands))
4417 return false;
4418 int Res = tryParseShiftRegister(Operands);
4419 if (Res == 0) // success
4420 return false;
4421 else if (Res == -1) // irrecoverable error
4422 return true;
4423 // If this is VMRS, check for the apsr_nzcv operand.
4424 if (Mnemonic == "vmrs" &&
4425 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4426 S = Parser.getTok().getLoc();
4427 Parser.Lex();
4428 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4429 return false;
4430 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004431 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004432
4433 // Fall though for the Identifier case that is not a register or a
4434 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004435 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004436 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004437 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004438 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004439 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004440 // This was not a register so parse other operands that start with an
4441 // identifier (like labels) as expressions and create them as immediates.
4442 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004443 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004444 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004445 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004446 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004447 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4448 return false;
4449 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004450 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004451 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004452 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004453 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004454 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004455 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004456 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004457 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004458 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004459
4460 if (Parser.getTok().isNot(AsmToken::Colon)) {
4461 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4462 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004463 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004464 return true;
4465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4466 if (CE) {
4467 int32_t Val = CE->getValue();
4468 if (isNegative && Val == 0)
4469 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4470 }
4471 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4472 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004473
4474 // There can be a trailing '!' on operands that we want as a separate
4475 // '!' Token operand. Handle that here. For example, the compatibilty
4476 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4477 if (Parser.getTok().is(AsmToken::Exclaim)) {
4478 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4479 Parser.getTok().getLoc()));
4480 Parser.Lex(); // Eat exclaim token
4481 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004482 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004483 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004484 // w/ a ':' after the '#', it's just like a plain ':'.
4485 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004486 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004487 case AsmToken::Colon: {
4488 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004489 // FIXME: Check it's an expression prefix,
4490 // e.g. (FOO - :lower16:BAR) isn't legal.
4491 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004492 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004493 return true;
4494
Evan Cheng965b3c72011-01-13 07:58:56 +00004495 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004496 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004497 return true;
4498
Evan Cheng965b3c72011-01-13 07:58:56 +00004499 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004500 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004501 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004502 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004503 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004504 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004505 }
4506}
4507
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004508// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004509// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004510bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004511 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004512
4513 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004514 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004515 Parser.Lex(); // Eat ':'
4516
4517 if (getLexer().isNot(AsmToken::Identifier)) {
4518 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4519 return true;
4520 }
4521
4522 StringRef IDVal = Parser.getTok().getIdentifier();
4523 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004524 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004525 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004526 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004527 } else {
4528 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4529 return true;
4530 }
4531 Parser.Lex();
4532
4533 if (getLexer().isNot(AsmToken::Colon)) {
4534 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4535 return true;
4536 }
4537 Parser.Lex(); // Eat the last ':'
4538 return false;
4539}
4540
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004541/// \brief Given a mnemonic, split out possible predication code and carry
4542/// setting letters to form a canonical mnemonic and flags.
4543//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004544// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004545// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004546StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004547 unsigned &PredicationCode,
4548 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004549 unsigned &ProcessorIMod,
4550 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004551 PredicationCode = ARMCC::AL;
4552 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004553 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004554
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004555 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004556 //
4557 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004558 if ((Mnemonic == "movs" && isThumb()) ||
4559 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4560 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4561 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4562 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004563 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004564 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4565 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004566 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004567 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004568 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4569 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4570 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004571 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004572
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004573 // First, split out any predication code. Ignore mnemonics we know aren't
4574 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004575 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004576 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004577 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004578 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004579 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4580 .Case("eq", ARMCC::EQ)
4581 .Case("ne", ARMCC::NE)
4582 .Case("hs", ARMCC::HS)
4583 .Case("cs", ARMCC::HS)
4584 .Case("lo", ARMCC::LO)
4585 .Case("cc", ARMCC::LO)
4586 .Case("mi", ARMCC::MI)
4587 .Case("pl", ARMCC::PL)
4588 .Case("vs", ARMCC::VS)
4589 .Case("vc", ARMCC::VC)
4590 .Case("hi", ARMCC::HI)
4591 .Case("ls", ARMCC::LS)
4592 .Case("ge", ARMCC::GE)
4593 .Case("lt", ARMCC::LT)
4594 .Case("gt", ARMCC::GT)
4595 .Case("le", ARMCC::LE)
4596 .Case("al", ARMCC::AL)
4597 .Default(~0U);
4598 if (CC != ~0U) {
4599 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4600 PredicationCode = CC;
4601 }
Bill Wendling193961b2010-10-29 23:50:21 +00004602 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004603
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004604 // Next, determine if we have a carry setting bit. We explicitly ignore all
4605 // the instructions we know end in 's'.
4606 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004607 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004608 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4609 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4610 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004611 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004612 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004613 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004614 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004615 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004616 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004617 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4618 CarrySetting = true;
4619 }
4620
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004621 // The "cps" instruction can have a interrupt mode operand which is glued into
4622 // the mnemonic. Check if this is the case, split it and parse the imod op
4623 if (Mnemonic.startswith("cps")) {
4624 // Split out any imod code.
4625 unsigned IMod =
4626 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4627 .Case("ie", ARM_PROC::IE)
4628 .Case("id", ARM_PROC::ID)
4629 .Default(~0U);
4630 if (IMod != ~0U) {
4631 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4632 ProcessorIMod = IMod;
4633 }
4634 }
4635
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004636 // The "it" instruction has the condition mask on the end of the mnemonic.
4637 if (Mnemonic.startswith("it")) {
4638 ITMask = Mnemonic.slice(2, Mnemonic.size());
4639 Mnemonic = Mnemonic.slice(0, 2);
4640 }
4641
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004642 return Mnemonic;
4643}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004644
4645/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4646/// inclusion of carry set or predication code operands.
4647//
4648// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004649void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004650getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004651 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004652 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4653 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004654 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004655 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004656 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004657 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004658 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004659 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004660 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004661 Mnemonic == "mla" || Mnemonic == "smlal" ||
4662 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004663 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004664 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004665 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004666
Tim Northover2c45a382013-06-26 16:52:40 +00004667 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4668 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4669 Mnemonic == "trap" || Mnemonic == "setend" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004670 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4671 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004672 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4673 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4674 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004675 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004676 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004677 } else if (!isThumb()) {
4678 // Some instructions are only predicable in Thumb mode
4679 CanAcceptPredicationCode
4680 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4681 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4682 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4683 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4684 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4685 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4686 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4687 } else if (isThumbOne()) {
4688 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004689 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004690 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004691}
4692
Jim Grosbach7283da92011-08-16 21:12:37 +00004693bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4694 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004695 // FIXME: This is all horribly hacky. We really need a better way to deal
4696 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004697
4698 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4699 // another does not. Specifically, the MOVW instruction does not. So we
4700 // special case it here and remove the defaulted (non-setting) cc_out
4701 // operand if that's the instruction we're trying to match.
4702 //
4703 // We do this as post-processing of the explicit operands rather than just
4704 // conditionally adding the cc_out in the first place because we need
4705 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004706 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004707 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4708 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4709 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4710 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004711
4712 // Register-register 'add' for thumb does not have a cc_out operand
4713 // when there are only two register operands.
4714 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4715 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4716 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4717 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4718 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004719 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004720 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4721 // have to check the immediate range here since Thumb2 has a variant
4722 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004723 if (((isThumb() && Mnemonic == "add") ||
4724 (isThumbTwo() && Mnemonic == "sub")) &&
4725 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004726 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4727 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4728 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004729 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004730 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004731 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004732 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004733 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4734 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004735 // selecting via the generic "add" mnemonic, so to know that we
4736 // should remove the cc_out operand, we have to explicitly check that
4737 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004738 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4739 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004740 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4741 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4742 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4743 // Nest conditions rather than one big 'if' statement for readability.
4744 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004745 // If both registers are low, we're in an IT block, and the immediate is
4746 // in range, we should use encoding T1 instead, which has a cc_out.
4747 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004748 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004749 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4750 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4751 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004752 // Check against T3. If the second register is the PC, this is an
4753 // alternate form of ADR, which uses encoding T4, so check for that too.
4754 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4755 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4756 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004757
4758 // Otherwise, we use encoding T4, which does not have a cc_out
4759 // operand.
4760 return true;
4761 }
4762
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004763 // The thumb2 multiply instruction doesn't have a CCOut register, so
4764 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4765 // use the 16-bit encoding or not.
4766 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4767 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4768 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4769 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4770 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4771 // If the registers aren't low regs, the destination reg isn't the
4772 // same as one of the source regs, or the cc_out operand is zero
4773 // outside of an IT block, we have to use the 32-bit encoding, so
4774 // remove the cc_out operand.
4775 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4776 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004777 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004778 !inITBlock() ||
4779 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4780 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4781 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4782 static_cast<ARMOperand*>(Operands[4])->getReg())))
4783 return true;
4784
Jim Grosbachefa7e952011-11-15 19:55:16 +00004785 // Also check the 'mul' syntax variant that doesn't specify an explicit
4786 // destination register.
4787 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4788 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4789 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4790 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4791 // If the registers aren't low regs or the cc_out operand is zero
4792 // outside of an IT block, we have to use the 32-bit encoding, so
4793 // remove the cc_out operand.
4794 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4795 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4796 !inITBlock()))
4797 return true;
4798
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004799
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004800
Jim Grosbach4b701af2011-08-24 21:42:27 +00004801 // Register-register 'add/sub' for thumb does not have a cc_out operand
4802 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4803 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4804 // right, this will result in better diagnostics (which operand is off)
4805 // anyway.
4806 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4807 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004808 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4809 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004810 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4811 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4812 (Operands.size() == 6 &&
4813 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004814 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004815
Jim Grosbach7283da92011-08-16 21:12:37 +00004816 return false;
4817}
4818
Joey Goulye8602552013-07-19 16:34:16 +00004819bool ARMAsmParser::shouldOmitPredicateOperand(
4820 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4821 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4822 unsigned RegIdx = 3;
4823 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4824 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4825 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4826 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4827 RegIdx = 4;
4828
4829 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4830 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4831 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4832 ARMMCRegisterClasses[ARM::QPRRegClassID]
4833 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4834 return true;
4835 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004836 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004837}
4838
Jim Grosbach12952fe2011-11-11 23:08:10 +00004839static bool isDataTypeToken(StringRef Tok) {
4840 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4841 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4842 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4843 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4844 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4845 Tok == ".f" || Tok == ".d";
4846}
4847
4848// FIXME: This bit should probably be handled via an explicit match class
4849// in the .td files that matches the suffix instead of having it be
4850// a literal string token the way it is now.
4851static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4852 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4853}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004854static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4855 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004856/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004857bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4858 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004859 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004860 // Apply mnemonic aliases before doing anything else, as the destination
4861 // mnemnonic may include suffices and we want to handle them normally.
4862 // The generic tblgen'erated code does this later, at the start of
4863 // MatchInstructionImpl(), but that's too late for aliases that include
4864 // any sort of suffix.
4865 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00004866 unsigned AssemblerDialect = getParser().getAssemblerDialect();
4867 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00004868
Jim Grosbachab5830e2011-12-14 02:16:11 +00004869 // First check for the ARM-specific .req directive.
4870 if (Parser.getTok().is(AsmToken::Identifier) &&
4871 Parser.getTok().getIdentifier() == ".req") {
4872 parseDirectiveReq(Name, NameLoc);
4873 // We always return 'error' for this, as we're done with this
4874 // statement and don't need to match the 'instruction."
4875 return true;
4876 }
4877
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004878 // Create the leading tokens for the mnemonic, split by '.' characters.
4879 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004880 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004881
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004882 // Split out the predication code and carry setting flag from the mnemonic.
4883 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004884 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004885 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004886 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004887 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004888 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004889
Jim Grosbach1c171b12011-08-25 17:23:55 +00004890 // In Thumb1, only the branch (B) instruction can be predicated.
4891 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004892 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00004893 return Error(NameLoc, "conditional execution not supported in Thumb1");
4894 }
4895
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004896 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4897
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004898 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4899 // is the mask as it will be for the IT encoding if the conditional
4900 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4901 // where the conditional bit0 is zero, the instruction post-processing
4902 // will adjust the mask accordingly.
4903 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00004904 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4905 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004906 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004907 return Error(Loc, "too many conditions on IT instruction");
4908 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004909 unsigned Mask = 8;
4910 for (unsigned i = ITMask.size(); i != 0; --i) {
4911 char pos = ITMask[i - 1];
4912 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004913 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004914 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004915 }
4916 Mask >>= 1;
4917 if (ITMask[i - 1] == 't')
4918 Mask |= 8;
4919 }
Jim Grosbached16ec42011-08-29 22:24:09 +00004920 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004921 }
4922
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004923 // FIXME: This is all a pretty gross hack. We should automatically handle
4924 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00004925
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004926 // Next, add the CCOut and ConditionCode operands, if needed.
4927 //
4928 // For mnemonics which can ever incorporate a carry setting bit or predication
4929 // code, our matching model involves us always generating CCOut and
4930 // ConditionCode operands to match the mnemonic "as written" and then we let
4931 // the matcher deal with finding the right instruction or generating an
4932 // appropriate error.
4933 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004934 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004935
Jim Grosbach03a8a162011-07-14 22:04:21 +00004936 // If we had a carry-set on an instruction that can't do that, issue an
4937 // error.
4938 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004939 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004940 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00004941 "' can not set flags, but 's' suffix specified");
4942 }
Jim Grosbach0a547702011-07-22 17:44:50 +00004943 // If we had a predication code on an instruction that can't do that, issue an
4944 // error.
4945 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004946 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00004947 return Error(NameLoc, "instruction '" + Mnemonic +
4948 "' is not predicable, but condition code specified");
4949 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00004950
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004951 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00004952 if (CanAcceptCarrySet) {
4953 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004954 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00004955 Loc));
4956 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004957
4958 // Add the predication code operand, if necessary.
4959 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00004960 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4961 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004962 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00004963 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004964 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004965
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004966 // Add the processor imod operand, if necessary.
4967 if (ProcessorIMod) {
4968 Operands.push_back(ARMOperand::CreateImm(
4969 MCConstantExpr::Create(ProcessorIMod, getContext()),
4970 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004971 }
4972
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004973 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004974 while (Next != StringRef::npos) {
4975 Start = Next;
4976 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004977 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004978
Jim Grosbach12952fe2011-11-11 23:08:10 +00004979 // Some NEON instructions have an optional datatype suffix that is
4980 // completely ignored. Check for that.
4981 if (isDataTypeToken(ExtraToken) &&
4982 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4983 continue;
4984
Kevin Enderbyc5d09352013-06-18 20:19:24 +00004985 // For for ARM mode generate an error if the .n qualifier is used.
4986 if (ExtraToken == ".n" && !isThumb()) {
4987 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4988 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
4989 "arm mode");
4990 }
4991
4992 // The .n qualifier is always discarded as that is what the tables
4993 // and matcher expect. In ARM mode the .w qualifier has no effect,
4994 // so discard it to avoid errors that can be caused by the matcher.
4995 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00004996 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4997 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4998 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004999 }
5000
5001 // Read the remaining operands.
5002 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005003 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005004 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005005 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005006 return true;
5007 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005008
5009 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005010 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005011
5012 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005013 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005014 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005015 return true;
5016 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005017 }
5018 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005019
Chris Lattnera2a9d162010-09-11 16:18:25 +00005020 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005021 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005022 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005023 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005024 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005025
Chris Lattner91689c12010-09-08 05:10:46 +00005026 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005027
Jim Grosbach7283da92011-08-16 21:12:37 +00005028 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5029 // do and don't have a cc_out optional-def operand. With some spot-checks
5030 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005031 // parse and adjust accordingly before actually matching. We shouldn't ever
5032 // try to remove a cc_out operand that was explicitly set on the the
5033 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5034 // table driven matcher doesn't fit well with the ARM instruction set.
5035 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005036 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5037 Operands.erase(Operands.begin() + 1);
5038 delete Op;
5039 }
5040
Joey Goulye8602552013-07-19 16:34:16 +00005041 // Some instructions have the same mnemonic, but don't always
5042 // have a predicate. Distinguish them here and delete the
5043 // predicate if needed.
5044 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5045 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5046 Operands.erase(Operands.begin() + 1);
5047 delete Op;
5048 }
5049
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005050 // ARM mode 'blx' need special handling, as the register operand version
5051 // is predicable, but the label operand version is not. So, we can't rely
5052 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005053 // a k_CondCode operand in the list. If we're trying to match the label
5054 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005055 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5056 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5057 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5058 Operands.erase(Operands.begin() + 1);
5059 delete Op;
5060 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005061
Weiming Zhao8f56f882012-11-16 21:55:34 +00005062 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5063 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5064 // a single GPRPair reg operand is used in the .td file to replace the two
5065 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5066 // expressed as a GPRPair, so we have to manually merge them.
5067 // FIXME: We would really like to be able to tablegen'erate this.
5068 if (!isThumb() && Operands.size() > 4 &&
5069 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5070 bool isLoad = (Mnemonic == "ldrexd");
5071 unsigned Idx = isLoad ? 2 : 3;
5072 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5073 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5074
5075 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5076 // Adjust only if Op1 and Op2 are GPRs.
5077 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5078 MRC.contains(Op2->getReg())) {
5079 unsigned Reg1 = Op1->getReg();
5080 unsigned Reg2 = Op2->getReg();
5081 unsigned Rt = MRI->getEncodingValue(Reg1);
5082 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5083
5084 // Rt2 must be Rt + 1 and Rt must be even.
5085 if (Rt + 1 != Rt2 || (Rt & 1)) {
5086 Error(Op2->getStartLoc(), isLoad ?
5087 "destination operands must be sequential" :
5088 "source operands must be sequential");
5089 return true;
5090 }
5091 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5092 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5093 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5094 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5095 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5096 delete Op1;
5097 delete Op2;
5098 }
5099 }
5100
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005101 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005102}
5103
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005104// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005105
5106// return 'true' if register list contains non-low GPR registers,
5107// 'false' otherwise. If Reg is in the register list or is HiReg, set
5108// 'containsReg' to true.
5109static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5110 unsigned HiReg, bool &containsReg) {
5111 containsReg = false;
5112 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5113 unsigned OpReg = Inst.getOperand(i).getReg();
5114 if (OpReg == Reg)
5115 containsReg = true;
5116 // Anything other than a low register isn't legal here.
5117 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5118 return true;
5119 }
5120 return false;
5121}
5122
Jim Grosbacha31f2232011-09-07 18:05:34 +00005123// Check if the specified regisgter is in the register list of the inst,
5124// starting at the indicated operand number.
5125static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5126 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5127 unsigned OpReg = Inst.getOperand(i).getReg();
5128 if (OpReg == Reg)
5129 return true;
5130 }
5131 return false;
5132}
5133
Jim Grosbached16ec42011-08-29 22:24:09 +00005134// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5135// the ARMInsts array) instead. Getting that here requires awkward
5136// API changes, though. Better way?
5137namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005138extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005139}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005140static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005141 return ARMInsts[Opcode];
5142}
5143
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005144// FIXME: We would really like to be able to tablegen'erate this.
5145bool ARMAsmParser::
5146validateInstruction(MCInst &Inst,
5147 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005148 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005149 SMLoc Loc = Operands[0]->getStartLoc();
5150 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005151 // NOTE: BKPT instruction has the interesting property of being
5152 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005153 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005154 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5155 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005156 unsigned bit = 1;
5157 if (ITState.FirstCond)
5158 ITState.FirstCond = false;
5159 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005160 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005161 // The instruction must be predicable.
5162 if (!MCID.isPredicable())
5163 return Error(Loc, "instructions in IT block must be predicable");
5164 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5165 unsigned ITCond = bit ? ITState.Cond :
5166 ARMCC::getOppositeCondition(ITState.Cond);
5167 if (Cond != ITCond) {
5168 // Find the condition code Operand to get its SMLoc information.
5169 SMLoc CondLoc;
5170 for (unsigned i = 1; i < Operands.size(); ++i)
5171 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5172 CondLoc = Operands[i]->getStartLoc();
5173 return Error(CondLoc, "incorrect condition in IT block; got '" +
5174 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5175 "', but expected '" +
5176 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5177 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005178 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005179 } else if (isThumbTwo() && MCID.isPredicable() &&
5180 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005181 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5182 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005183 return Error(Loc, "predicated instructions must be in IT block");
5184
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005185 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005186 case ARM::LDRD:
5187 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005188 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005189 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005190 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5191 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005192 if (Rt2 != Rt + 1)
5193 return Error(Operands[3]->getStartLoc(),
5194 "destination operands must be sequential");
5195 return false;
5196 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005197 case ARM::STRD: {
5198 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005199 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5200 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005201 if (Rt2 != Rt + 1)
5202 return Error(Operands[3]->getStartLoc(),
5203 "source operands must be sequential");
5204 return false;
5205 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005206 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005207 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005208 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005209 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5210 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005211 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005212 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005213 "source operands must be sequential");
5214 return false;
5215 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005216 case ARM::SBFX:
5217 case ARM::UBFX: {
5218 // width must be in range [1, 32-lsb]
5219 unsigned lsb = Inst.getOperand(2).getImm();
5220 unsigned widthm1 = Inst.getOperand(3).getImm();
5221 if (widthm1 >= 32 - lsb)
5222 return Error(Operands[5]->getStartLoc(),
5223 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005224 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005225 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005226 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005227 // If we're parsing Thumb2, the .w variant is available and handles
5228 // most cases that are normally illegal for a Thumb1 LDM
5229 // instruction. We'll make the transformation in processInstruction()
5230 // if necessary.
5231 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005232 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005233 // in the register list.
5234 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005235 bool hasWritebackToken =
5236 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5237 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005238 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005239 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005240 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5241 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005242 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005243 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005244 return Error(Operands[2]->getStartLoc(),
5245 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005246 // If we should not have writeback, there must not be a '!'. This is
5247 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005248 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005249 return Error(Operands[3]->getStartLoc(),
5250 "writeback operator '!' not allowed when base register "
5251 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005252
5253 break;
5254 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005255 case ARM::t2LDMIA_UPD: {
5256 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5257 return Error(Operands[4]->getStartLoc(),
5258 "writeback operator '!' not allowed when base register "
5259 "in register list");
5260 break;
5261 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005262 case ARM::tMUL: {
5263 // The second source operand must be the same register as the destination
5264 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005265 //
5266 // In this case, we must directly check the parsed operands because the
5267 // cvtThumbMultiply() function is written in such a way that it guarantees
5268 // this first statement is always true for the new Inst. Essentially, the
5269 // destination is unconditionally copied into the second source operand
5270 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005271 if (Operands.size() == 6 &&
5272 (((ARMOperand*)Operands[3])->getReg() !=
5273 ((ARMOperand*)Operands[5])->getReg()) &&
5274 (((ARMOperand*)Operands[3])->getReg() !=
5275 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005276 return Error(Operands[3]->getStartLoc(),
5277 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005278 }
5279 break;
5280 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005281 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5282 // so only issue a diagnostic for thumb1. The instructions will be
5283 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005284 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005285 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005286 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5287 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005288 return Error(Operands[2]->getStartLoc(),
5289 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005290 break;
5291 }
5292 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005293 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005294 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5295 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005296 return Error(Operands[2]->getStartLoc(),
5297 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005298 break;
5299 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005300 case ARM::tSTMIA_UPD: {
5301 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005302 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005303 return Error(Operands[4]->getStartLoc(),
5304 "registers must be in range r0-r7");
5305 break;
5306 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005307 case ARM::tADDrSP: {
5308 // If the non-SP source operand and the destination operand are not the
5309 // same, we need thumb2 (for the wide encoding), or we have an error.
5310 if (!isThumbTwo() &&
5311 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5312 return Error(Operands[4]->getStartLoc(),
5313 "source register must be the same as destination");
5314 }
5315 break;
5316 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005317 }
5318
5319 return false;
5320}
5321
Jim Grosbach1a747242012-01-23 23:45:44 +00005322static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005323 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005324 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005325 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005326 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5327 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5328 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5329 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5330 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5331 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5332 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5333 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5334 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005335
5336 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005337 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5338 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5339 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5340 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5341 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005342
Jim Grosbach1e946a42012-01-24 00:43:12 +00005343 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5344 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5345 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5346 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5347 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005348
Jim Grosbach1e946a42012-01-24 00:43:12 +00005349 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5350 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5351 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5352 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5353 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005354
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005355 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005356 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5357 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5358 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5359 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5360 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5361 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5362 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5363 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5364 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5365 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5366 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5367 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5368 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5369 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5370 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005371
Jim Grosbach1a747242012-01-23 23:45:44 +00005372 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005373 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5374 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5375 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5376 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5377 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5378 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5379 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5380 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5381 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5382 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5383 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5384 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5385 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5386 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5387 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5388 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5389 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5390 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005391
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005392 // VST4LN
5393 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5394 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5395 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5396 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5397 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5398 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5399 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5400 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5401 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5402 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5403 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5404 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5405 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5406 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5407 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5408
Jim Grosbachda70eac2012-01-24 00:58:13 +00005409 // VST4
5410 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5411 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5412 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5413 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5414 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5415 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5416 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5417 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5418 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5419 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5420 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5421 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5422 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5423 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5424 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5425 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5426 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5427 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005428 }
5429}
5430
Jim Grosbach1a747242012-01-23 23:45:44 +00005431static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005432 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005433 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005434 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005435 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5436 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5437 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5438 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5439 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5440 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5441 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5442 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5443 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005444
5445 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005446 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5447 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5448 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5449 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5450 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5451 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5452 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5453 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5454 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5455 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5456 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5457 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5458 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5459 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5460 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005461
Jim Grosbachb78403c2012-01-24 23:47:04 +00005462 // VLD3DUP
5463 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5464 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5465 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5466 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5467 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5468 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5469 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5470 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5471 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5472 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5473 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5474 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5475 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5476 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5477 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5478 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5479 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5480 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5481
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005482 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005483 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5484 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5485 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5486 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5487 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5488 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5489 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5490 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5491 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5492 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5493 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5494 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5495 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5496 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5497 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005498
5499 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005500 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5501 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5502 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5503 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5504 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5505 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5506 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5507 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5508 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5509 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5510 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5511 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5512 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5513 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5514 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5515 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5516 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5517 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005518
Jim Grosbach14952a02012-01-24 18:37:25 +00005519 // VLD4LN
5520 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5521 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5522 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5523 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5524 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5525 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5526 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5527 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5528 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5529 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5530 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5531 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5532 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5533 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5534 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5535
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005536 // VLD4DUP
5537 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5538 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5539 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5540 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5541 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5542 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5543 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5544 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5545 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5546 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5547 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5548 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5549 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5550 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5551 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5552 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5553 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5554 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5555
Jim Grosbached561fc2012-01-24 00:43:17 +00005556 // VLD4
5557 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5558 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5559 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5560 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5561 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5562 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5563 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5564 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5565 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5566 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5567 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5568 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5569 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5570 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5571 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5572 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5573 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5574 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005575 }
5576}
5577
Jim Grosbachafad0532011-11-10 23:42:14 +00005578bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005579processInstruction(MCInst &Inst,
5580 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5581 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005582 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5583 case ARM::ADDri: {
5584 if (Inst.getOperand(1).getReg() != ARM::PC ||
5585 Inst.getOperand(5).getReg() != 0)
5586 return false;
5587 MCInst TmpInst;
5588 TmpInst.setOpcode(ARM::ADR);
5589 TmpInst.addOperand(Inst.getOperand(0));
5590 TmpInst.addOperand(Inst.getOperand(2));
5591 TmpInst.addOperand(Inst.getOperand(3));
5592 TmpInst.addOperand(Inst.getOperand(4));
5593 Inst = TmpInst;
5594 return true;
5595 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005596 // Aliases for alternate PC+imm syntax of LDR instructions.
5597 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005598 // Select the narrow version if the immediate will fit.
5599 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005600 Inst.getOperand(1).getImm() <= 0xff &&
5601 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5602 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005603 Inst.setOpcode(ARM::tLDRpci);
5604 else
5605 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005606 return true;
5607 case ARM::t2LDRBpcrel:
5608 Inst.setOpcode(ARM::t2LDRBpci);
5609 return true;
5610 case ARM::t2LDRHpcrel:
5611 Inst.setOpcode(ARM::t2LDRHpci);
5612 return true;
5613 case ARM::t2LDRSBpcrel:
5614 Inst.setOpcode(ARM::t2LDRSBpci);
5615 return true;
5616 case ARM::t2LDRSHpcrel:
5617 Inst.setOpcode(ARM::t2LDRSHpci);
5618 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005619 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005620 case ARM::VST1LNdWB_register_Asm_8:
5621 case ARM::VST1LNdWB_register_Asm_16:
5622 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005623 MCInst TmpInst;
5624 // Shuffle the operands around so the lane index operand is in the
5625 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005626 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005627 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005628 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5629 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5630 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5631 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5632 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5633 TmpInst.addOperand(Inst.getOperand(1)); // lane
5634 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5635 TmpInst.addOperand(Inst.getOperand(6));
5636 Inst = TmpInst;
5637 return true;
5638 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005639
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005640 case ARM::VST2LNdWB_register_Asm_8:
5641 case ARM::VST2LNdWB_register_Asm_16:
5642 case ARM::VST2LNdWB_register_Asm_32:
5643 case ARM::VST2LNqWB_register_Asm_16:
5644 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005645 MCInst TmpInst;
5646 // Shuffle the operands around so the lane index operand is in the
5647 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005648 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005649 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005650 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5651 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5652 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5653 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5656 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005657 TmpInst.addOperand(Inst.getOperand(1)); // lane
5658 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5659 TmpInst.addOperand(Inst.getOperand(6));
5660 Inst = TmpInst;
5661 return true;
5662 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005663
5664 case ARM::VST3LNdWB_register_Asm_8:
5665 case ARM::VST3LNdWB_register_Asm_16:
5666 case ARM::VST3LNdWB_register_Asm_32:
5667 case ARM::VST3LNqWB_register_Asm_16:
5668 case ARM::VST3LNqWB_register_Asm_32: {
5669 MCInst TmpInst;
5670 // Shuffle the operands around so the lane index operand is in the
5671 // right place.
5672 unsigned Spacing;
5673 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5674 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5675 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5676 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5677 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5678 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5680 Spacing));
5681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5682 Spacing * 2));
5683 TmpInst.addOperand(Inst.getOperand(1)); // lane
5684 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5685 TmpInst.addOperand(Inst.getOperand(6));
5686 Inst = TmpInst;
5687 return true;
5688 }
5689
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005690 case ARM::VST4LNdWB_register_Asm_8:
5691 case ARM::VST4LNdWB_register_Asm_16:
5692 case ARM::VST4LNdWB_register_Asm_32:
5693 case ARM::VST4LNqWB_register_Asm_16:
5694 case ARM::VST4LNqWB_register_Asm_32: {
5695 MCInst TmpInst;
5696 // Shuffle the operands around so the lane index operand is in the
5697 // right place.
5698 unsigned Spacing;
5699 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5700 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5701 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5702 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5703 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5704 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5706 Spacing));
5707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5708 Spacing * 2));
5709 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5710 Spacing * 3));
5711 TmpInst.addOperand(Inst.getOperand(1)); // lane
5712 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5713 TmpInst.addOperand(Inst.getOperand(6));
5714 Inst = TmpInst;
5715 return true;
5716 }
5717
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005718 case ARM::VST1LNdWB_fixed_Asm_8:
5719 case ARM::VST1LNdWB_fixed_Asm_16:
5720 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005721 MCInst TmpInst;
5722 // Shuffle the operands around so the lane index operand is in the
5723 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005724 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5731 TmpInst.addOperand(Inst.getOperand(1)); // lane
5732 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5733 TmpInst.addOperand(Inst.getOperand(5));
5734 Inst = TmpInst;
5735 return true;
5736 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005737
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005738 case ARM::VST2LNdWB_fixed_Asm_8:
5739 case ARM::VST2LNdWB_fixed_Asm_16:
5740 case ARM::VST2LNdWB_fixed_Asm_32:
5741 case ARM::VST2LNqWB_fixed_Asm_16:
5742 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005743 MCInst TmpInst;
5744 // Shuffle the operands around so the lane index operand is in the
5745 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005746 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005747 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005748 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5749 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5750 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5751 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5754 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005755 TmpInst.addOperand(Inst.getOperand(1)); // lane
5756 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5757 TmpInst.addOperand(Inst.getOperand(5));
5758 Inst = TmpInst;
5759 return true;
5760 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005761
5762 case ARM::VST3LNdWB_fixed_Asm_8:
5763 case ARM::VST3LNdWB_fixed_Asm_16:
5764 case ARM::VST3LNdWB_fixed_Asm_32:
5765 case ARM::VST3LNqWB_fixed_Asm_16:
5766 case ARM::VST3LNqWB_fixed_Asm_32: {
5767 MCInst TmpInst;
5768 // Shuffle the operands around so the lane index operand is in the
5769 // right place.
5770 unsigned Spacing;
5771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5775 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5778 Spacing));
5779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5780 Spacing * 2));
5781 TmpInst.addOperand(Inst.getOperand(1)); // lane
5782 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5783 TmpInst.addOperand(Inst.getOperand(5));
5784 Inst = TmpInst;
5785 return true;
5786 }
5787
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005788 case ARM::VST4LNdWB_fixed_Asm_8:
5789 case ARM::VST4LNdWB_fixed_Asm_16:
5790 case ARM::VST4LNdWB_fixed_Asm_32:
5791 case ARM::VST4LNqWB_fixed_Asm_16:
5792 case ARM::VST4LNqWB_fixed_Asm_32: {
5793 MCInst TmpInst;
5794 // Shuffle the operands around so the lane index operand is in the
5795 // right place.
5796 unsigned Spacing;
5797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5798 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5799 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5800 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5801 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5804 Spacing));
5805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5806 Spacing * 2));
5807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5808 Spacing * 3));
5809 TmpInst.addOperand(Inst.getOperand(1)); // lane
5810 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5811 TmpInst.addOperand(Inst.getOperand(5));
5812 Inst = TmpInst;
5813 return true;
5814 }
5815
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005816 case ARM::VST1LNdAsm_8:
5817 case ARM::VST1LNdAsm_16:
5818 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005819 MCInst TmpInst;
5820 // Shuffle the operands around so the lane index operand is in the
5821 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005822 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005824 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5825 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5826 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5827 TmpInst.addOperand(Inst.getOperand(1)); // lane
5828 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5829 TmpInst.addOperand(Inst.getOperand(5));
5830 Inst = TmpInst;
5831 return true;
5832 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005833
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005834 case ARM::VST2LNdAsm_8:
5835 case ARM::VST2LNdAsm_16:
5836 case ARM::VST2LNdAsm_32:
5837 case ARM::VST2LNqAsm_16:
5838 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005839 MCInst TmpInst;
5840 // Shuffle the operands around so the lane index operand is in the
5841 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005842 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005843 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005844 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5845 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5846 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5848 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005849 TmpInst.addOperand(Inst.getOperand(1)); // lane
5850 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5851 TmpInst.addOperand(Inst.getOperand(5));
5852 Inst = TmpInst;
5853 return true;
5854 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005855
5856 case ARM::VST3LNdAsm_8:
5857 case ARM::VST3LNdAsm_16:
5858 case ARM::VST3LNdAsm_32:
5859 case ARM::VST3LNqAsm_16:
5860 case ARM::VST3LNqAsm_32: {
5861 MCInst TmpInst;
5862 // Shuffle the operands around so the lane index operand is in the
5863 // right place.
5864 unsigned Spacing;
5865 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5866 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5867 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5868 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5869 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5870 Spacing));
5871 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5872 Spacing * 2));
5873 TmpInst.addOperand(Inst.getOperand(1)); // lane
5874 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5875 TmpInst.addOperand(Inst.getOperand(5));
5876 Inst = TmpInst;
5877 return true;
5878 }
5879
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005880 case ARM::VST4LNdAsm_8:
5881 case ARM::VST4LNdAsm_16:
5882 case ARM::VST4LNdAsm_32:
5883 case ARM::VST4LNqAsm_16:
5884 case ARM::VST4LNqAsm_32: {
5885 MCInst TmpInst;
5886 // Shuffle the operands around so the lane index operand is in the
5887 // right place.
5888 unsigned Spacing;
5889 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5890 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5891 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5892 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5894 Spacing));
5895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5896 Spacing * 2));
5897 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5898 Spacing * 3));
5899 TmpInst.addOperand(Inst.getOperand(1)); // lane
5900 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5901 TmpInst.addOperand(Inst.getOperand(5));
5902 Inst = TmpInst;
5903 return true;
5904 }
5905
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005906 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005907 case ARM::VLD1LNdWB_register_Asm_8:
5908 case ARM::VLD1LNdWB_register_Asm_16:
5909 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00005910 MCInst TmpInst;
5911 // Shuffle the operands around so the lane index operand is in the
5912 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005913 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005914 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00005915 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5916 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5917 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5918 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5919 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5920 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5921 TmpInst.addOperand(Inst.getOperand(1)); // lane
5922 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5923 TmpInst.addOperand(Inst.getOperand(6));
5924 Inst = TmpInst;
5925 return true;
5926 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005927
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005928 case ARM::VLD2LNdWB_register_Asm_8:
5929 case ARM::VLD2LNdWB_register_Asm_16:
5930 case ARM::VLD2LNdWB_register_Asm_32:
5931 case ARM::VLD2LNqWB_register_Asm_16:
5932 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005933 MCInst TmpInst;
5934 // Shuffle the operands around so the lane index operand is in the
5935 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005936 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005937 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5940 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005941 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5942 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5943 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5944 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5945 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005946 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5947 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005948 TmpInst.addOperand(Inst.getOperand(1)); // lane
5949 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5950 TmpInst.addOperand(Inst.getOperand(6));
5951 Inst = TmpInst;
5952 return true;
5953 }
5954
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005955 case ARM::VLD3LNdWB_register_Asm_8:
5956 case ARM::VLD3LNdWB_register_Asm_16:
5957 case ARM::VLD3LNdWB_register_Asm_32:
5958 case ARM::VLD3LNqWB_register_Asm_16:
5959 case ARM::VLD3LNqWB_register_Asm_32: {
5960 MCInst TmpInst;
5961 // Shuffle the operands around so the lane index operand is in the
5962 // right place.
5963 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005964 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005965 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5967 Spacing));
5968 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005969 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005970 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5971 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5972 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5973 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5974 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5975 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5976 Spacing));
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005978 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005979 TmpInst.addOperand(Inst.getOperand(1)); // lane
5980 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5981 TmpInst.addOperand(Inst.getOperand(6));
5982 Inst = TmpInst;
5983 return true;
5984 }
5985
Jim Grosbach14952a02012-01-24 18:37:25 +00005986 case ARM::VLD4LNdWB_register_Asm_8:
5987 case ARM::VLD4LNdWB_register_Asm_16:
5988 case ARM::VLD4LNdWB_register_Asm_32:
5989 case ARM::VLD4LNqWB_register_Asm_16:
5990 case ARM::VLD4LNqWB_register_Asm_32: {
5991 MCInst TmpInst;
5992 // Shuffle the operands around so the lane index operand is in the
5993 // right place.
5994 unsigned Spacing;
5995 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5996 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5997 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5998 Spacing));
5999 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6000 Spacing * 2));
6001 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6002 Spacing * 3));
6003 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6004 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6005 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6006 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6007 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6009 Spacing));
6010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6011 Spacing * 2));
6012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6013 Spacing * 3));
6014 TmpInst.addOperand(Inst.getOperand(1)); // lane
6015 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6016 TmpInst.addOperand(Inst.getOperand(6));
6017 Inst = TmpInst;
6018 return true;
6019 }
6020
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006021 case ARM::VLD1LNdWB_fixed_Asm_8:
6022 case ARM::VLD1LNdWB_fixed_Asm_16:
6023 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006024 MCInst TmpInst;
6025 // Shuffle the operands around so the lane index operand is in the
6026 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006027 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006028 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006029 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6030 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6031 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6032 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6033 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6034 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6035 TmpInst.addOperand(Inst.getOperand(1)); // lane
6036 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6037 TmpInst.addOperand(Inst.getOperand(5));
6038 Inst = TmpInst;
6039 return true;
6040 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006041
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006042 case ARM::VLD2LNdWB_fixed_Asm_8:
6043 case ARM::VLD2LNdWB_fixed_Asm_16:
6044 case ARM::VLD2LNdWB_fixed_Asm_32:
6045 case ARM::VLD2LNqWB_fixed_Asm_16:
6046 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006047 MCInst TmpInst;
6048 // Shuffle the operands around so the lane index operand is in the
6049 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006050 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006051 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006052 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6054 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006055 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6056 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6057 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6058 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6059 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6061 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006062 TmpInst.addOperand(Inst.getOperand(1)); // lane
6063 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6064 TmpInst.addOperand(Inst.getOperand(5));
6065 Inst = TmpInst;
6066 return true;
6067 }
6068
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006069 case ARM::VLD3LNdWB_fixed_Asm_8:
6070 case ARM::VLD3LNdWB_fixed_Asm_16:
6071 case ARM::VLD3LNdWB_fixed_Asm_32:
6072 case ARM::VLD3LNqWB_fixed_Asm_16:
6073 case ARM::VLD3LNqWB_fixed_Asm_32: {
6074 MCInst TmpInst;
6075 // Shuffle the operands around so the lane index operand is in the
6076 // right place.
6077 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006078 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006079 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing));
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006083 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006084 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6085 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6086 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6087 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6088 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6090 Spacing));
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006092 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006093 TmpInst.addOperand(Inst.getOperand(1)); // lane
6094 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6095 TmpInst.addOperand(Inst.getOperand(5));
6096 Inst = TmpInst;
6097 return true;
6098 }
6099
Jim Grosbach14952a02012-01-24 18:37:25 +00006100 case ARM::VLD4LNdWB_fixed_Asm_8:
6101 case ARM::VLD4LNdWB_fixed_Asm_16:
6102 case ARM::VLD4LNdWB_fixed_Asm_32:
6103 case ARM::VLD4LNqWB_fixed_Asm_16:
6104 case ARM::VLD4LNqWB_fixed_Asm_32: {
6105 MCInst TmpInst;
6106 // Shuffle the operands around so the lane index operand is in the
6107 // right place.
6108 unsigned Spacing;
6109 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6112 Spacing));
6113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6114 Spacing * 2));
6115 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6116 Spacing * 3));
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(MCOperand::CreateReg(0)); // Rm
6121 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6123 Spacing));
6124 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6125 Spacing * 2));
6126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 Spacing * 3));
6128 TmpInst.addOperand(Inst.getOperand(1)); // lane
6129 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6130 TmpInst.addOperand(Inst.getOperand(5));
6131 Inst = TmpInst;
6132 return true;
6133 }
6134
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006135 case ARM::VLD1LNdAsm_8:
6136 case ARM::VLD1LNdAsm_16:
6137 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006138 MCInst TmpInst;
6139 // Shuffle the operands around so the lane index operand is in the
6140 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006141 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006142 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006143 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6144 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6145 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6146 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6147 TmpInst.addOperand(Inst.getOperand(1)); // lane
6148 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6149 TmpInst.addOperand(Inst.getOperand(5));
6150 Inst = TmpInst;
6151 return true;
6152 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006153
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006154 case ARM::VLD2LNdAsm_8:
6155 case ARM::VLD2LNdAsm_16:
6156 case ARM::VLD2LNdAsm_32:
6157 case ARM::VLD2LNqAsm_16:
6158 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006159 MCInst TmpInst;
6160 // Shuffle the operands around so the lane index operand is in the
6161 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006162 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006163 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006164 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6166 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006167 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6168 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6169 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006172 TmpInst.addOperand(Inst.getOperand(1)); // lane
6173 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6174 TmpInst.addOperand(Inst.getOperand(5));
6175 Inst = TmpInst;
6176 return true;
6177 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006178
6179 case ARM::VLD3LNdAsm_8:
6180 case ARM::VLD3LNdAsm_16:
6181 case ARM::VLD3LNdAsm_32:
6182 case ARM::VLD3LNqAsm_16:
6183 case ARM::VLD3LNqAsm_32: {
6184 MCInst TmpInst;
6185 // Shuffle the operands around so the lane index operand is in the
6186 // right place.
6187 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006188 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006189 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 Spacing));
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006193 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006194 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6195 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6196 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6198 Spacing));
6199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006200 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006201 TmpInst.addOperand(Inst.getOperand(1)); // lane
6202 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6203 TmpInst.addOperand(Inst.getOperand(5));
6204 Inst = TmpInst;
6205 return true;
6206 }
6207
Jim Grosbach14952a02012-01-24 18:37:25 +00006208 case ARM::VLD4LNdAsm_8:
6209 case ARM::VLD4LNdAsm_16:
6210 case ARM::VLD4LNdAsm_32:
6211 case ARM::VLD4LNqAsm_16:
6212 case ARM::VLD4LNqAsm_32: {
6213 MCInst TmpInst;
6214 // Shuffle the operands around so the lane index operand is in the
6215 // right place.
6216 unsigned Spacing;
6217 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6218 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6219 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6220 Spacing));
6221 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6222 Spacing * 2));
6223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6224 Spacing * 3));
6225 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6226 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6227 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6228 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6229 Spacing));
6230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6231 Spacing * 2));
6232 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6233 Spacing * 3));
6234 TmpInst.addOperand(Inst.getOperand(1)); // lane
6235 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6236 TmpInst.addOperand(Inst.getOperand(5));
6237 Inst = TmpInst;
6238 return true;
6239 }
6240
Jim Grosbachb78403c2012-01-24 23:47:04 +00006241 // VLD3DUP single 3-element structure to all lanes instructions.
6242 case ARM::VLD3DUPdAsm_8:
6243 case ARM::VLD3DUPdAsm_16:
6244 case ARM::VLD3DUPdAsm_32:
6245 case ARM::VLD3DUPqAsm_8:
6246 case ARM::VLD3DUPqAsm_16:
6247 case ARM::VLD3DUPqAsm_32: {
6248 MCInst TmpInst;
6249 unsigned Spacing;
6250 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6251 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 Spacing));
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 Spacing * 2));
6256 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6257 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6258 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6259 TmpInst.addOperand(Inst.getOperand(4));
6260 Inst = TmpInst;
6261 return true;
6262 }
6263
6264 case ARM::VLD3DUPdWB_fixed_Asm_8:
6265 case ARM::VLD3DUPdWB_fixed_Asm_16:
6266 case ARM::VLD3DUPdWB_fixed_Asm_32:
6267 case ARM::VLD3DUPqWB_fixed_Asm_8:
6268 case ARM::VLD3DUPqWB_fixed_Asm_16:
6269 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6270 MCInst TmpInst;
6271 unsigned Spacing;
6272 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6273 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 Spacing));
6276 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6277 Spacing * 2));
6278 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6279 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6280 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6281 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6282 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6283 TmpInst.addOperand(Inst.getOperand(4));
6284 Inst = TmpInst;
6285 return true;
6286 }
6287
6288 case ARM::VLD3DUPdWB_register_Asm_8:
6289 case ARM::VLD3DUPdWB_register_Asm_16:
6290 case ARM::VLD3DUPdWB_register_Asm_32:
6291 case ARM::VLD3DUPqWB_register_Asm_8:
6292 case ARM::VLD3DUPqWB_register_Asm_16:
6293 case ARM::VLD3DUPqWB_register_Asm_32: {
6294 MCInst TmpInst;
6295 unsigned Spacing;
6296 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6297 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing));
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 Spacing * 2));
6302 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6303 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6304 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6305 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6306 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6307 TmpInst.addOperand(Inst.getOperand(5));
6308 Inst = TmpInst;
6309 return true;
6310 }
6311
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006312 // VLD3 multiple 3-element structure instructions.
6313 case ARM::VLD3dAsm_8:
6314 case ARM::VLD3dAsm_16:
6315 case ARM::VLD3dAsm_32:
6316 case ARM::VLD3qAsm_8:
6317 case ARM::VLD3qAsm_16:
6318 case ARM::VLD3qAsm_32: {
6319 MCInst TmpInst;
6320 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006321 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006322 TmpInst.addOperand(Inst.getOperand(0)); // 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(Inst.getOperand(1)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6329 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6330 TmpInst.addOperand(Inst.getOperand(4));
6331 Inst = TmpInst;
6332 return true;
6333 }
6334
6335 case ARM::VLD3dWB_fixed_Asm_8:
6336 case ARM::VLD3dWB_fixed_Asm_16:
6337 case ARM::VLD3dWB_fixed_Asm_32:
6338 case ARM::VLD3qWB_fixed_Asm_8:
6339 case ARM::VLD3qWB_fixed_Asm_16:
6340 case ARM::VLD3qWB_fixed_Asm_32: {
6341 MCInst TmpInst;
6342 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006343 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 Spacing));
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing * 2));
6349 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6350 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6351 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6352 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6353 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6354 TmpInst.addOperand(Inst.getOperand(4));
6355 Inst = TmpInst;
6356 return true;
6357 }
6358
6359 case ARM::VLD3dWB_register_Asm_8:
6360 case ARM::VLD3dWB_register_Asm_16:
6361 case ARM::VLD3dWB_register_Asm_32:
6362 case ARM::VLD3qWB_register_Asm_8:
6363 case ARM::VLD3qWB_register_Asm_16:
6364 case ARM::VLD3qWB_register_Asm_32: {
6365 MCInst TmpInst;
6366 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006367 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006368 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6370 Spacing));
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 Spacing * 2));
6373 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6374 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6375 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6376 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6377 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6378 TmpInst.addOperand(Inst.getOperand(5));
6379 Inst = TmpInst;
6380 return true;
6381 }
6382
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006383 // VLD4DUP single 3-element structure to all lanes instructions.
6384 case ARM::VLD4DUPdAsm_8:
6385 case ARM::VLD4DUPdAsm_16:
6386 case ARM::VLD4DUPdAsm_32:
6387 case ARM::VLD4DUPqAsm_8:
6388 case ARM::VLD4DUPqAsm_16:
6389 case ARM::VLD4DUPqAsm_32: {
6390 MCInst TmpInst;
6391 unsigned Spacing;
6392 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6393 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6395 Spacing));
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6397 Spacing * 2));
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing * 3));
6400 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6401 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6402 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6403 TmpInst.addOperand(Inst.getOperand(4));
6404 Inst = TmpInst;
6405 return true;
6406 }
6407
6408 case ARM::VLD4DUPdWB_fixed_Asm_8:
6409 case ARM::VLD4DUPdWB_fixed_Asm_16:
6410 case ARM::VLD4DUPdWB_fixed_Asm_32:
6411 case ARM::VLD4DUPqWB_fixed_Asm_8:
6412 case ARM::VLD4DUPqWB_fixed_Asm_16:
6413 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6414 MCInst TmpInst;
6415 unsigned Spacing;
6416 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6417 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 Spacing));
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 Spacing * 2));
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 Spacing * 3));
6424 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6425 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6426 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6427 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6428 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6429 TmpInst.addOperand(Inst.getOperand(4));
6430 Inst = TmpInst;
6431 return true;
6432 }
6433
6434 case ARM::VLD4DUPdWB_register_Asm_8:
6435 case ARM::VLD4DUPdWB_register_Asm_16:
6436 case ARM::VLD4DUPdWB_register_Asm_32:
6437 case ARM::VLD4DUPqWB_register_Asm_8:
6438 case ARM::VLD4DUPqWB_register_Asm_16:
6439 case ARM::VLD4DUPqWB_register_Asm_32: {
6440 MCInst TmpInst;
6441 unsigned Spacing;
6442 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6443 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6445 Spacing));
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 Spacing * 2));
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 Spacing * 3));
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6452 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6453 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6454 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6455 TmpInst.addOperand(Inst.getOperand(5));
6456 Inst = TmpInst;
6457 return true;
6458 }
6459
6460 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006461 case ARM::VLD4dAsm_8:
6462 case ARM::VLD4dAsm_16:
6463 case ARM::VLD4dAsm_32:
6464 case ARM::VLD4qAsm_8:
6465 case ARM::VLD4qAsm_16:
6466 case ARM::VLD4qAsm_32: {
6467 MCInst TmpInst;
6468 unsigned Spacing;
6469 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6470 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 2));
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing * 3));
6477 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6478 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6479 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6480 TmpInst.addOperand(Inst.getOperand(4));
6481 Inst = TmpInst;
6482 return true;
6483 }
6484
6485 case ARM::VLD4dWB_fixed_Asm_8:
6486 case ARM::VLD4dWB_fixed_Asm_16:
6487 case ARM::VLD4dWB_fixed_Asm_32:
6488 case ARM::VLD4qWB_fixed_Asm_8:
6489 case ARM::VLD4qWB_fixed_Asm_16:
6490 case ARM::VLD4qWB_fixed_Asm_32: {
6491 MCInst TmpInst;
6492 unsigned Spacing;
6493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing));
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 Spacing * 2));
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 Spacing * 3));
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6502 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6503 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6504 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6505 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6506 TmpInst.addOperand(Inst.getOperand(4));
6507 Inst = TmpInst;
6508 return true;
6509 }
6510
6511 case ARM::VLD4dWB_register_Asm_8:
6512 case ARM::VLD4dWB_register_Asm_16:
6513 case ARM::VLD4dWB_register_Asm_32:
6514 case ARM::VLD4qWB_register_Asm_8:
6515 case ARM::VLD4qWB_register_Asm_16:
6516 case ARM::VLD4qWB_register_Asm_32: {
6517 MCInst TmpInst;
6518 unsigned Spacing;
6519 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6520 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 Spacing));
6523 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6524 Spacing * 2));
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 Spacing * 3));
6527 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6531 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6532 TmpInst.addOperand(Inst.getOperand(5));
6533 Inst = TmpInst;
6534 return true;
6535 }
6536
Jim Grosbach1a747242012-01-23 23:45:44 +00006537 // VST3 multiple 3-element structure instructions.
6538 case ARM::VST3dAsm_8:
6539 case ARM::VST3dAsm_16:
6540 case ARM::VST3dAsm_32:
6541 case ARM::VST3qAsm_8:
6542 case ARM::VST3qAsm_16:
6543 case ARM::VST3qAsm_32: {
6544 MCInst TmpInst;
6545 unsigned Spacing;
6546 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6547 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6548 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6549 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6551 Spacing));
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 Spacing * 2));
6554 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6555 TmpInst.addOperand(Inst.getOperand(4));
6556 Inst = TmpInst;
6557 return true;
6558 }
6559
6560 case ARM::VST3dWB_fixed_Asm_8:
6561 case ARM::VST3dWB_fixed_Asm_16:
6562 case ARM::VST3dWB_fixed_Asm_32:
6563 case ARM::VST3qWB_fixed_Asm_8:
6564 case ARM::VST3qWB_fixed_Asm_16:
6565 case ARM::VST3qWB_fixed_Asm_32: {
6566 MCInst TmpInst;
6567 unsigned Spacing;
6568 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6569 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6570 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6571 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6572 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6573 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 Spacing));
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing * 2));
6578 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(4));
6580 Inst = TmpInst;
6581 return true;
6582 }
6583
6584 case ARM::VST3dWB_register_Asm_8:
6585 case ARM::VST3dWB_register_Asm_16:
6586 case ARM::VST3dWB_register_Asm_32:
6587 case ARM::VST3qWB_register_Asm_8:
6588 case ARM::VST3qWB_register_Asm_16:
6589 case ARM::VST3qWB_register_Asm_32: {
6590 MCInst TmpInst;
6591 unsigned Spacing;
6592 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6593 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6594 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6595 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6596 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6597 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6598 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 Spacing));
6600 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 Spacing * 2));
6602 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6603 TmpInst.addOperand(Inst.getOperand(5));
6604 Inst = TmpInst;
6605 return true;
6606 }
6607
Jim Grosbachda70eac2012-01-24 00:58:13 +00006608 // VST4 multiple 3-element structure instructions.
6609 case ARM::VST4dAsm_8:
6610 case ARM::VST4dAsm_16:
6611 case ARM::VST4dAsm_32:
6612 case ARM::VST4qAsm_8:
6613 case ARM::VST4qAsm_16:
6614 case ARM::VST4qAsm_32: {
6615 MCInst TmpInst;
6616 unsigned Spacing;
6617 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6618 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6619 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6620 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing));
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing * 2));
6625 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6626 Spacing * 3));
6627 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6628 TmpInst.addOperand(Inst.getOperand(4));
6629 Inst = TmpInst;
6630 return true;
6631 }
6632
6633 case ARM::VST4dWB_fixed_Asm_8:
6634 case ARM::VST4dWB_fixed_Asm_16:
6635 case ARM::VST4dWB_fixed_Asm_32:
6636 case ARM::VST4qWB_fixed_Asm_8:
6637 case ARM::VST4qWB_fixed_Asm_16:
6638 case ARM::VST4qWB_fixed_Asm_32: {
6639 MCInst TmpInst;
6640 unsigned Spacing;
6641 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6642 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6644 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6645 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6646 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing));
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 Spacing * 2));
6651 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 Spacing * 3));
6653 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6654 TmpInst.addOperand(Inst.getOperand(4));
6655 Inst = TmpInst;
6656 return true;
6657 }
6658
6659 case ARM::VST4dWB_register_Asm_8:
6660 case ARM::VST4dWB_register_Asm_16:
6661 case ARM::VST4dWB_register_Asm_32:
6662 case ARM::VST4qWB_register_Asm_8:
6663 case ARM::VST4qWB_register_Asm_16:
6664 case ARM::VST4qWB_register_Asm_32: {
6665 MCInst TmpInst;
6666 unsigned Spacing;
6667 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6669 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6670 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6671 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6672 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6673 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6674 Spacing));
6675 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 Spacing * 2));
6677 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 Spacing * 3));
6679 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6680 TmpInst.addOperand(Inst.getOperand(5));
6681 Inst = TmpInst;
6682 return true;
6683 }
6684
Jim Grosbachad66de12012-04-11 00:15:16 +00006685 // Handle encoding choice for the shift-immediate instructions.
6686 case ARM::t2LSLri:
6687 case ARM::t2LSRri:
6688 case ARM::t2ASRri: {
6689 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6690 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6691 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6692 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6693 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6694 unsigned NewOpc;
6695 switch (Inst.getOpcode()) {
6696 default: llvm_unreachable("unexpected opcode");
6697 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6698 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6699 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6700 }
6701 // The Thumb1 operands aren't in the same order. Awesome, eh?
6702 MCInst TmpInst;
6703 TmpInst.setOpcode(NewOpc);
6704 TmpInst.addOperand(Inst.getOperand(0));
6705 TmpInst.addOperand(Inst.getOperand(5));
6706 TmpInst.addOperand(Inst.getOperand(1));
6707 TmpInst.addOperand(Inst.getOperand(2));
6708 TmpInst.addOperand(Inst.getOperand(3));
6709 TmpInst.addOperand(Inst.getOperand(4));
6710 Inst = TmpInst;
6711 return true;
6712 }
6713 return false;
6714 }
6715
Jim Grosbach485e5622011-12-13 22:45:11 +00006716 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006717 case ARM::t2MOVsr:
6718 case ARM::t2MOVSsr: {
6719 // Which instruction to expand to depends on the CCOut operand and
6720 // whether we're in an IT block if the register operands are low
6721 // registers.
6722 bool isNarrow = false;
6723 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6724 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6725 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6726 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6727 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6728 isNarrow = true;
6729 MCInst TmpInst;
6730 unsigned newOpc;
6731 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6732 default: llvm_unreachable("unexpected opcode!");
6733 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6734 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6735 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6736 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6737 }
6738 TmpInst.setOpcode(newOpc);
6739 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6740 if (isNarrow)
6741 TmpInst.addOperand(MCOperand::CreateReg(
6742 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6743 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6744 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6745 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6746 TmpInst.addOperand(Inst.getOperand(5));
6747 if (!isNarrow)
6748 TmpInst.addOperand(MCOperand::CreateReg(
6749 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6750 Inst = TmpInst;
6751 return true;
6752 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006753 case ARM::t2MOVsi:
6754 case ARM::t2MOVSsi: {
6755 // Which instruction to expand to depends on the CCOut operand and
6756 // whether we're in an IT block if the register operands are low
6757 // registers.
6758 bool isNarrow = false;
6759 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6760 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6761 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6762 isNarrow = true;
6763 MCInst TmpInst;
6764 unsigned newOpc;
6765 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6766 default: llvm_unreachable("unexpected opcode!");
6767 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6768 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6769 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6770 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006771 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006772 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006773 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6774 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006775 TmpInst.setOpcode(newOpc);
6776 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6777 if (isNarrow)
6778 TmpInst.addOperand(MCOperand::CreateReg(
6779 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6780 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006781 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006782 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006783 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6784 TmpInst.addOperand(Inst.getOperand(4));
6785 if (!isNarrow)
6786 TmpInst.addOperand(MCOperand::CreateReg(
6787 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6788 Inst = TmpInst;
6789 return true;
6790 }
6791 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006792 case ARM::ASRr:
6793 case ARM::LSRr:
6794 case ARM::LSLr:
6795 case ARM::RORr: {
6796 ARM_AM::ShiftOpc ShiftTy;
6797 switch(Inst.getOpcode()) {
6798 default: llvm_unreachable("unexpected opcode!");
6799 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6800 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6801 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6802 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6803 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006804 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6805 MCInst TmpInst;
6806 TmpInst.setOpcode(ARM::MOVsr);
6807 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6808 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6809 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6810 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6811 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6812 TmpInst.addOperand(Inst.getOperand(4));
6813 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6814 Inst = TmpInst;
6815 return true;
6816 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006817 case ARM::ASRi:
6818 case ARM::LSRi:
6819 case ARM::LSLi:
6820 case ARM::RORi: {
6821 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006822 switch(Inst.getOpcode()) {
6823 default: llvm_unreachable("unexpected opcode!");
6824 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6825 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6826 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6827 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6828 }
6829 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006830 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006831 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006832 // A shift by 32 should be encoded as 0 when permitted
6833 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6834 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006835 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006836 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006837 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006838 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6839 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006840 if (Opc == ARM::MOVsi)
6841 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006842 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6843 TmpInst.addOperand(Inst.getOperand(4));
6844 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6845 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006846 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006847 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006848 case ARM::RRXi: {
6849 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6850 MCInst TmpInst;
6851 TmpInst.setOpcode(ARM::MOVsi);
6852 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6853 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6854 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6855 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6856 TmpInst.addOperand(Inst.getOperand(3));
6857 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6858 Inst = TmpInst;
6859 return true;
6860 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006861 case ARM::t2LDMIA_UPD: {
6862 // If this is a load of a single register, then we should use
6863 // a post-indexed LDR instruction instead, per the ARM ARM.
6864 if (Inst.getNumOperands() != 5)
6865 return false;
6866 MCInst TmpInst;
6867 TmpInst.setOpcode(ARM::t2LDR_POST);
6868 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6869 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6870 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6871 TmpInst.addOperand(MCOperand::CreateImm(4));
6872 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6873 TmpInst.addOperand(Inst.getOperand(3));
6874 Inst = TmpInst;
6875 return true;
6876 }
6877 case ARM::t2STMDB_UPD: {
6878 // If this is a store of a single register, then we should use
6879 // a pre-indexed STR instruction instead, per the ARM ARM.
6880 if (Inst.getNumOperands() != 5)
6881 return false;
6882 MCInst TmpInst;
6883 TmpInst.setOpcode(ARM::t2STR_PRE);
6884 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6885 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6886 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6887 TmpInst.addOperand(MCOperand::CreateImm(-4));
6888 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6889 TmpInst.addOperand(Inst.getOperand(3));
6890 Inst = TmpInst;
6891 return true;
6892 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006893 case ARM::LDMIA_UPD:
6894 // If this is a load of a single register via a 'pop', then we should use
6895 // a post-indexed LDR instruction instead, per the ARM ARM.
6896 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6897 Inst.getNumOperands() == 5) {
6898 MCInst TmpInst;
6899 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6900 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6901 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6902 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6903 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6904 TmpInst.addOperand(MCOperand::CreateImm(4));
6905 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6906 TmpInst.addOperand(Inst.getOperand(3));
6907 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006908 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006909 }
6910 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00006911 case ARM::STMDB_UPD:
6912 // If this is a store of a single register via a 'push', then we should use
6913 // a pre-indexed STR instruction instead, per the ARM ARM.
6914 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6915 Inst.getNumOperands() == 5) {
6916 MCInst TmpInst;
6917 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6918 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6919 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6920 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6921 TmpInst.addOperand(MCOperand::CreateImm(-4));
6922 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6923 TmpInst.addOperand(Inst.getOperand(3));
6924 Inst = TmpInst;
6925 }
6926 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00006927 case ARM::t2ADDri12:
6928 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6929 // mnemonic was used (not "addw"), encoding T3 is preferred.
6930 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6931 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6932 break;
6933 Inst.setOpcode(ARM::t2ADDri);
6934 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6935 break;
6936 case ARM::t2SUBri12:
6937 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6938 // mnemonic was used (not "subw"), encoding T3 is preferred.
6939 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6940 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6941 break;
6942 Inst.setOpcode(ARM::t2SUBri);
6943 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6944 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00006945 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00006946 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00006947 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6948 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6949 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00006950 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00006951 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00006952 return true;
6953 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00006954 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00006955 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00006956 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00006957 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6958 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6959 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00006960 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00006961 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00006962 return true;
6963 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00006964 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00006965 case ARM::t2ADDri:
6966 case ARM::t2SUBri: {
6967 // If the destination and first source operand are the same, and
6968 // the flags are compatible with the current IT status, use encoding T2
6969 // instead of T3. For compatibility with the system 'as'. Make sure the
6970 // wide encoding wasn't explicit.
6971 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00006972 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00006973 (unsigned)Inst.getOperand(2).getImm() > 255 ||
6974 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
6975 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
6976 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6977 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6978 break;
6979 MCInst TmpInst;
6980 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
6981 ARM::tADDi8 : ARM::tSUBi8);
6982 TmpInst.addOperand(Inst.getOperand(0));
6983 TmpInst.addOperand(Inst.getOperand(5));
6984 TmpInst.addOperand(Inst.getOperand(0));
6985 TmpInst.addOperand(Inst.getOperand(2));
6986 TmpInst.addOperand(Inst.getOperand(3));
6987 TmpInst.addOperand(Inst.getOperand(4));
6988 Inst = TmpInst;
6989 return true;
6990 }
Jim Grosbache489bab2011-12-05 22:16:39 +00006991 case ARM::t2ADDrr: {
6992 // If the destination and first source operand are the same, and
6993 // there's no setting of the flags, use encoding T2 instead of T3.
6994 // Note that this is only for ADD, not SUB. This mirrors the system
6995 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6996 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6997 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00006998 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6999 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007000 break;
7001 MCInst TmpInst;
7002 TmpInst.setOpcode(ARM::tADDhirr);
7003 TmpInst.addOperand(Inst.getOperand(0));
7004 TmpInst.addOperand(Inst.getOperand(0));
7005 TmpInst.addOperand(Inst.getOperand(2));
7006 TmpInst.addOperand(Inst.getOperand(3));
7007 TmpInst.addOperand(Inst.getOperand(4));
7008 Inst = TmpInst;
7009 return true;
7010 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007011 case ARM::tADDrSP: {
7012 // If the non-SP source operand and the destination operand are not the
7013 // same, we need to use the 32-bit encoding if it's available.
7014 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7015 Inst.setOpcode(ARM::t2ADDrr);
7016 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7017 return true;
7018 }
7019 break;
7020 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007021 case ARM::tB:
7022 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007023 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007024 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007025 return true;
7026 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007027 break;
7028 case ARM::t2B:
7029 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007030 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007031 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007032 return true;
7033 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007034 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007035 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007036 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007037 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007038 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007039 return true;
7040 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007041 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007042 case ARM::tBcc:
7043 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007044 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007045 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007046 return true;
7047 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007048 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007049 case ARM::tLDMIA: {
7050 // If the register list contains any high registers, or if the writeback
7051 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7052 // instead if we're in Thumb2. Otherwise, this should have generated
7053 // an error in validateInstruction().
7054 unsigned Rn = Inst.getOperand(0).getReg();
7055 bool hasWritebackToken =
7056 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7057 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7058 bool listContainsBase;
7059 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7060 (!listContainsBase && !hasWritebackToken) ||
7061 (listContainsBase && hasWritebackToken)) {
7062 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7063 assert (isThumbTwo());
7064 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7065 // If we're switching to the updating version, we need to insert
7066 // the writeback tied operand.
7067 if (hasWritebackToken)
7068 Inst.insert(Inst.begin(),
7069 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007070 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007071 }
7072 break;
7073 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007074 case ARM::tSTMIA_UPD: {
7075 // If the register list contains any high registers, we need to use
7076 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7077 // should have generated an error in validateInstruction().
7078 unsigned Rn = Inst.getOperand(0).getReg();
7079 bool listContainsBase;
7080 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7081 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7082 assert (isThumbTwo());
7083 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007084 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007085 }
7086 break;
7087 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007088 case ARM::tPOP: {
7089 bool listContainsBase;
7090 // If the register list contains any high registers, we need to use
7091 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7092 // should have generated an error in validateInstruction().
7093 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007094 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007095 assert (isThumbTwo());
7096 Inst.setOpcode(ARM::t2LDMIA_UPD);
7097 // Add the base register and writeback operands.
7098 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7099 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007100 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007101 }
7102 case ARM::tPUSH: {
7103 bool listContainsBase;
7104 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007105 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007106 assert (isThumbTwo());
7107 Inst.setOpcode(ARM::t2STMDB_UPD);
7108 // Add the base register and writeback operands.
7109 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7110 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007111 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007112 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007113 case ARM::t2MOVi: {
7114 // If we can use the 16-bit encoding and the user didn't explicitly
7115 // request the 32-bit variant, transform it here.
7116 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007117 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007118 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7119 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7120 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007121 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7122 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7123 // The operands aren't in the same order for tMOVi8...
7124 MCInst TmpInst;
7125 TmpInst.setOpcode(ARM::tMOVi8);
7126 TmpInst.addOperand(Inst.getOperand(0));
7127 TmpInst.addOperand(Inst.getOperand(4));
7128 TmpInst.addOperand(Inst.getOperand(1));
7129 TmpInst.addOperand(Inst.getOperand(2));
7130 TmpInst.addOperand(Inst.getOperand(3));
7131 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007132 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007133 }
7134 break;
7135 }
7136 case ARM::t2MOVr: {
7137 // If we can use the 16-bit encoding and the user didn't explicitly
7138 // request the 32-bit variant, transform it here.
7139 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7140 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7141 Inst.getOperand(2).getImm() == ARMCC::AL &&
7142 Inst.getOperand(4).getReg() == ARM::CPSR &&
7143 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7144 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7145 // The operands aren't the same for tMOV[S]r... (no cc_out)
7146 MCInst TmpInst;
7147 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7148 TmpInst.addOperand(Inst.getOperand(0));
7149 TmpInst.addOperand(Inst.getOperand(1));
7150 TmpInst.addOperand(Inst.getOperand(2));
7151 TmpInst.addOperand(Inst.getOperand(3));
7152 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007153 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007154 }
7155 break;
7156 }
Jim Grosbach82213192011-09-19 20:29:33 +00007157 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007158 case ARM::t2SXTB:
7159 case ARM::t2UXTH:
7160 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007161 // If we can use the 16-bit encoding and the user didn't explicitly
7162 // request the 32-bit variant, transform it here.
7163 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7164 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7165 Inst.getOperand(2).getImm() == 0 &&
7166 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7167 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007168 unsigned NewOpc;
7169 switch (Inst.getOpcode()) {
7170 default: llvm_unreachable("Illegal opcode!");
7171 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7172 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7173 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7174 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7175 }
Jim Grosbach82213192011-09-19 20:29:33 +00007176 // The operands aren't the same for thumb1 (no rotate operand).
7177 MCInst TmpInst;
7178 TmpInst.setOpcode(NewOpc);
7179 TmpInst.addOperand(Inst.getOperand(0));
7180 TmpInst.addOperand(Inst.getOperand(1));
7181 TmpInst.addOperand(Inst.getOperand(3));
7182 TmpInst.addOperand(Inst.getOperand(4));
7183 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007184 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007185 }
7186 break;
7187 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007188 case ARM::MOVsi: {
7189 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007190 // rrx shifts and asr/lsr of #32 is encoded as 0
7191 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7192 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007193 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7194 // Shifting by zero is accepted as a vanilla 'MOVr'
7195 MCInst TmpInst;
7196 TmpInst.setOpcode(ARM::MOVr);
7197 TmpInst.addOperand(Inst.getOperand(0));
7198 TmpInst.addOperand(Inst.getOperand(1));
7199 TmpInst.addOperand(Inst.getOperand(3));
7200 TmpInst.addOperand(Inst.getOperand(4));
7201 TmpInst.addOperand(Inst.getOperand(5));
7202 Inst = TmpInst;
7203 return true;
7204 }
7205 return false;
7206 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007207 case ARM::ANDrsi:
7208 case ARM::ORRrsi:
7209 case ARM::EORrsi:
7210 case ARM::BICrsi:
7211 case ARM::SUBrsi:
7212 case ARM::ADDrsi: {
7213 unsigned newOpc;
7214 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7215 if (SOpc == ARM_AM::rrx) return false;
7216 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007217 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007218 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7219 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7220 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7221 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7222 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7223 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7224 }
7225 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007226 // The exception is for right shifts, where 0 == 32
7227 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7228 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007229 MCInst TmpInst;
7230 TmpInst.setOpcode(newOpc);
7231 TmpInst.addOperand(Inst.getOperand(0));
7232 TmpInst.addOperand(Inst.getOperand(1));
7233 TmpInst.addOperand(Inst.getOperand(2));
7234 TmpInst.addOperand(Inst.getOperand(4));
7235 TmpInst.addOperand(Inst.getOperand(5));
7236 TmpInst.addOperand(Inst.getOperand(6));
7237 Inst = TmpInst;
7238 return true;
7239 }
7240 return false;
7241 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007242 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007243 case ARM::t2IT: {
7244 // The mask bits for all but the first condition are represented as
7245 // the low bit of the condition code value implies 't'. We currently
7246 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007247 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007248 MCOperand &MO = Inst.getOperand(1);
7249 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007250 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007251 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007252 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007253 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007254 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007255 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007256 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007257
7258 // Set up the IT block state according to the IT instruction we just
7259 // matched.
7260 assert(!inITBlock() && "nested IT blocks?!");
7261 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7262 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7263 ITState.CurPosition = 0;
7264 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007265 break;
7266 }
Richard Bartona39625e2012-07-09 16:12:24 +00007267 case ARM::t2LSLrr:
7268 case ARM::t2LSRrr:
7269 case ARM::t2ASRrr:
7270 case ARM::t2SBCrr:
7271 case ARM::t2RORrr:
7272 case ARM::t2BICrr:
7273 {
Richard Bartond5660372012-07-09 16:14:28 +00007274 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007275 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7276 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7277 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007278 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7279 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007280 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7281 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7282 unsigned NewOpc;
7283 switch (Inst.getOpcode()) {
7284 default: llvm_unreachable("unexpected opcode");
7285 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7286 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7287 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7288 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7289 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7290 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7291 }
7292 MCInst TmpInst;
7293 TmpInst.setOpcode(NewOpc);
7294 TmpInst.addOperand(Inst.getOperand(0));
7295 TmpInst.addOperand(Inst.getOperand(5));
7296 TmpInst.addOperand(Inst.getOperand(1));
7297 TmpInst.addOperand(Inst.getOperand(2));
7298 TmpInst.addOperand(Inst.getOperand(3));
7299 TmpInst.addOperand(Inst.getOperand(4));
7300 Inst = TmpInst;
7301 return true;
7302 }
7303 return false;
7304 }
7305 case ARM::t2ANDrr:
7306 case ARM::t2EORrr:
7307 case ARM::t2ADCrr:
7308 case ARM::t2ORRrr:
7309 {
Richard Bartond5660372012-07-09 16:14:28 +00007310 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007311 // These instructions are special in that they are commutable, so shorter encodings
7312 // are available more often.
7313 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7314 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7315 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7316 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007317 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7318 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007319 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7320 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7321 unsigned NewOpc;
7322 switch (Inst.getOpcode()) {
7323 default: llvm_unreachable("unexpected opcode");
7324 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7325 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7326 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7327 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7328 }
7329 MCInst TmpInst;
7330 TmpInst.setOpcode(NewOpc);
7331 TmpInst.addOperand(Inst.getOperand(0));
7332 TmpInst.addOperand(Inst.getOperand(5));
7333 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7334 TmpInst.addOperand(Inst.getOperand(1));
7335 TmpInst.addOperand(Inst.getOperand(2));
7336 } else {
7337 TmpInst.addOperand(Inst.getOperand(2));
7338 TmpInst.addOperand(Inst.getOperand(1));
7339 }
7340 TmpInst.addOperand(Inst.getOperand(3));
7341 TmpInst.addOperand(Inst.getOperand(4));
7342 Inst = TmpInst;
7343 return true;
7344 }
7345 return false;
7346 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007347 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007348 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007349}
7350
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007351unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7352 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7353 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007354 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007355 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007356 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7357 assert(MCID.hasOptionalDef() &&
7358 "optionally flag setting instruction missing optional def operand");
7359 assert(MCID.NumOperands == Inst.getNumOperands() &&
7360 "operand count mismatch!");
7361 // Find the optional-def operand (cc_out).
7362 unsigned OpNo;
7363 for (OpNo = 0;
7364 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7365 ++OpNo)
7366 ;
7367 // If we're parsing Thumb1, reject it completely.
7368 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7369 return Match_MnemonicFail;
7370 // If we're parsing Thumb2, which form is legal depends on whether we're
7371 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007372 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7373 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007374 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007375 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7376 inITBlock())
7377 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007378 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007379 // Some high-register supporting Thumb1 encodings only allow both registers
7380 // to be from r0-r7 when in Thumb2.
7381 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7382 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7383 isARMLowRegister(Inst.getOperand(2).getReg()))
7384 return Match_RequiresThumb2;
7385 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007386 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007387 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7388 isARMLowRegister(Inst.getOperand(1).getReg()))
7389 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007390 return Match_Success;
7391}
7392
Jim Grosbach5117ef72012-04-24 22:40:08 +00007393static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007394bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007395MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007396 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007397 MCStreamer &Out, unsigned &ErrorInfo,
7398 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007399 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007400 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007401
Chad Rosier2f480a82012-10-12 22:53:36 +00007402 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007403 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007404 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007405 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007406 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007407 // Context sensitive operand constraints aren't handled by the matcher,
7408 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007409 if (validateInstruction(Inst, Operands)) {
7410 // Still progress the IT block, otherwise one wrong condition causes
7411 // nasty cascading errors.
7412 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007413 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007414 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007415
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007416 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007417 // encoding is selected. Loop on it while changes happen so the
7418 // individual transformations can chain off each other. E.g.,
7419 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7420 while (processInstruction(Inst, Operands))
7421 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007422
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007423 // Only move forward at the very end so that everything in validate
7424 // and process gets a consistent answer about whether we're in an IT
7425 // block.
7426 forwardITPosition();
7427
Jim Grosbach82f76d12012-01-25 19:52:01 +00007428 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7429 // doesn't actually encode.
7430 if (Inst.getOpcode() == ARM::ITasm)
7431 return false;
7432
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007433 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007434 Out.EmitInstruction(Inst);
7435 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007436 case Match_MissingFeature: {
7437 assert(ErrorInfo && "Unknown missing feature!");
7438 // Special case the error message for the very common case where only
7439 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7440 std::string Msg = "instruction requires:";
7441 unsigned Mask = 1;
7442 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7443 if (ErrorInfo & Mask) {
7444 Msg += " ";
7445 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7446 }
7447 Mask <<= 1;
7448 }
7449 return Error(IDLoc, Msg);
7450 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007451 case Match_InvalidOperand: {
7452 SMLoc ErrorLoc = IDLoc;
7453 if (ErrorInfo != ~0U) {
7454 if (ErrorInfo >= Operands.size())
7455 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007456
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007457 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7458 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7459 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007460
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007461 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007462 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007463 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007464 return Error(IDLoc, "invalid instruction",
7465 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007466 case Match_RequiresNotITBlock:
7467 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007468 case Match_RequiresITBlock:
7469 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007470 case Match_RequiresV6:
7471 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7472 case Match_RequiresThumb2:
7473 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007474 case Match_ImmRange0_4: {
7475 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7476 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7477 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7478 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007479 case Match_ImmRange0_15: {
7480 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7481 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7482 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7483 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007484 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007485
Eric Christopher91d7b902010-10-29 09:26:59 +00007486 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007487}
7488
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007489/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007490bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7491 StringRef IDVal = DirectiveID.getIdentifier();
7492 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007493 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007494 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007495 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007496 else if (IDVal == ".arm")
7497 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007498 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007499 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007500 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007501 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007502 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007503 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007504 else if (IDVal == ".unreq")
7505 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007506 else if (IDVal == ".arch")
7507 return parseDirectiveArch(DirectiveID.getLoc());
7508 else if (IDVal == ".eabi_attribute")
7509 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007510 else if (IDVal == ".fnstart")
7511 return parseDirectiveFnStart(DirectiveID.getLoc());
7512 else if (IDVal == ".fnend")
7513 return parseDirectiveFnEnd(DirectiveID.getLoc());
7514 else if (IDVal == ".cantunwind")
7515 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7516 else if (IDVal == ".personality")
7517 return parseDirectivePersonality(DirectiveID.getLoc());
7518 else if (IDVal == ".handlerdata")
7519 return parseDirectiveHandlerData(DirectiveID.getLoc());
7520 else if (IDVal == ".setfp")
7521 return parseDirectiveSetFP(DirectiveID.getLoc());
7522 else if (IDVal == ".pad")
7523 return parseDirectivePad(DirectiveID.getLoc());
7524 else if (IDVal == ".save")
7525 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7526 else if (IDVal == ".vsave")
7527 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007528 return true;
7529}
7530
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007531/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007532/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007533bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007534 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7535 for (;;) {
7536 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007537 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007538 return true;
7539
Eric Christopherbf7bc492013-01-09 03:52:05 +00007540 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007541
7542 if (getLexer().is(AsmToken::EndOfStatement))
7543 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007544
Kevin Enderbyccab3172009-09-15 00:27:25 +00007545 // FIXME: Improve diagnostic.
7546 if (getLexer().isNot(AsmToken::Comma))
7547 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007548 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007549 }
7550 }
7551
Sean Callanana83fd7d2010-01-19 20:27:46 +00007552 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007553 return false;
7554}
7555
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007556/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007557/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007558bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007559 if (getLexer().isNot(AsmToken::EndOfStatement))
7560 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007561 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007562
Tim Northovera2292d02013-06-10 23:20:58 +00007563 if (!hasThumb())
7564 return Error(L, "target does not support Thumb mode");
7565
Jim Grosbach7f882392011-12-07 18:04:19 +00007566 if (!isThumb())
7567 SwitchMode();
7568 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7569 return false;
7570}
7571
7572/// parseDirectiveARM
7573/// ::= .arm
7574bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7575 if (getLexer().isNot(AsmToken::EndOfStatement))
7576 return Error(L, "unexpected token in directive");
7577 Parser.Lex();
7578
Tim Northovera2292d02013-06-10 23:20:58 +00007579 if (!hasARM())
7580 return Error(L, "target does not support ARM mode");
7581
Jim Grosbach7f882392011-12-07 18:04:19 +00007582 if (isThumb())
7583 SwitchMode();
7584 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007585 return false;
7586}
7587
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007588/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007589/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007590bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007591 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7592 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007593 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007594 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007595
Jim Grosbach1152cc02011-12-21 22:30:16 +00007596 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007597 // ELF doesn't
7598 if (isMachO) {
7599 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007600 if (Tok.isNot(AsmToken::EndOfStatement)) {
7601 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7602 return Error(L, "unexpected token in .thumb_func directive");
7603 Name = Tok.getIdentifier();
7604 Parser.Lex(); // Consume the identifier token.
7605 needFuncName = false;
7606 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007607 }
7608
Jim Grosbach1152cc02011-12-21 22:30:16 +00007609 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007610 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007611
7612 // Eat the end of statement and any blank lines that follow.
7613 while (getLexer().is(AsmToken::EndOfStatement))
7614 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007615
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007616 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007617 // We really should be checking the next symbol definition even if there's
7618 // stuff in between.
7619 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007620 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007621 }
7622
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007623 // Mark symbol as a thumb symbol.
7624 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7625 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007626 return false;
7627}
7628
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007629/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007630/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007631bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007632 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007633 if (Tok.isNot(AsmToken::Identifier))
7634 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007635 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007636 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007637 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007638 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007639 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007640 else
7641 return Error(L, "unrecognized syntax mode in .syntax directive");
7642
7643 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007644 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007645 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007646
7647 // TODO tell the MC streamer the mode
7648 // getParser().getStreamer().Emit???();
7649 return false;
7650}
7651
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007652/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007653/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007654bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007655 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007656 if (Tok.isNot(AsmToken::Integer))
7657 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007658 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007659 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007660 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007661 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007662 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007663 else
7664 return Error(L, "invalid operand to .code directive");
7665
7666 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007667 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007668 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007669
Evan Cheng284b4672011-07-08 22:36:29 +00007670 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007671 if (!hasThumb())
7672 return Error(L, "target does not support Thumb mode");
7673
Jim Grosbachf471ac32011-09-06 18:46:23 +00007674 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007675 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007676 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007677 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007678 if (!hasARM())
7679 return Error(L, "target does not support ARM mode");
7680
Jim Grosbachf471ac32011-09-06 18:46:23 +00007681 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007682 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007683 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007684 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007685
Kevin Enderby146dcf22009-10-15 20:48:48 +00007686 return false;
7687}
7688
Jim Grosbachab5830e2011-12-14 02:16:11 +00007689/// parseDirectiveReq
7690/// ::= name .req registername
7691bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7692 Parser.Lex(); // Eat the '.req' token.
7693 unsigned Reg;
7694 SMLoc SRegLoc, ERegLoc;
7695 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007696 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007697 return Error(SRegLoc, "register name expected");
7698 }
7699
7700 // Shouldn't be anything else.
7701 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007702 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007703 return Error(Parser.getTok().getLoc(),
7704 "unexpected input in .req directive.");
7705 }
7706
7707 Parser.Lex(); // Consume the EndOfStatement
7708
7709 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7710 return Error(SRegLoc, "redefinition of '" + Name +
7711 "' does not match original.");
7712
7713 return false;
7714}
7715
7716/// parseDirectiveUneq
7717/// ::= .unreq registername
7718bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7719 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007720 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007721 return Error(L, "unexpected input in .unreq directive.");
7722 }
7723 RegisterReqs.erase(Parser.getTok().getIdentifier());
7724 Parser.Lex(); // Eat the identifier.
7725 return false;
7726}
7727
Jason W Kim135d2442011-12-20 17:38:12 +00007728/// parseDirectiveArch
7729/// ::= .arch token
7730bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7731 return true;
7732}
7733
7734/// parseDirectiveEabiAttr
7735/// ::= .eabi_attribute int, int
7736bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7737 return true;
7738}
7739
Logan Chien4ea23b52013-05-10 16:17:24 +00007740/// parseDirectiveFnStart
7741/// ::= .fnstart
7742bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7743 if (FnStartLoc.isValid()) {
7744 Error(L, ".fnstart starts before the end of previous one");
7745 Error(FnStartLoc, "previous .fnstart starts here");
7746 return true;
7747 }
7748
7749 FnStartLoc = L;
7750 getParser().getStreamer().EmitFnStart();
7751 return false;
7752}
7753
7754/// parseDirectiveFnEnd
7755/// ::= .fnend
7756bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7757 // Check the ordering of unwind directives
7758 if (!FnStartLoc.isValid())
7759 return Error(L, ".fnstart must precede .fnend directive");
7760
7761 // Reset the unwind directives parser state
7762 resetUnwindDirectiveParserState();
7763
7764 getParser().getStreamer().EmitFnEnd();
7765 return false;
7766}
7767
7768/// parseDirectiveCantUnwind
7769/// ::= .cantunwind
7770bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7771 // Check the ordering of unwind directives
7772 CantUnwindLoc = L;
7773 if (!FnStartLoc.isValid())
7774 return Error(L, ".fnstart must precede .cantunwind directive");
7775 if (HandlerDataLoc.isValid()) {
7776 Error(L, ".cantunwind can't be used with .handlerdata directive");
7777 Error(HandlerDataLoc, ".handlerdata was specified here");
7778 return true;
7779 }
7780 if (PersonalityLoc.isValid()) {
7781 Error(L, ".cantunwind can't be used with .personality directive");
7782 Error(PersonalityLoc, ".personality was specified here");
7783 return true;
7784 }
7785
7786 getParser().getStreamer().EmitCantUnwind();
7787 return false;
7788}
7789
7790/// parseDirectivePersonality
7791/// ::= .personality name
7792bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7793 // Check the ordering of unwind directives
7794 PersonalityLoc = L;
7795 if (!FnStartLoc.isValid())
7796 return Error(L, ".fnstart must precede .personality directive");
7797 if (CantUnwindLoc.isValid()) {
7798 Error(L, ".personality can't be used with .cantunwind directive");
7799 Error(CantUnwindLoc, ".cantunwind was specified here");
7800 return true;
7801 }
7802 if (HandlerDataLoc.isValid()) {
7803 Error(L, ".personality must precede .handlerdata directive");
7804 Error(HandlerDataLoc, ".handlerdata was specified here");
7805 return true;
7806 }
7807
7808 // Parse the name of the personality routine
7809 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7810 Parser.eatToEndOfStatement();
7811 return Error(L, "unexpected input in .personality directive.");
7812 }
7813 StringRef Name(Parser.getTok().getIdentifier());
7814 Parser.Lex();
7815
7816 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7817 getParser().getStreamer().EmitPersonality(PR);
7818 return false;
7819}
7820
7821/// parseDirectiveHandlerData
7822/// ::= .handlerdata
7823bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7824 // Check the ordering of unwind directives
7825 HandlerDataLoc = L;
7826 if (!FnStartLoc.isValid())
7827 return Error(L, ".fnstart must precede .personality directive");
7828 if (CantUnwindLoc.isValid()) {
7829 Error(L, ".handlerdata can't be used with .cantunwind directive");
7830 Error(CantUnwindLoc, ".cantunwind was specified here");
7831 return true;
7832 }
7833
7834 getParser().getStreamer().EmitHandlerData();
7835 return false;
7836}
7837
7838/// parseDirectiveSetFP
7839/// ::= .setfp fpreg, spreg [, offset]
7840bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
7841 // Check the ordering of unwind directives
7842 if (!FnStartLoc.isValid())
7843 return Error(L, ".fnstart must precede .setfp directive");
7844 if (HandlerDataLoc.isValid())
7845 return Error(L, ".setfp must precede .handlerdata directive");
7846
7847 // Parse fpreg
7848 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
7849 int NewFPReg = tryParseRegister();
7850 if (NewFPReg == -1)
7851 return Error(NewFPRegLoc, "frame pointer register expected");
7852
7853 // Consume comma
7854 if (!Parser.getTok().is(AsmToken::Comma))
7855 return Error(Parser.getTok().getLoc(), "comma expected");
7856 Parser.Lex(); // skip comma
7857
7858 // Parse spreg
7859 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
7860 int NewSPReg = tryParseRegister();
7861 if (NewSPReg == -1)
7862 return Error(NewSPRegLoc, "stack pointer register expected");
7863
7864 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
7865 return Error(NewSPRegLoc,
7866 "register should be either $sp or the latest fp register");
7867
7868 // Update the frame pointer register
7869 FPReg = NewFPReg;
7870
7871 // Parse offset
7872 int64_t Offset = 0;
7873 if (Parser.getTok().is(AsmToken::Comma)) {
7874 Parser.Lex(); // skip comma
7875
7876 if (Parser.getTok().isNot(AsmToken::Hash) &&
7877 Parser.getTok().isNot(AsmToken::Dollar)) {
7878 return Error(Parser.getTok().getLoc(), "'#' expected");
7879 }
7880 Parser.Lex(); // skip hash token.
7881
7882 const MCExpr *OffsetExpr;
7883 SMLoc ExLoc = Parser.getTok().getLoc();
7884 SMLoc EndLoc;
7885 if (getParser().parseExpression(OffsetExpr, EndLoc))
7886 return Error(ExLoc, "malformed setfp offset");
7887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7888 if (!CE)
7889 return Error(ExLoc, "setfp offset must be an immediate");
7890
7891 Offset = CE->getValue();
7892 }
7893
7894 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
7895 static_cast<unsigned>(NewSPReg),
7896 Offset);
7897 return false;
7898}
7899
7900/// parseDirective
7901/// ::= .pad offset
7902bool ARMAsmParser::parseDirectivePad(SMLoc L) {
7903 // Check the ordering of unwind directives
7904 if (!FnStartLoc.isValid())
7905 return Error(L, ".fnstart must precede .pad directive");
7906 if (HandlerDataLoc.isValid())
7907 return Error(L, ".pad must precede .handlerdata directive");
7908
7909 // Parse the offset
7910 if (Parser.getTok().isNot(AsmToken::Hash) &&
7911 Parser.getTok().isNot(AsmToken::Dollar)) {
7912 return Error(Parser.getTok().getLoc(), "'#' expected");
7913 }
7914 Parser.Lex(); // skip hash token.
7915
7916 const MCExpr *OffsetExpr;
7917 SMLoc ExLoc = Parser.getTok().getLoc();
7918 SMLoc EndLoc;
7919 if (getParser().parseExpression(OffsetExpr, EndLoc))
7920 return Error(ExLoc, "malformed pad offset");
7921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7922 if (!CE)
7923 return Error(ExLoc, "pad offset must be an immediate");
7924
7925 getParser().getStreamer().EmitPad(CE->getValue());
7926 return false;
7927}
7928
7929/// parseDirectiveRegSave
7930/// ::= .save { registers }
7931/// ::= .vsave { registers }
7932bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
7933 // Check the ordering of unwind directives
7934 if (!FnStartLoc.isValid())
7935 return Error(L, ".fnstart must precede .save or .vsave directives");
7936 if (HandlerDataLoc.isValid())
7937 return Error(L, ".save or .vsave must precede .handlerdata directive");
7938
7939 // Parse the register list
7940 SmallVector<MCParsedAsmOperand*, 1> Operands;
7941 if (parseRegisterList(Operands))
7942 return true;
7943 ARMOperand *Op = (ARMOperand*)Operands[0];
7944 if (!IsVector && !Op->isRegList())
7945 return Error(L, ".save expects GPR registers");
7946 if (IsVector && !Op->isDPRRegList())
7947 return Error(L, ".vsave expects DPR registers");
7948
7949 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
7950 return false;
7951}
7952
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007953/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007954extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007955 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7956 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007957}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007958
Chris Lattner3e4582a2010-09-06 19:11:01 +00007959#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00007960#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00007961#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007962#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00007963
7964// Define this matcher function after the auto-generated include so we
7965// have the match class enum definitions.
7966unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
7967 unsigned Kind) {
7968 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
7969 // If the kind is a token for a literal immediate, check if our asm
7970 // operand matches. This is for InstAliases which have a fixed-value
7971 // immediate in the syntax.
7972 if (Kind == MCK__35_0 && Op->isImm()) {
7973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
7974 if (!CE)
7975 return Match_InvalidOperand;
7976 if (CE->getValue() == 0)
7977 return Match_Success;
7978 }
7979 return Match_InvalidOperand;
7980}