blob: 1e090d97dadb37102e5c6503ffe68f5862239a00 [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
Amara Emerson52cfb6a2013-10-03 09:31:51 +000010#include "ARMFeatures.h"
Evan Cheng11424442011-07-26 00:24:13 +000011#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "MCTargetDesc/ARMAddressingModes.h"
13#include "MCTargetDesc/ARMBaseInfo.h"
14#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000015#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000016#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000017#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000018#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000019#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000020#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000022#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000024#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000025#include "llvm/MC/MCExpr.h"
26#include "llvm/MC/MCInst.h"
27#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000028#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/MC/MCParser/MCAsmLexer.h"
30#include "llvm/MC/MCParser/MCAsmParser.h"
31#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
32#include "llvm/MC/MCRegisterInfo.h"
33#include "llvm/MC/MCStreamer.h"
34#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000035#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Support/MathExtras.h"
37#include "llvm/Support/SourceMgr.h"
38#include "llvm/Support/TargetRegistry.h"
39#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000040
Kevin Enderbyccab3172009-09-15 00:27:25 +000041using namespace llvm;
42
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000043namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000044
45class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000046
Jim Grosbach04945c42011-12-02 00:35:16 +000047enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000048
Evan Cheng11424442011-07-26 00:24:13 +000049class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000050 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +000052 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000053 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000054
Logan Chien4ea23b52013-05-10 16:17:24 +000055 // Unwind directives state
56 SMLoc FnStartLoc;
57 SMLoc CantUnwindLoc;
58 SMLoc PersonalityLoc;
59 SMLoc HandlerDataLoc;
60 int FPReg;
61 void resetUnwindDirectiveParserState() {
62 FnStartLoc = SMLoc();
63 CantUnwindLoc = SMLoc();
64 PersonalityLoc = SMLoc();
65 HandlerDataLoc = SMLoc();
66 FPReg = -1;
67 }
68
Jim Grosbachab5830e2011-12-14 02:16:11 +000069 // Map of register aliases registers via the .req directive.
70 StringMap<unsigned> RegisterReqs;
71
Jim Grosbached16ec42011-08-29 22:24:09 +000072 struct {
73 ARMCC::CondCodes Cond; // Condition for IT block.
74 unsigned Mask:4; // Condition mask for instructions.
75 // Starting at first 1 (from lsb).
76 // '1' condition as indicated in IT.
77 // '0' inverse of condition (else).
78 // Count of instructions in IT block is
79 // 4 - trailingzeroes(mask)
80
81 bool FirstCond; // Explicit flag for when we're parsing the
82 // First instruction in the IT block. It's
83 // implied in the mask, so needs special
84 // handling.
85
86 unsigned CurPosition; // Current position in parsing of IT
87 // block. In range [0,3]. Initialized
88 // according to count of instructions in block.
89 // ~0U if no active IT block.
90 } ITState;
91 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000092 void forwardITPosition() {
93 if (!inITBlock()) return;
94 // Move to the next instruction in the IT block, if there is one. If not,
95 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000096 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000097 if (++ITState.CurPosition == 5 - TZ)
98 ITState.CurPosition = ~0U; // Done with the IT block after this.
99 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000100
101
Kevin Enderbyccab3172009-09-15 00:27:25 +0000102 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000103 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
104
Benjamin Kramer673824b2012-04-15 17:04:27 +0000105 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000106 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000107 return Parser.Warning(L, Msg, Ranges);
108 }
109 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000110 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000111 return Parser.Error(L, Msg, Ranges);
112 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000113
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 int tryParseRegister();
115 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000116 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000117 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000119 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
120 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000121 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
122 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveWord(unsigned Size, SMLoc L);
124 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000125 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000126 bool parseDirectiveThumbFunc(SMLoc L);
127 bool parseDirectiveCode(SMLoc L);
128 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000129 bool parseDirectiveReq(StringRef Name, SMLoc L);
130 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000131 bool parseDirectiveArch(SMLoc L);
132 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000133 bool parseDirectiveFnStart(SMLoc L);
134 bool parseDirectiveFnEnd(SMLoc L);
135 bool parseDirectiveCantUnwind(SMLoc L);
136 bool parseDirectivePersonality(SMLoc L);
137 bool parseDirectiveHandlerData(SMLoc L);
138 bool parseDirectiveSetFP(SMLoc L);
139 bool parseDirectivePad(SMLoc L);
140 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000141
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000143 bool &CarrySetting, unsigned &ProcessorIMod,
144 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000145 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
146 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000147 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000148
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumb() const {
150 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000151 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000152 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000153 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000154 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000155 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000156 bool isThumbTwo() const {
157 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
158 }
Tim Northovera2292d02013-06-10 23:20:58 +0000159 bool hasThumb() const {
160 return STI.getFeatureBits() & ARM::HasV4TOps;
161 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000162 bool hasV6Ops() const {
163 return STI.getFeatureBits() & ARM::HasV6Ops;
164 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000165 bool hasV6MOps() const {
166 return STI.getFeatureBits() & ARM::HasV6MOps;
167 }
James Molloy21efa7d2011-09-28 14:21:38 +0000168 bool hasV7Ops() const {
169 return STI.getFeatureBits() & ARM::HasV7Ops;
170 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000171 bool hasV8Ops() const {
172 return STI.getFeatureBits() & ARM::HasV8Ops;
173 }
Tim Northovera2292d02013-06-10 23:20:58 +0000174 bool hasARM() const {
175 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
176 }
177
Evan Cheng284b4672011-07-08 22:36:29 +0000178 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000179 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
180 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000181 }
James Molloy21efa7d2011-09-28 14:21:38 +0000182 bool isMClass() const {
183 return STI.getFeatureBits() & ARM::FeatureMClass;
184 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000185
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000186 /// @name Auto-generated Match Functions
187 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000188
Chris Lattner3e4582a2010-09-06 19:11:01 +0000189#define GET_ASSEMBLER_HEADER
190#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000191
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000192 /// }
193
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000194 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000195 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000196 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000197 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000198 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000199 OperandMatchResultTy parseCoprocOptionOperand(
200 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000201 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000202 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000203 OperandMatchResultTy parseInstSyncBarrierOptOperand(
204 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000205 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000206 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000207 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000208 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000209 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
210 StringRef Op, int Low, int High);
211 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
212 return parsePKHImm(O, "lsl", 0, 31);
213 }
214 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
215 return parsePKHImm(O, "asr", 1, 32);
216 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000217 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000218 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000219 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000220 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000221 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000222 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000223 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000224 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000225 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
226 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000227
228 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000229 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000230 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000231 void cvtThumbBranches(MCInst &Inst,
232 const SmallVectorImpl<MCParsedAsmOperand*> &);
233
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000234 bool validateInstruction(MCInst &Inst,
235 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000236 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000237 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000238 bool shouldOmitCCOutOperand(StringRef Mnemonic,
239 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000240 bool shouldOmitPredicateOperand(StringRef Mnemonic,
241 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000242public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000243 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000244 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000245 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000246 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000247 Match_RequiresThumb2,
248#define GET_OPERAND_DIAGNOSTIC_TYPES
249#include "ARMGenAsmMatcher.inc"
250
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000251 };
252
Joey Gouly0e76fa72013-09-12 10:28:05 +0000253 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
254 const MCInstrInfo &MII)
255 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000256 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000257
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000258 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000259 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000260
Evan Cheng4d1ca962011-07-08 01:53:10 +0000261 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000262 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000263
264 // Not in an ITBlock to start with.
265 ITState.CurPosition = ~0U;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000266 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000267
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000268 // Implementation of the MCTargetAsmParser interface:
269 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000270 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
271 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000272 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000273 bool ParseDirective(AsmToken DirectiveID);
274
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000275 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000276 unsigned checkTargetMatchPredicate(MCInst &Inst);
277
Chad Rosier49963552012-10-13 00:26:04 +0000278 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000279 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000280 MCStreamer &Out, unsigned &ErrorInfo,
281 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000282};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000283} // end anonymous namespace
284
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000285namespace {
286
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000287/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000288/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000289class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000290 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000291 k_CondCode,
292 k_CCOut,
293 k_ITCondMask,
294 k_CoprocNum,
295 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000296 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000297 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000298 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000299 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000300 k_Memory,
301 k_PostIndexRegister,
302 k_MSRMask,
303 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000304 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000305 k_Register,
306 k_RegisterList,
307 k_DPRRegisterList,
308 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000309 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000310 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000311 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000312 k_ShiftedRegister,
313 k_ShiftedImmediate,
314 k_ShifterImmediate,
315 k_RotateImmediate,
316 k_BitfieldDescriptor,
317 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000318 } Kind;
319
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000320 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000321 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000322
Eric Christopher8996c5d2013-03-15 00:42:55 +0000323 struct CCOp {
324 ARMCC::CondCodes Val;
325 };
326
327 struct CopOp {
328 unsigned Val;
329 };
330
331 struct CoprocOptionOp {
332 unsigned Val;
333 };
334
335 struct ITMaskOp {
336 unsigned Mask:4;
337 };
338
339 struct MBOptOp {
340 ARM_MB::MemBOpt Val;
341 };
342
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000343 struct ISBOptOp {
344 ARM_ISB::InstSyncBOpt Val;
345 };
346
Eric Christopher8996c5d2013-03-15 00:42:55 +0000347 struct IFlagsOp {
348 ARM_PROC::IFlags Val;
349 };
350
351 struct MMaskOp {
352 unsigned Val;
353 };
354
355 struct TokOp {
356 const char *Data;
357 unsigned Length;
358 };
359
360 struct RegOp {
361 unsigned RegNum;
362 };
363
364 // A vector register list is a sequential list of 1 to 4 registers.
365 struct VectorListOp {
366 unsigned RegNum;
367 unsigned Count;
368 unsigned LaneIndex;
369 bool isDoubleSpaced;
370 };
371
372 struct VectorIndexOp {
373 unsigned Val;
374 };
375
376 struct ImmOp {
377 const MCExpr *Val;
378 };
379
380 /// Combined record for all forms of ARM address expressions.
381 struct MemoryOp {
382 unsigned BaseRegNum;
383 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
384 // was specified.
385 const MCConstantExpr *OffsetImm; // Offset immediate value
386 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
387 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
388 unsigned ShiftImm; // shift for OffsetReg.
389 unsigned Alignment; // 0 = no alignment specified
390 // n = alignment in bytes (2, 4, 8, 16, or 32)
391 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
392 };
393
394 struct PostIdxRegOp {
395 unsigned RegNum;
396 bool isAdd;
397 ARM_AM::ShiftOpc ShiftTy;
398 unsigned ShiftImm;
399 };
400
401 struct ShifterImmOp {
402 bool isASR;
403 unsigned Imm;
404 };
405
406 struct RegShiftedRegOp {
407 ARM_AM::ShiftOpc ShiftTy;
408 unsigned SrcReg;
409 unsigned ShiftReg;
410 unsigned ShiftImm;
411 };
412
413 struct RegShiftedImmOp {
414 ARM_AM::ShiftOpc ShiftTy;
415 unsigned SrcReg;
416 unsigned ShiftImm;
417 };
418
419 struct RotImmOp {
420 unsigned Imm;
421 };
422
423 struct BitfieldOp {
424 unsigned LSB;
425 unsigned Width;
426 };
427
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000428 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000429 struct CCOp CC;
430 struct CopOp Cop;
431 struct CoprocOptionOp CoprocOption;
432 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000433 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000434 struct ITMaskOp ITMask;
435 struct IFlagsOp IFlags;
436 struct MMaskOp MMask;
437 struct TokOp Tok;
438 struct RegOp Reg;
439 struct VectorListOp VectorList;
440 struct VectorIndexOp VectorIndex;
441 struct ImmOp Imm;
442 struct MemoryOp Memory;
443 struct PostIdxRegOp PostIdxReg;
444 struct ShifterImmOp ShifterImm;
445 struct RegShiftedRegOp RegShiftedReg;
446 struct RegShiftedImmOp RegShiftedImm;
447 struct RotImmOp RotImm;
448 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000449 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000450
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000451 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
452public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000453 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
454 Kind = o.Kind;
455 StartLoc = o.StartLoc;
456 EndLoc = o.EndLoc;
457 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000458 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000459 CC = o.CC;
460 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000462 ITMask = o.ITMask;
463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000465 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000466 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000467 case k_CCOut:
468 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000469 Reg = o.Reg;
470 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000471 case k_RegisterList:
472 case k_DPRRegisterList:
473 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000474 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000475 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000476 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000477 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000478 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000479 VectorList = o.VectorList;
480 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000481 case k_CoprocNum:
482 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000483 Cop = o.Cop;
484 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000485 case k_CoprocOption:
486 CoprocOption = o.CoprocOption;
487 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000488 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000489 Imm = o.Imm;
490 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000491 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000492 MBOpt = o.MBOpt;
493 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000494 case k_InstSyncBarrierOpt:
495 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000496 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000497 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000500 PostIdxReg = o.PostIdxReg;
501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000503 MMask = o.MMask;
504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000505 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000506 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000508 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000509 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000510 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000511 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000512 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000514 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000515 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000517 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000518 RotImm = o.RotImm;
519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000520 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000521 Bitfield = o.Bitfield;
522 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000523 case k_VectorIndex:
524 VectorIndex = o.VectorIndex;
525 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000526 }
527 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000528
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000529 /// getStartLoc - Get the location of the first token of this operand.
530 SMLoc getStartLoc() const { return StartLoc; }
531 /// getEndLoc - Get the location of the last token of this operand.
532 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000533 /// getLocRange - Get the range between the first and last token of this
534 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000535 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
536
Daniel Dunbard8042b72010-08-11 06:36:53 +0000537 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000538 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000539 return CC.Val;
540 }
541
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000542 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000543 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000544 return Cop.Val;
545 }
546
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000547 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000548 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000549 return StringRef(Tok.Data, Tok.Length);
550 }
551
552 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000553 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000554 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000555 }
556
Bill Wendlingbed94652010-11-09 23:28:44 +0000557 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000558 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
559 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000560 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000561 }
562
Kevin Enderbyf5079942009-10-13 22:19:02 +0000563 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000564 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000565 return Imm.Val;
566 }
567
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000568 unsigned getVectorIndex() const {
569 assert(Kind == k_VectorIndex && "Invalid access!");
570 return VectorIndex.Val;
571 }
572
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000573 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000575 return MBOpt.Val;
576 }
577
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000578 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
579 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
580 return ISBOpt.Val;
581 }
582
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000583 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000584 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000585 return IFlags.Val;
586 }
587
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000588 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000590 return MMask.Val;
591 }
592
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000593 bool isCoprocNum() const { return Kind == k_CoprocNum; }
594 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000595 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000596 bool isCondCode() const { return Kind == k_CondCode; }
597 bool isCCOut() const { return Kind == k_CCOut; }
598 bool isITMask() const { return Kind == k_ITCondMask; }
599 bool isITCondCode() const { return Kind == k_CondCode; }
600 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000601 // checks whether this operand is an unsigned offset which fits is a field
602 // of specified width and scaled by a specific number of bits
603 template<unsigned width, unsigned scale>
604 bool isUnsignedOffset() const {
605 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000606 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000607 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
608 int64_t Val = CE->getValue();
609 int64_t Align = 1LL << scale;
610 int64_t Max = Align * ((1LL << width) - 1);
611 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
612 }
613 return false;
614 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000615 // checks whether this operand is an signed offset which fits is a field
616 // of specified width and scaled by a specific number of bits
617 template<unsigned width, unsigned scale>
618 bool isSignedOffset() const {
619 if (!isImm()) return false;
620 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
621 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
622 int64_t Val = CE->getValue();
623 int64_t Align = 1LL << scale;
624 int64_t Max = Align * ((1LL << (width-1)) - 1);
625 int64_t Min = -Align * (1LL << (width-1));
626 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
627 }
628 return false;
629 }
630
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000631 // checks whether this operand is a memory operand computed as an offset
632 // applied to PC. the offset may have 8 bits of magnitude and is represented
633 // with two bits of shift. textually it may be either [pc, #imm], #imm or
634 // relocable expression...
635 bool isThumbMemPC() const {
636 int64_t Val = 0;
637 if (isImm()) {
638 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
639 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
640 if (!CE) return false;
641 Val = CE->getValue();
642 }
643 else if (isMem()) {
644 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
645 if(Memory.BaseRegNum != ARM::PC) return false;
646 Val = Memory.OffsetImm->getValue();
647 }
648 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000649 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000650 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000651 bool isFPImm() const {
652 if (!isImm()) return false;
653 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
654 if (!CE) return false;
655 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
656 return Val != -1;
657 }
Jim Grosbachea231912011-12-22 22:19:05 +0000658 bool isFBits16() const {
659 if (!isImm()) return false;
660 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
661 if (!CE) return false;
662 int64_t Value = CE->getValue();
663 return Value >= 0 && Value <= 16;
664 }
665 bool isFBits32() const {
666 if (!isImm()) return false;
667 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
668 if (!CE) return false;
669 int64_t Value = CE->getValue();
670 return Value >= 1 && Value <= 32;
671 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000672 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000673 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000674 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
675 if (!CE) return false;
676 int64_t Value = CE->getValue();
677 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
678 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000679 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000680 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000681 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
682 if (!CE) return false;
683 int64_t Value = CE->getValue();
684 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
685 }
686 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000687 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
689 if (!CE) return false;
690 int64_t Value = CE->getValue();
691 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
692 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000693 bool isImm0_508s4Neg() const {
694 if (!isImm()) return false;
695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
696 if (!CE) return false;
697 int64_t Value = -CE->getValue();
698 // explicitly exclude zero. we want that to use the normal 0_508 version.
699 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
700 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000701 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000702 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return Value >= 0 && Value < 256;
707 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000708 bool isImm0_4095() const {
709 if (!isImm()) return false;
710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = CE->getValue();
713 return Value >= 0 && Value < 4096;
714 }
715 bool isImm0_4095Neg() const {
716 if (!isImm()) return false;
717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = -CE->getValue();
720 return Value > 0 && Value < 4096;
721 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000722 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000723 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value >= 0 && Value < 2;
728 }
729 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000730 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 if (!CE) return false;
733 int64_t Value = CE->getValue();
734 return Value >= 0 && Value < 4;
735 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000736 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000737 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
739 if (!CE) return false;
740 int64_t Value = CE->getValue();
741 return Value >= 0 && Value < 8;
742 }
743 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000744 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
746 if (!CE) return false;
747 int64_t Value = CE->getValue();
748 return Value >= 0 && Value < 16;
749 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000750 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000751 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000752 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
753 if (!CE) return false;
754 int64_t Value = CE->getValue();
755 return Value >= 0 && Value < 32;
756 }
Jim Grosbach00326402011-12-08 01:30:04 +0000757 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000758 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
760 if (!CE) return false;
761 int64_t Value = CE->getValue();
762 return Value >= 0 && Value < 64;
763 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000764 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000765 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
767 if (!CE) return false;
768 int64_t Value = CE->getValue();
769 return Value == 8;
770 }
771 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000772 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
774 if (!CE) return false;
775 int64_t Value = CE->getValue();
776 return Value == 16;
777 }
778 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000779 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
781 if (!CE) return false;
782 int64_t Value = CE->getValue();
783 return Value == 32;
784 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000785 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000786 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int64_t Value = CE->getValue();
790 return Value > 0 && Value <= 8;
791 }
792 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000793 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
795 if (!CE) return false;
796 int64_t Value = CE->getValue();
797 return Value > 0 && Value <= 16;
798 }
799 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000800 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
802 if (!CE) return false;
803 int64_t Value = CE->getValue();
804 return Value > 0 && Value <= 32;
805 }
806 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000807 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return Value > 0 && Value <= 64;
812 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000813 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000814 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return Value > 0 && Value < 8;
819 }
820 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000821 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = CE->getValue();
825 return Value > 0 && Value < 16;
826 }
827 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000828 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = CE->getValue();
832 return Value > 0 && Value < 32;
833 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000834 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000835 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return Value > 0 && Value < 17;
840 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000841 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000842 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
846 return Value > 0 && Value < 33;
847 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000848 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000849 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value >= 0 && Value < 33;
854 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000855 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000856 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
858 if (!CE) return false;
859 int64_t Value = CE->getValue();
860 return Value >= 0 && Value < 65536;
861 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000862 bool isImm256_65535Expr() const {
863 if (!isImm()) return false;
864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 // If it's not a constant expression, it'll generate a fixup and be
866 // handled later.
867 if (!CE) return true;
868 int64_t Value = CE->getValue();
869 return Value >= 256 && Value < 65536;
870 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000871 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000872 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 // If it's not a constant expression, it'll generate a fixup and be
875 // handled later.
876 if (!CE) return true;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value < 65536;
879 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000880 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value >= 0 && Value <= 0xffffff;
886 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000887 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000888 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 if (!CE) return false;
891 int64_t Value = CE->getValue();
892 return Value > 0 && Value < 33;
893 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000894 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000895 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return Value >= 0 && Value < 32;
900 }
901 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000902 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Value = CE->getValue();
906 return Value > 0 && Value <= 32;
907 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000908 bool isAdrLabel() const {
909 // If we have an immediate that's not a constant, treat it as a label
910 // reference needing a fixup. If it is a constant, but it can't fit
911 // into shift immediate encoding, we reject it.
912 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
913 else return (isARMSOImm() || isARMSOImmNeg());
914 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000915 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
918 if (!CE) return false;
919 int64_t Value = CE->getValue();
920 return ARM_AM::getSOImmVal(Value) != -1;
921 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000922 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000923 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
925 if (!CE) return false;
926 int64_t Value = CE->getValue();
927 return ARM_AM::getSOImmVal(~Value) != -1;
928 }
Jim Grosbach30506252011-12-08 00:31:07 +0000929 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000930 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000931 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
932 if (!CE) return false;
933 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000934 // Only use this when not representable as a plain so_imm.
935 return ARM_AM::getSOImmVal(Value) == -1 &&
936 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000937 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000938 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000939 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return ARM_AM::getT2SOImmVal(Value) != -1;
944 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000945 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000946 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000950 return ARM_AM::getT2SOImmVal(Value) == -1 &&
951 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000952 }
Jim Grosbach30506252011-12-08 00:31:07 +0000953 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000954 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
956 if (!CE) return false;
957 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000958 // Only use this when not representable as a plain so_imm.
959 return ARM_AM::getT2SOImmVal(Value) == -1 &&
960 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000961 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000962 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000963 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 if (!CE) return false;
966 int64_t Value = CE->getValue();
967 return Value == 1 || Value == 0;
968 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000969 bool isReg() const { return Kind == k_Register; }
970 bool isRegList() const { return Kind == k_RegisterList; }
971 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
972 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
973 bool isToken() const { return Kind == k_Token; }
974 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000975 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000976 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000977 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
978 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
979 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
980 bool isRotImm() const { return Kind == k_RotateImmediate; }
981 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
982 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000983 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000984 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000985 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000986 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000987 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000988 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000989 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000990 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
991 (alignOK || Memory.Alignment == 0);
992 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000993 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000994 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000995 return false;
996 // Base register must be PC.
997 if (Memory.BaseRegNum != ARM::PC)
998 return false;
999 // Immediate offset in range [-4095, 4095].
1000 if (!Memory.OffsetImm) return true;
1001 int64_t Val = Memory.OffsetImm->getValue();
1002 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1003 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001004 bool isAlignedMemory() const {
1005 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001006 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001007 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001008 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001009 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001010 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001011 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001012 if (!Memory.OffsetImm) return true;
1013 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001014 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001015 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001016 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001017 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001018 // Immediate offset in range [-4095, 4095].
1019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1020 if (!CE) return false;
1021 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001022 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001023 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001024 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001025 // If we have an immediate that's not a constant, treat it as a label
1026 // reference needing a fixup. If it is a constant, it's something else
1027 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001028 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001029 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001030 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001031 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001032 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001033 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001034 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001035 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001036 if (!Memory.OffsetImm) return true;
1037 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001038 // The #-0 offset is encoded as INT32_MIN, and we have to check
1039 // for this too.
1040 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001041 }
1042 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001043 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001044 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001045 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001046 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1047 // Immediate offset in range [-255, 255].
1048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1049 if (!CE) return false;
1050 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001051 // Special case, #-0 is INT32_MIN.
1052 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001053 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001054 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001055 // If we have an immediate that's not a constant, treat it as a label
1056 // reference needing a fixup. If it is a constant, it's something else
1057 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001058 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001059 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001060 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001061 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001062 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001063 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001064 if (!Memory.OffsetImm) return true;
1065 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001066 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001067 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001068 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001069 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001070 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001071 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001072 return false;
1073 return true;
1074 }
1075 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001076 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001077 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1078 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001079 return false;
1080 return true;
1081 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001082 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001083 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001084 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001085 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001086 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001087 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001088 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001089 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001090 return false;
1091 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001092 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001093 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001094 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001095 return false;
1096 return true;
1097 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001098 bool isMemThumbRR() const {
1099 // Thumb reg+reg addressing is simple. Just two registers, a base and
1100 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001101 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001102 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001103 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 return isARMLowRegister(Memory.BaseRegNum) &&
1105 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001106 }
1107 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001108 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001109 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001110 return false;
1111 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001112 if (!Memory.OffsetImm) return true;
1113 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001114 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1115 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001116 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001117 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001118 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001119 return false;
1120 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001121 if (!Memory.OffsetImm) return true;
1122 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001123 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1124 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001125 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001126 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001127 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001128 return false;
1129 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001130 if (!Memory.OffsetImm) return true;
1131 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001132 return Val >= 0 && Val <= 31;
1133 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001134 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001135 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001136 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001137 return false;
1138 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001139 if (!Memory.OffsetImm) return true;
1140 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001141 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001142 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001143 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001144 // If we have an immediate that's not a constant, treat it as a label
1145 // reference needing a fixup. If it is a constant, it's something else
1146 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001147 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001148 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001149 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001150 return false;
1151 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001152 if (!Memory.OffsetImm) return true;
1153 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001154 // Special case, #-0 is INT32_MIN.
1155 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001156 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001157 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001158 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001159 return false;
1160 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001161 if (!Memory.OffsetImm) return true;
1162 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001163 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1164 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001165 bool isMemImm8Offset() const {
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;
Jim Grosbach94298a92012-01-18 22:46:46 +00001168 // Base reg of PC isn't allowed for these encodings.
1169 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001170 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001173 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001174 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001175 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001177 return false;
1178 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001179 if (!Memory.OffsetImm) return true;
1180 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001181 return Val >= 0 && Val < 256;
1182 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001183 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001184 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001185 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001186 // Base reg of PC isn't allowed for these encodings.
1187 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001188 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001189 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001190 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001191 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001192 }
1193 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001194 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001195 return false;
1196 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001197 if (!Memory.OffsetImm) return true;
1198 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001199 return (Val >= 0 && Val < 4096);
1200 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001201 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001202 // If we have an immediate that's not a constant, treat it as a label
1203 // reference needing a fixup. If it is a constant, it's something else
1204 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001205 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001206 return true;
1207
Chad Rosier41099832012-09-11 23:02:35 +00001208 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001209 return false;
1210 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001211 if (!Memory.OffsetImm) return true;
1212 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001213 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001214 }
1215 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001216 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1218 if (!CE) return false;
1219 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001220 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001221 }
Jim Grosbach93981412011-10-11 21:55:36 +00001222 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001223 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001224 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1225 if (!CE) return false;
1226 int64_t Val = CE->getValue();
1227 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1228 (Val == INT32_MIN);
1229 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001230
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001231 bool isMSRMask() const { return Kind == k_MSRMask; }
1232 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001233
Jim Grosbach741cd732011-10-17 22:26:03 +00001234 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001235 bool isSingleSpacedVectorList() const {
1236 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1237 }
1238 bool isDoubleSpacedVectorList() const {
1239 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1240 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001241 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001242 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001243 return VectorList.Count == 1;
1244 }
1245
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001246 bool isVecListDPair() const {
1247 if (!isSingleSpacedVectorList()) return false;
1248 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1249 .contains(VectorList.RegNum));
1250 }
1251
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001252 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001253 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001254 return VectorList.Count == 3;
1255 }
1256
Jim Grosbach846bcff2011-10-21 20:35:01 +00001257 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001258 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001259 return VectorList.Count == 4;
1260 }
1261
Jim Grosbache5307f92012-03-05 21:43:40 +00001262 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001263 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001264 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1265 .contains(VectorList.RegNum));
1266 }
1267
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001268 bool isVecListThreeQ() const {
1269 if (!isDoubleSpacedVectorList()) return false;
1270 return VectorList.Count == 3;
1271 }
1272
Jim Grosbach1e946a42012-01-24 00:43:12 +00001273 bool isVecListFourQ() const {
1274 if (!isDoubleSpacedVectorList()) return false;
1275 return VectorList.Count == 4;
1276 }
1277
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001278 bool isSingleSpacedVectorAllLanes() const {
1279 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1280 }
1281 bool isDoubleSpacedVectorAllLanes() const {
1282 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1283 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001284 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001285 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001286 return VectorList.Count == 1;
1287 }
1288
Jim Grosbach13a292c2012-03-06 22:01:44 +00001289 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001290 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001291 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1292 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001293 }
1294
Jim Grosbached428bc2012-03-06 23:10:38 +00001295 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001296 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001297 return VectorList.Count == 2;
1298 }
1299
Jim Grosbachb78403c2012-01-24 23:47:04 +00001300 bool isVecListThreeDAllLanes() const {
1301 if (!isSingleSpacedVectorAllLanes()) return false;
1302 return VectorList.Count == 3;
1303 }
1304
1305 bool isVecListThreeQAllLanes() const {
1306 if (!isDoubleSpacedVectorAllLanes()) return false;
1307 return VectorList.Count == 3;
1308 }
1309
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001310 bool isVecListFourDAllLanes() const {
1311 if (!isSingleSpacedVectorAllLanes()) return false;
1312 return VectorList.Count == 4;
1313 }
1314
1315 bool isVecListFourQAllLanes() const {
1316 if (!isDoubleSpacedVectorAllLanes()) return false;
1317 return VectorList.Count == 4;
1318 }
1319
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001320 bool isSingleSpacedVectorIndexed() const {
1321 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1322 }
1323 bool isDoubleSpacedVectorIndexed() const {
1324 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1325 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001326 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001327 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001328 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1329 }
1330
Jim Grosbachda511042011-12-14 23:35:06 +00001331 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001332 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001333 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1334 }
1335
1336 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001337 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001338 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1339 }
1340
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001341 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001342 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001343 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1344 }
1345
Jim Grosbachda511042011-12-14 23:35:06 +00001346 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001347 if (!isSingleSpacedVectorIndexed()) return false;
1348 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1349 }
1350
1351 bool isVecListTwoQWordIndexed() const {
1352 if (!isDoubleSpacedVectorIndexed()) return false;
1353 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1354 }
1355
1356 bool isVecListTwoQHWordIndexed() const {
1357 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001358 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1359 }
1360
1361 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001362 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001363 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1364 }
1365
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001366 bool isVecListThreeDByteIndexed() const {
1367 if (!isSingleSpacedVectorIndexed()) return false;
1368 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1369 }
1370
1371 bool isVecListThreeDHWordIndexed() const {
1372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1374 }
1375
1376 bool isVecListThreeQWordIndexed() const {
1377 if (!isDoubleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1379 }
1380
1381 bool isVecListThreeQHWordIndexed() const {
1382 if (!isDoubleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1384 }
1385
1386 bool isVecListThreeDWordIndexed() const {
1387 if (!isSingleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1389 }
1390
Jim Grosbach14952a02012-01-24 18:37:25 +00001391 bool isVecListFourDByteIndexed() const {
1392 if (!isSingleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1394 }
1395
1396 bool isVecListFourDHWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1399 }
1400
1401 bool isVecListFourQWordIndexed() const {
1402 if (!isDoubleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1404 }
1405
1406 bool isVecListFourQHWordIndexed() const {
1407 if (!isDoubleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1409 }
1410
1411 bool isVecListFourDWordIndexed() const {
1412 if (!isSingleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1414 }
1415
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001416 bool isVectorIndex8() const {
1417 if (Kind != k_VectorIndex) return false;
1418 return VectorIndex.Val < 8;
1419 }
1420 bool isVectorIndex16() const {
1421 if (Kind != k_VectorIndex) return false;
1422 return VectorIndex.Val < 4;
1423 }
1424 bool isVectorIndex32() const {
1425 if (Kind != k_VectorIndex) return false;
1426 return VectorIndex.Val < 2;
1427 }
1428
Jim Grosbach741cd732011-10-17 22:26:03 +00001429 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001430 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1432 // Must be a constant.
1433 if (!CE) return false;
1434 int64_t Value = CE->getValue();
1435 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1436 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001437 return Value >= 0 && Value < 256;
1438 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001439
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001440 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001441 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001442 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1443 // Must be a constant.
1444 if (!CE) return false;
1445 int64_t Value = CE->getValue();
1446 // i16 value in the range [0,255] or [0x0100, 0xff00]
1447 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1448 }
1449
Jim Grosbach8211c052011-10-18 00:22:00 +00001450 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001451 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001452 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1453 // Must be a constant.
1454 if (!CE) return false;
1455 int64_t Value = CE->getValue();
1456 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1457 return (Value >= 0 && Value < 256) ||
1458 (Value >= 0x0100 && Value <= 0xff00) ||
1459 (Value >= 0x010000 && Value <= 0xff0000) ||
1460 (Value >= 0x01000000 && Value <= 0xff000000);
1461 }
1462
1463 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001464 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1466 // Must be a constant.
1467 if (!CE) return false;
1468 int64_t Value = CE->getValue();
1469 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1470 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1471 return (Value >= 0 && Value < 256) ||
1472 (Value >= 0x0100 && Value <= 0xff00) ||
1473 (Value >= 0x010000 && Value <= 0xff0000) ||
1474 (Value >= 0x01000000 && Value <= 0xff000000) ||
1475 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1476 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1477 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001478 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001479 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001480 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1481 // Must be a constant.
1482 if (!CE) return false;
1483 int64_t Value = ~CE->getValue();
1484 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1485 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1486 return (Value >= 0 && Value < 256) ||
1487 (Value >= 0x0100 && Value <= 0xff00) ||
1488 (Value >= 0x010000 && Value <= 0xff0000) ||
1489 (Value >= 0x01000000 && Value <= 0xff000000) ||
1490 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1491 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1492 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001493
Jim Grosbache4454e02011-10-18 16:18:11 +00001494 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001495 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001496 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1497 // Must be a constant.
1498 if (!CE) return false;
1499 uint64_t Value = CE->getValue();
1500 // i64 value with each byte being either 0 or 0xff.
1501 for (unsigned i = 0; i < 8; ++i)
1502 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1503 return true;
1504 }
1505
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001506 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001507 // Add as immediates when possible. Null MCExpr = 0.
1508 if (Expr == 0)
1509 Inst.addOperand(MCOperand::CreateImm(0));
1510 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001511 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1512 else
1513 Inst.addOperand(MCOperand::CreateExpr(Expr));
1514 }
1515
Daniel Dunbard8042b72010-08-11 06:36:53 +00001516 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001517 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001518 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001519 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1520 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001521 }
1522
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001523 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1524 assert(N == 1 && "Invalid number of operands!");
1525 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1526 }
1527
Jim Grosbach48399582011-10-12 17:34:41 +00001528 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1531 }
1532
1533 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1536 }
1537
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001538 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1541 }
1542
1543 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1546 }
1547
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001548 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateReg(getReg()));
1551 }
1552
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001553 void addRegOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateReg(getReg()));
1556 }
1557
Jim Grosbachac798e12011-07-25 20:49:51 +00001558 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001559 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001560 assert(isRegShiftedReg() &&
1561 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001562 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1563 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001564 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001565 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001566 }
1567
Jim Grosbachac798e12011-07-25 20:49:51 +00001568 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001569 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001570 assert(isRegShiftedImm() &&
1571 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001572 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001573 // Shift of #32 is encoded as 0 where permitted
1574 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001575 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001576 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001577 }
1578
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001579 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001580 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001581 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1582 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001583 }
1584
Bill Wendling8d2aa032010-11-08 23:49:57 +00001585 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001586 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001587 const SmallVectorImpl<unsigned> &RegList = getRegList();
1588 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001589 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1590 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001591 }
1592
Bill Wendling9898ac92010-11-17 04:32:08 +00001593 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1594 addRegListOperands(Inst, N);
1595 }
1596
1597 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1598 addRegListOperands(Inst, N);
1599 }
1600
Jim Grosbach833b9d32011-07-27 20:15:40 +00001601 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1604 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1605 }
1606
Jim Grosbach864b6092011-07-28 21:34:26 +00001607 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 // Munge the lsb/width into a bitfield mask.
1610 unsigned lsb = Bitfield.LSB;
1611 unsigned width = Bitfield.Width;
1612 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1613 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1614 (32 - (lsb + width)));
1615 Inst.addOperand(MCOperand::CreateImm(Mask));
1616 }
1617
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001618 void addImmOperands(MCInst &Inst, unsigned N) const {
1619 assert(N == 1 && "Invalid number of operands!");
1620 addExpr(Inst, getImm());
1621 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001622
Jim Grosbachea231912011-12-22 22:19:05 +00001623 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1626 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1627 }
1628
1629 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1630 assert(N == 1 && "Invalid number of operands!");
1631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1632 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1633 }
1634
Jim Grosbache7fbce72011-10-03 23:38:36 +00001635 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1639 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001640 }
1641
Jim Grosbach7db8d692011-09-08 22:07:06 +00001642 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 // FIXME: We really want to scale the value here, but the LDRD/STRD
1645 // instruction don't encode operands that way yet.
1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1648 }
1649
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001650 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 // The immediate is scaled by four in the encoding and is stored
1653 // in the MCInst as such. Lop off the low two bits here.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1656 }
1657
Jim Grosbach930f2f62012-04-05 20:57:13 +00001658 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1659 assert(N == 1 && "Invalid number of operands!");
1660 // The immediate is scaled by four in the encoding and is stored
1661 // in the MCInst as such. Lop off the low two bits here.
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1664 }
1665
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001666 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The immediate is scaled by four in the encoding and is stored
1669 // in the MCInst as such. Lop off the low two bits here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1672 }
1673
Jim Grosbach475c6db2011-07-25 23:09:14 +00001674 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The constant encodes as the immediate-1, and we store in the instruction
1677 // the bits as encoded, so subtract off one here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1680 }
1681
Jim Grosbach801e0a32011-07-22 23:16:18 +00001682 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The constant encodes as the immediate-1, and we store in the instruction
1685 // the bits as encoded, so subtract off one here.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1688 }
1689
Jim Grosbach46dd4132011-08-17 21:51:27 +00001690 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1691 assert(N == 1 && "Invalid number of operands!");
1692 // The constant encodes as the immediate, except for 32, which encodes as
1693 // zero.
1694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1695 unsigned Imm = CE->getValue();
1696 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1697 }
1698
Jim Grosbach27c1e252011-07-21 17:23:04 +00001699 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1700 assert(N == 1 && "Invalid number of operands!");
1701 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1702 // the instruction as well.
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 int Val = CE->getValue();
1705 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1706 }
1707
Jim Grosbachb009a872011-10-28 22:36:30 +00001708 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // The operand is actually a t2_so_imm, but we have its bitwise
1711 // negation in the assembly source, so twiddle it here.
1712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1713 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1714 }
1715
Jim Grosbach30506252011-12-08 00:31:07 +00001716 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1717 assert(N == 1 && "Invalid number of operands!");
1718 // The operand is actually a t2_so_imm, but we have its
1719 // negation in the assembly source, so twiddle it here.
1720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1722 }
1723
Jim Grosbach930f2f62012-04-05 20:57:13 +00001724 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1725 assert(N == 1 && "Invalid number of operands!");
1726 // The operand is actually an imm0_4095, but we have its
1727 // negation in the assembly source, so twiddle it here.
1728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1730 }
1731
Mihai Popad36cbaa2013-07-03 09:21:44 +00001732 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1733 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1734 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1735 return;
1736 }
1737
1738 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1739 assert(SR && "Unknown value type!");
1740 Inst.addOperand(MCOperand::CreateExpr(SR));
1741 }
1742
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001743 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1744 assert(N == 1 && "Invalid number of operands!");
1745 if (isImm()) {
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1747 if (CE) {
1748 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1749 return;
1750 }
1751
1752 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1753 assert(SR && "Unknown value type!");
1754 Inst.addOperand(MCOperand::CreateExpr(SR));
1755 return;
1756 }
1757
1758 assert(isMem() && "Unknown value type!");
1759 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1760 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1761 }
1762
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001763 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1764 assert(N == 1 && "Invalid number of operands!");
1765 // The operand is actually a so_imm, but we have its bitwise
1766 // negation in the assembly source, so twiddle it here.
1767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1768 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1769 }
1770
Jim Grosbach30506252011-12-08 00:31:07 +00001771 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1772 assert(N == 1 && "Invalid number of operands!");
1773 // The operand is actually a so_imm, but we have its
1774 // negation in the assembly source, so twiddle it here.
1775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1776 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1777 }
1778
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001779 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 1 && "Invalid number of operands!");
1781 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1782 }
1783
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001784 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1785 assert(N == 1 && "Invalid number of operands!");
1786 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1787 }
1788
Jim Grosbachd3595712011-08-03 23:50:40 +00001789 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001791 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001792 }
1793
Jim Grosbach94298a92012-01-18 22:46:46 +00001794 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001797 Inst.addOperand(MCOperand::CreateImm(Imm));
1798 }
1799
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001800 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1801 assert(N == 1 && "Invalid number of operands!");
1802 assert(isImm() && "Not an immediate!");
1803
1804 // If we have an immediate that's not a constant, treat it as a label
1805 // reference needing a fixup.
1806 if (!isa<MCConstantExpr>(getImm())) {
1807 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1808 return;
1809 }
1810
1811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1812 int Val = CE->getValue();
1813 Inst.addOperand(MCOperand::CreateImm(Val));
1814 }
1815
Jim Grosbacha95ec992011-10-11 17:29:55 +00001816 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 2 && "Invalid number of operands!");
1818 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1819 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1820 }
1821
Jim Grosbachd3595712011-08-03 23:50:40 +00001822 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1823 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001824 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1825 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001826 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1827 // Special case for #-0
1828 if (Val == INT32_MIN) Val = 0;
1829 if (Val < 0) Val = -Val;
1830 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1831 } else {
1832 // For register offset, we encode the shift type and negation flag
1833 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001834 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1835 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001836 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001837 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1838 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001839 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001840 }
1841
Jim Grosbachcd17c122011-08-04 23:01:30 +00001842 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1843 assert(N == 2 && "Invalid number of operands!");
1844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1845 assert(CE && "non-constant AM2OffsetImm operand!");
1846 int32_t Val = CE->getValue();
1847 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1848 // Special case for #-0
1849 if (Val == INT32_MIN) Val = 0;
1850 if (Val < 0) Val = -Val;
1851 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1852 Inst.addOperand(MCOperand::CreateReg(0));
1853 Inst.addOperand(MCOperand::CreateImm(Val));
1854 }
1855
Jim Grosbach5b96b802011-08-10 20:29:19 +00001856 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1857 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001858 // If we have an immediate that's not a constant, treat it as a label
1859 // reference needing a fixup. If it is a constant, it's something else
1860 // and we reject it.
1861 if (isImm()) {
1862 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1863 Inst.addOperand(MCOperand::CreateReg(0));
1864 Inst.addOperand(MCOperand::CreateImm(0));
1865 return;
1866 }
1867
Jim Grosbach871dff72011-10-11 15:59:20 +00001868 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1869 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001870 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1871 // Special case for #-0
1872 if (Val == INT32_MIN) Val = 0;
1873 if (Val < 0) Val = -Val;
1874 Val = ARM_AM::getAM3Opc(AddSub, Val);
1875 } else {
1876 // For register offset, we encode the shift type and negation flag
1877 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001878 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001879 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001882 Inst.addOperand(MCOperand::CreateImm(Val));
1883 }
1884
1885 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001887 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001888 int32_t Val =
1889 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1890 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1891 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001892 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001893 }
1894
1895 // Constant offset.
1896 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1897 int32_t Val = CE->getValue();
1898 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1899 // Special case for #-0
1900 if (Val == INT32_MIN) Val = 0;
1901 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001902 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001903 Inst.addOperand(MCOperand::CreateReg(0));
1904 Inst.addOperand(MCOperand::CreateImm(Val));
1905 }
1906
Jim Grosbachd3595712011-08-03 23:50:40 +00001907 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001909 // If we have an immediate that's not a constant, treat it as a label
1910 // reference needing a fixup. If it is a constant, it's something else
1911 // and we reject it.
1912 if (isImm()) {
1913 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1914 Inst.addOperand(MCOperand::CreateImm(0));
1915 return;
1916 }
1917
Jim Grosbachd3595712011-08-03 23:50:40 +00001918 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001919 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001920 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1921 // Special case for #-0
1922 if (Val == INT32_MIN) Val = 0;
1923 if (Val < 0) Val = -Val;
1924 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001925 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001926 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001927 }
1928
Jim Grosbach7db8d692011-09-08 22:07:06 +00001929 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1930 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001931 // If we have an immediate that's not a constant, treat it as a label
1932 // reference needing a fixup. If it is a constant, it's something else
1933 // and we reject it.
1934 if (isImm()) {
1935 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1936 Inst.addOperand(MCOperand::CreateImm(0));
1937 return;
1938 }
1939
Jim Grosbach871dff72011-10-11 15:59:20 +00001940 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1941 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001942 Inst.addOperand(MCOperand::CreateImm(Val));
1943 }
1944
Jim Grosbacha05627e2011-09-09 18:37:27 +00001945 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 2 && "Invalid number of operands!");
1947 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001948 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1949 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001950 Inst.addOperand(MCOperand::CreateImm(Val));
1951 }
1952
Jim Grosbachd3595712011-08-03 23:50:40 +00001953 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1954 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001955 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1956 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001957 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001958 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001959
Jim Grosbach2392c532011-09-07 23:39:14 +00001960 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1961 addMemImm8OffsetOperands(Inst, N);
1962 }
1963
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001964 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001965 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001966 }
1967
1968 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1969 assert(N == 2 && "Invalid number of operands!");
1970 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001971 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001972 addExpr(Inst, getImm());
1973 Inst.addOperand(MCOperand::CreateImm(0));
1974 return;
1975 }
1976
1977 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001978 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1979 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001980 Inst.addOperand(MCOperand::CreateImm(Val));
1981 }
1982
Jim Grosbachd3595712011-08-03 23:50:40 +00001983 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1984 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001985 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001986 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001987 addExpr(Inst, getImm());
1988 Inst.addOperand(MCOperand::CreateImm(0));
1989 return;
1990 }
1991
1992 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001993 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1994 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001995 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001996 }
Bill Wendling811c9362010-11-30 07:44:32 +00001997
Jim Grosbach05541f42011-09-19 22:21:13 +00001998 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002000 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2001 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002002 }
2003
2004 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2005 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002006 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2007 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002008 }
2009
Jim Grosbachd3595712011-08-03 23:50:40 +00002010 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002012 unsigned Val =
2013 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2014 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002015 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2016 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002017 Inst.addOperand(MCOperand::CreateImm(Val));
2018 }
2019
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002020 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002022 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2023 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2024 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002025 }
2026
Jim Grosbachd3595712011-08-03 23:50:40 +00002027 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2028 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002029 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2030 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002031 }
2032
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002033 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2034 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002035 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2036 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002037 Inst.addOperand(MCOperand::CreateImm(Val));
2038 }
2039
Jim Grosbach26d35872011-08-19 18:55:51 +00002040 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2041 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002042 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2043 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002044 Inst.addOperand(MCOperand::CreateImm(Val));
2045 }
2046
Jim Grosbacha32c7532011-08-19 18:49:59 +00002047 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2048 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002049 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2050 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002051 Inst.addOperand(MCOperand::CreateImm(Val));
2052 }
2053
Jim Grosbach23983d62011-08-19 18:13:48 +00002054 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2055 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002056 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2057 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002058 Inst.addOperand(MCOperand::CreateImm(Val));
2059 }
2060
Jim Grosbachd3595712011-08-03 23:50:40 +00002061 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2062 assert(N == 1 && "Invalid number of operands!");
2063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2064 assert(CE && "non-constant post-idx-imm8 operand!");
2065 int Imm = CE->getValue();
2066 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002067 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002068 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2069 Inst.addOperand(MCOperand::CreateImm(Imm));
2070 }
2071
Jim Grosbach93981412011-10-11 21:55:36 +00002072 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 1 && "Invalid number of operands!");
2074 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2075 assert(CE && "non-constant post-idx-imm8s4 operand!");
2076 int Imm = CE->getValue();
2077 bool isAdd = Imm >= 0;
2078 if (Imm == INT32_MIN) Imm = 0;
2079 // Immediate is scaled by 4.
2080 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2081 Inst.addOperand(MCOperand::CreateImm(Imm));
2082 }
2083
Jim Grosbachd3595712011-08-03 23:50:40 +00002084 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2085 assert(N == 2 && "Invalid number of operands!");
2086 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002087 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2088 }
2089
2090 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
2092 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2093 // The sign, shift type, and shift amount are encoded in a single operand
2094 // using the AM2 encoding helpers.
2095 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2096 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2097 PostIdxReg.ShiftTy);
2098 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002099 }
2100
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002101 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2102 assert(N == 1 && "Invalid number of operands!");
2103 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2104 }
2105
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002106 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2109 }
2110
Jim Grosbach182b6a02011-11-29 23:51:09 +00002111 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2114 }
2115
Jim Grosbach04945c42011-12-02 00:35:16 +00002116 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 2 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2119 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2120 }
2121
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002122 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2123 assert(N == 1 && "Invalid number of operands!");
2124 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2125 }
2126
2127 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2128 assert(N == 1 && "Invalid number of operands!");
2129 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2130 }
2131
2132 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2135 }
2136
Jim Grosbach741cd732011-10-17 22:26:03 +00002137 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 // The immediate encodes the type of constant as well as the value.
2140 // Mask in that this is an i8 splat.
2141 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2142 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2143 }
2144
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002145 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 // The immediate encodes the type of constant as well as the value.
2148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2149 unsigned Value = CE->getValue();
2150 if (Value >= 256)
2151 Value = (Value >> 8) | 0xa00;
2152 else
2153 Value |= 0x800;
2154 Inst.addOperand(MCOperand::CreateImm(Value));
2155 }
2156
Jim Grosbach8211c052011-10-18 00:22:00 +00002157 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 // The immediate encodes the type of constant as well as the value.
2160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2161 unsigned Value = CE->getValue();
2162 if (Value >= 256 && Value <= 0xff00)
2163 Value = (Value >> 8) | 0x200;
2164 else if (Value > 0xffff && Value <= 0xff0000)
2165 Value = (Value >> 16) | 0x400;
2166 else if (Value > 0xffffff)
2167 Value = (Value >> 24) | 0x600;
2168 Inst.addOperand(MCOperand::CreateImm(Value));
2169 }
2170
2171 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2172 assert(N == 1 && "Invalid number of operands!");
2173 // The immediate encodes the type of constant as well as the value.
2174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2175 unsigned Value = CE->getValue();
2176 if (Value >= 256 && Value <= 0xffff)
2177 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2178 else if (Value > 0xffff && Value <= 0xffffff)
2179 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2180 else if (Value > 0xffffff)
2181 Value = (Value >> 24) | 0x600;
2182 Inst.addOperand(MCOperand::CreateImm(Value));
2183 }
2184
Jim Grosbach045b6c72011-12-19 23:51:07 +00002185 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2186 assert(N == 1 && "Invalid number of operands!");
2187 // The immediate encodes the type of constant as well as the value.
2188 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2189 unsigned Value = ~CE->getValue();
2190 if (Value >= 256 && Value <= 0xffff)
2191 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2192 else if (Value > 0xffff && Value <= 0xffffff)
2193 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2194 else if (Value > 0xffffff)
2195 Value = (Value >> 24) | 0x600;
2196 Inst.addOperand(MCOperand::CreateImm(Value));
2197 }
2198
Jim Grosbache4454e02011-10-18 16:18:11 +00002199 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2200 assert(N == 1 && "Invalid number of operands!");
2201 // The immediate encodes the type of constant as well as the value.
2202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2203 uint64_t Value = CE->getValue();
2204 unsigned Imm = 0;
2205 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2206 Imm |= (Value & 1) << i;
2207 }
2208 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2209 }
2210
Jim Grosbach602aa902011-07-13 15:34:57 +00002211 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002212
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002213 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002214 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002215 Op->ITMask.Mask = Mask;
2216 Op->StartLoc = S;
2217 Op->EndLoc = S;
2218 return Op;
2219 }
2220
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002221 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002222 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002223 Op->CC.Val = CC;
2224 Op->StartLoc = S;
2225 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002226 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002227 }
2228
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002229 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002230 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002231 Op->Cop.Val = CopVal;
2232 Op->StartLoc = S;
2233 Op->EndLoc = S;
2234 return Op;
2235 }
2236
2237 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002238 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002239 Op->Cop.Val = CopVal;
2240 Op->StartLoc = S;
2241 Op->EndLoc = S;
2242 return Op;
2243 }
2244
Jim Grosbach48399582011-10-12 17:34:41 +00002245 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2246 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2247 Op->Cop.Val = Val;
2248 Op->StartLoc = S;
2249 Op->EndLoc = E;
2250 return Op;
2251 }
2252
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002253 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002254 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002255 Op->Reg.RegNum = RegNum;
2256 Op->StartLoc = S;
2257 Op->EndLoc = S;
2258 return Op;
2259 }
2260
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002261 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002262 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002263 Op->Tok.Data = Str.data();
2264 Op->Tok.Length = Str.size();
2265 Op->StartLoc = S;
2266 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002267 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002268 }
2269
Bill Wendling2063b842010-11-18 23:43:05 +00002270 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002272 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002273 Op->StartLoc = S;
2274 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002275 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002276 }
2277
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002278 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2279 unsigned SrcReg,
2280 unsigned ShiftReg,
2281 unsigned ShiftImm,
2282 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002283 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002284 Op->RegShiftedReg.ShiftTy = ShTy;
2285 Op->RegShiftedReg.SrcReg = SrcReg;
2286 Op->RegShiftedReg.ShiftReg = ShiftReg;
2287 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002288 Op->StartLoc = S;
2289 Op->EndLoc = E;
2290 return Op;
2291 }
2292
Owen Andersonb595ed02011-07-21 18:54:16 +00002293 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2294 unsigned SrcReg,
2295 unsigned ShiftImm,
2296 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002297 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002298 Op->RegShiftedImm.ShiftTy = ShTy;
2299 Op->RegShiftedImm.SrcReg = SrcReg;
2300 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002301 Op->StartLoc = S;
2302 Op->EndLoc = E;
2303 return Op;
2304 }
2305
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002306 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002307 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002308 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002309 Op->ShifterImm.isASR = isASR;
2310 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002311 Op->StartLoc = S;
2312 Op->EndLoc = E;
2313 return Op;
2314 }
2315
Jim Grosbach833b9d32011-07-27 20:15:40 +00002316 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002317 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002318 Op->RotImm.Imm = Imm;
2319 Op->StartLoc = S;
2320 Op->EndLoc = E;
2321 return Op;
2322 }
2323
Jim Grosbach864b6092011-07-28 21:34:26 +00002324 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2325 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002326 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002327 Op->Bitfield.LSB = LSB;
2328 Op->Bitfield.Width = Width;
2329 Op->StartLoc = S;
2330 Op->EndLoc = E;
2331 return Op;
2332 }
2333
Bill Wendling2cae3272010-11-09 22:44:22 +00002334 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002335 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002336 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002337 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002338 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002339
Chad Rosierfa705ee2013-07-01 20:49:23 +00002340 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002341 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002342 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002343 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002344 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002345
Chad Rosierfa705ee2013-07-01 20:49:23 +00002346 // Sort based on the register encoding values.
2347 array_pod_sort(Regs.begin(), Regs.end());
2348
Bill Wendling9898ac92010-11-17 04:32:08 +00002349 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002350 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002351 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002352 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002353 Op->StartLoc = StartLoc;
2354 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002355 return Op;
2356 }
2357
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002358 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002359 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002360 ARMOperand *Op = new ARMOperand(k_VectorList);
2361 Op->VectorList.RegNum = RegNum;
2362 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002363 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002364 Op->StartLoc = S;
2365 Op->EndLoc = E;
2366 return Op;
2367 }
2368
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002369 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002370 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002371 SMLoc S, SMLoc E) {
2372 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2373 Op->VectorList.RegNum = RegNum;
2374 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002375 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002376 Op->StartLoc = S;
2377 Op->EndLoc = E;
2378 return Op;
2379 }
2380
Jim Grosbach04945c42011-12-02 00:35:16 +00002381 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002382 unsigned Index,
2383 bool isDoubleSpaced,
2384 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002385 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2386 Op->VectorList.RegNum = RegNum;
2387 Op->VectorList.Count = Count;
2388 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002389 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002390 Op->StartLoc = S;
2391 Op->EndLoc = E;
2392 return Op;
2393 }
2394
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002395 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2396 MCContext &Ctx) {
2397 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2398 Op->VectorIndex.Val = Idx;
2399 Op->StartLoc = S;
2400 Op->EndLoc = E;
2401 return Op;
2402 }
2403
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002404 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002405 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002406 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002407 Op->StartLoc = S;
2408 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002409 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002410 }
2411
Jim Grosbachd3595712011-08-03 23:50:40 +00002412 static ARMOperand *CreateMem(unsigned BaseRegNum,
2413 const MCConstantExpr *OffsetImm,
2414 unsigned OffsetRegNum,
2415 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002416 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002417 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002418 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002419 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002420 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002421 Op->Memory.BaseRegNum = BaseRegNum;
2422 Op->Memory.OffsetImm = OffsetImm;
2423 Op->Memory.OffsetRegNum = OffsetRegNum;
2424 Op->Memory.ShiftType = ShiftType;
2425 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002426 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002427 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002428 Op->StartLoc = S;
2429 Op->EndLoc = E;
2430 return Op;
2431 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002432
Jim Grosbachc320c852011-08-05 21:28:30 +00002433 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2434 ARM_AM::ShiftOpc ShiftTy,
2435 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002436 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002437 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002438 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002439 Op->PostIdxReg.isAdd = isAdd;
2440 Op->PostIdxReg.ShiftTy = ShiftTy;
2441 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002442 Op->StartLoc = S;
2443 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002444 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002445 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002446
2447 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002448 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002449 Op->MBOpt.Val = Opt;
2450 Op->StartLoc = S;
2451 Op->EndLoc = S;
2452 return Op;
2453 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002454
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002455 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2456 SMLoc S) {
2457 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2458 Op->ISBOpt.Val = Opt;
2459 Op->StartLoc = S;
2460 Op->EndLoc = S;
2461 return Op;
2462 }
2463
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002464 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002465 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002466 Op->IFlags.Val = IFlags;
2467 Op->StartLoc = S;
2468 Op->EndLoc = S;
2469 return Op;
2470 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002471
2472 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002473 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002474 Op->MMask.Val = MMask;
2475 Op->StartLoc = S;
2476 Op->EndLoc = S;
2477 return Op;
2478 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002479};
2480
2481} // end anonymous namespace.
2482
Jim Grosbach602aa902011-07-13 15:34:57 +00002483void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002484 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002485 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002486 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002487 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002488 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002489 OS << "<ccout " << getReg() << ">";
2490 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002491 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002492 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002493 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2494 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2495 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002496 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2497 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2498 break;
2499 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002500 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002501 OS << "<coprocessor number: " << getCoproc() << ">";
2502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002503 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002504 OS << "<coprocessor register: " << getCoproc() << ">";
2505 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002506 case k_CoprocOption:
2507 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002509 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002510 OS << "<mask: " << getMSRMask() << ">";
2511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002512 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002513 getImm()->print(OS);
2514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002515 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002516 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002517 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002518 case k_InstSyncBarrierOpt:
2519 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2520 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002521 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002522 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002523 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002524 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002525 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002526 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002527 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2528 << PostIdxReg.RegNum;
2529 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2530 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2531 << PostIdxReg.ShiftImm;
2532 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002533 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002534 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002535 OS << "<ARM_PROC::";
2536 unsigned IFlags = getProcIFlags();
2537 for (int i=2; i >= 0; --i)
2538 if (IFlags & (1 << i))
2539 OS << ARM_PROC::IFlagsToString(1 << i);
2540 OS << ">";
2541 break;
2542 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002544 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002545 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002546 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002547 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2548 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002549 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002550 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002551 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002552 << RegShiftedReg.SrcReg << " "
2553 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2554 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002555 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002556 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002557 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002558 << RegShiftedImm.SrcReg << " "
2559 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2560 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002561 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002562 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002563 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2564 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002565 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002566 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2567 << ", width: " << Bitfield.Width << ">";
2568 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002569 case k_RegisterList:
2570 case k_DPRRegisterList:
2571 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002572 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002573
Bill Wendlingbed94652010-11-09 23:28:44 +00002574 const SmallVectorImpl<unsigned> &RegList = getRegList();
2575 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002576 I = RegList.begin(), E = RegList.end(); I != E; ) {
2577 OS << *I;
2578 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002579 }
2580
2581 OS << ">";
2582 break;
2583 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002584 case k_VectorList:
2585 OS << "<vector_list " << VectorList.Count << " * "
2586 << VectorList.RegNum << ">";
2587 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002588 case k_VectorListAllLanes:
2589 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2590 << VectorList.RegNum << ">";
2591 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002592 case k_VectorListIndexed:
2593 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2594 << VectorList.Count << " * " << VectorList.RegNum << ">";
2595 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002596 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002597 OS << "'" << getToken() << "'";
2598 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002599 case k_VectorIndex:
2600 OS << "<vectorindex " << getVectorIndex() << ">";
2601 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002602 }
2603}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002604
2605/// @name Auto-generated Match Functions
2606/// {
2607
2608static unsigned MatchRegisterName(StringRef Name);
2609
2610/// }
2611
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002612bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2613 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002614 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002615 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002616 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002617
2618 return (RegNo == (unsigned)-1);
2619}
2620
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002621/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002622/// and if it is a register name the token is eaten and the register number is
2623/// returned. Otherwise return -1.
2624///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002625int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002626 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002627 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002628
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002629 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002630 unsigned RegNum = MatchRegisterName(lowerCase);
2631 if (!RegNum) {
2632 RegNum = StringSwitch<unsigned>(lowerCase)
2633 .Case("r13", ARM::SP)
2634 .Case("r14", ARM::LR)
2635 .Case("r15", ARM::PC)
2636 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002637 // Additional register name aliases for 'gas' compatibility.
2638 .Case("a1", ARM::R0)
2639 .Case("a2", ARM::R1)
2640 .Case("a3", ARM::R2)
2641 .Case("a4", ARM::R3)
2642 .Case("v1", ARM::R4)
2643 .Case("v2", ARM::R5)
2644 .Case("v3", ARM::R6)
2645 .Case("v4", ARM::R7)
2646 .Case("v5", ARM::R8)
2647 .Case("v6", ARM::R9)
2648 .Case("v7", ARM::R10)
2649 .Case("v8", ARM::R11)
2650 .Case("sb", ARM::R9)
2651 .Case("sl", ARM::R10)
2652 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002653 .Default(0);
2654 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002655 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002656 // Check for aliases registered via .req. Canonicalize to lower case.
2657 // That's more consistent since register names are case insensitive, and
2658 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2659 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002660 // If no match, return failure.
2661 if (Entry == RegisterReqs.end())
2662 return -1;
2663 Parser.Lex(); // Eat identifier token.
2664 return Entry->getValue();
2665 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002666
Chris Lattner44e5981c2010-10-30 04:09:10 +00002667 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002668
Chris Lattner44e5981c2010-10-30 04:09:10 +00002669 return RegNum;
2670}
Jim Grosbach99710a82010-11-01 16:44:21 +00002671
Jim Grosbachbb24c592011-07-13 18:49:30 +00002672// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2673// If a recoverable error occurs, return 1. If an irrecoverable error
2674// occurs, return -1. An irrecoverable error is one where tokens have been
2675// consumed in the process of trying to parse the shifter (i.e., when it is
2676// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002677int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002678 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2679 SMLoc S = Parser.getTok().getLoc();
2680 const AsmToken &Tok = Parser.getTok();
2681 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2682
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002683 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002684 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002685 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002686 .Case("lsl", ARM_AM::lsl)
2687 .Case("lsr", ARM_AM::lsr)
2688 .Case("asr", ARM_AM::asr)
2689 .Case("ror", ARM_AM::ror)
2690 .Case("rrx", ARM_AM::rrx)
2691 .Default(ARM_AM::no_shift);
2692
2693 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002694 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002695
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002696 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002697
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002698 // The source register for the shift has already been added to the
2699 // operand list, so we need to pop it off and combine it into the shifted
2700 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002701 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002702 if (!PrevOp->isReg())
2703 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2704 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002705
2706 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002707 int64_t Imm = 0;
2708 int ShiftReg = 0;
2709 if (ShiftTy == ARM_AM::rrx) {
2710 // RRX Doesn't have an explicit shift amount. The encoder expects
2711 // the shift register to be the same as the source register. Seems odd,
2712 // but OK.
2713 ShiftReg = SrcReg;
2714 } else {
2715 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002716 if (Parser.getTok().is(AsmToken::Hash) ||
2717 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002718 Parser.Lex(); // Eat hash.
2719 SMLoc ImmLoc = Parser.getTok().getLoc();
2720 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002721 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002722 Error(ImmLoc, "invalid immediate shift value");
2723 return -1;
2724 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002725 // The expression must be evaluatable as an immediate.
2726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002727 if (!CE) {
2728 Error(ImmLoc, "invalid immediate shift value");
2729 return -1;
2730 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002731 // Range check the immediate.
2732 // lsl, ror: 0 <= imm <= 31
2733 // lsr, asr: 0 <= imm <= 32
2734 Imm = CE->getValue();
2735 if (Imm < 0 ||
2736 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2737 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002738 Error(ImmLoc, "immediate shift value out of range");
2739 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002740 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002741 // shift by zero is a nop. Always send it through as lsl.
2742 // ('as' compatibility)
2743 if (Imm == 0)
2744 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002745 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002746 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002747 EndLoc = Parser.getTok().getEndLoc();
2748 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002749 if (ShiftReg == -1) {
2750 Error (L, "expected immediate or register in shift operand");
2751 return -1;
2752 }
2753 } else {
2754 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002755 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002756 return -1;
2757 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002758 }
2759
Owen Andersonb595ed02011-07-21 18:54:16 +00002760 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2761 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002762 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002763 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002764 else
2765 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002766 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002767
Jim Grosbachbb24c592011-07-13 18:49:30 +00002768 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002769}
2770
2771
Bill Wendling2063b842010-11-18 23:43:05 +00002772/// Try to parse a register name. The token must be an Identifier when called.
2773/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2774/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002775///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002776/// TODO this is likely to change to allow different register types and or to
2777/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002778bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002779tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002780 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002781 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002782 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002783 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002784
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002785 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2786 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002787
Chris Lattner44e5981c2010-10-30 04:09:10 +00002788 const AsmToken &ExclaimTok = Parser.getTok();
2789 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002790 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2791 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002792 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002793 return false;
2794 }
2795
2796 // Also check for an index operand. This is only legal for vector registers,
2797 // but that'll get caught OK in operand matching, so we don't need to
2798 // explicitly filter everything else out here.
2799 if (Parser.getTok().is(AsmToken::LBrac)) {
2800 SMLoc SIdx = Parser.getTok().getLoc();
2801 Parser.Lex(); // Eat left bracket token.
2802
2803 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002804 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002805 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002806 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002807 if (!MCE)
2808 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002809
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002810 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002811 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002812
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002813 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002814 Parser.Lex(); // Eat right bracket token.
2815
2816 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2817 SIdx, E,
2818 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002819 }
2820
Bill Wendling2063b842010-11-18 23:43:05 +00002821 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002822}
2823
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002824/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2825/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2826/// "c5", ...
2827static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002828 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2829 // but efficient.
2830 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002831 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002832 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002833 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002834 return -1;
2835 switch (Name[1]) {
2836 default: return -1;
2837 case '0': return 0;
2838 case '1': return 1;
2839 case '2': return 2;
2840 case '3': return 3;
2841 case '4': return 4;
2842 case '5': return 5;
2843 case '6': return 6;
2844 case '7': return 7;
2845 case '8': return 8;
2846 case '9': return 9;
2847 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002848 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002849 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002850 return -1;
2851 switch (Name[2]) {
2852 default: return -1;
2853 case '0': return 10;
2854 case '1': return 11;
2855 case '2': return 12;
2856 case '3': return 13;
2857 case '4': return 14;
2858 case '5': return 15;
2859 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002860 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002861}
2862
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002863/// parseITCondCode - Try to parse a condition code for an IT instruction.
2864ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2865parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2866 SMLoc S = Parser.getTok().getLoc();
2867 const AsmToken &Tok = Parser.getTok();
2868 if (!Tok.is(AsmToken::Identifier))
2869 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002870 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002871 .Case("eq", ARMCC::EQ)
2872 .Case("ne", ARMCC::NE)
2873 .Case("hs", ARMCC::HS)
2874 .Case("cs", ARMCC::HS)
2875 .Case("lo", ARMCC::LO)
2876 .Case("cc", ARMCC::LO)
2877 .Case("mi", ARMCC::MI)
2878 .Case("pl", ARMCC::PL)
2879 .Case("vs", ARMCC::VS)
2880 .Case("vc", ARMCC::VC)
2881 .Case("hi", ARMCC::HI)
2882 .Case("ls", ARMCC::LS)
2883 .Case("ge", ARMCC::GE)
2884 .Case("lt", ARMCC::LT)
2885 .Case("gt", ARMCC::GT)
2886 .Case("le", ARMCC::LE)
2887 .Case("al", ARMCC::AL)
2888 .Default(~0U);
2889 if (CC == ~0U)
2890 return MatchOperand_NoMatch;
2891 Parser.Lex(); // Eat the token.
2892
2893 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2894
2895 return MatchOperand_Success;
2896}
2897
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002898/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002899/// token must be an Identifier when called, and if it is a coprocessor
2900/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002901ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002902parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002903 SMLoc S = Parser.getTok().getLoc();
2904 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002905 if (Tok.isNot(AsmToken::Identifier))
2906 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002907
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002908 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002909 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002910 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002911
2912 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002913 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002914 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002915}
2916
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002917/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002918/// token must be an Identifier when called, and if it is a coprocessor
2919/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002920ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002921parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002922 SMLoc S = Parser.getTok().getLoc();
2923 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002924 if (Tok.isNot(AsmToken::Identifier))
2925 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002926
2927 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2928 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002929 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002930
2931 Parser.Lex(); // Eat identifier token.
2932 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002933 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002934}
2935
Jim Grosbach48399582011-10-12 17:34:41 +00002936/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2937/// coproc_option : '{' imm0_255 '}'
2938ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2939parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2940 SMLoc S = Parser.getTok().getLoc();
2941
2942 // If this isn't a '{', this isn't a coprocessor immediate operand.
2943 if (Parser.getTok().isNot(AsmToken::LCurly))
2944 return MatchOperand_NoMatch;
2945 Parser.Lex(); // Eat the '{'
2946
2947 const MCExpr *Expr;
2948 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002949 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002950 Error(Loc, "illegal expression");
2951 return MatchOperand_ParseFail;
2952 }
2953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2954 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2955 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2956 return MatchOperand_ParseFail;
2957 }
2958 int Val = CE->getValue();
2959
2960 // Check for and consume the closing '}'
2961 if (Parser.getTok().isNot(AsmToken::RCurly))
2962 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002963 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002964 Parser.Lex(); // Eat the '}'
2965
2966 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2967 return MatchOperand_Success;
2968}
2969
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002970// For register list parsing, we need to map from raw GPR register numbering
2971// to the enumeration values. The enumeration values aren't sorted by
2972// register number due to our using "sp", "lr" and "pc" as canonical names.
2973static unsigned getNextRegister(unsigned Reg) {
2974 // If this is a GPR, we need to do it manually, otherwise we can rely
2975 // on the sort ordering of the enumeration since the other reg-classes
2976 // are sane.
2977 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2978 return Reg + 1;
2979 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002980 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002981 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2982 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2983 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2984 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2985 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2986 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2987 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2988 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2989 }
2990}
2991
Jim Grosbach85a23432011-11-11 21:27:40 +00002992// Return the low-subreg of a given Q register.
2993static unsigned getDRegFromQReg(unsigned QReg) {
2994 switch (QReg) {
2995 default: llvm_unreachable("expected a Q register!");
2996 case ARM::Q0: return ARM::D0;
2997 case ARM::Q1: return ARM::D2;
2998 case ARM::Q2: return ARM::D4;
2999 case ARM::Q3: return ARM::D6;
3000 case ARM::Q4: return ARM::D8;
3001 case ARM::Q5: return ARM::D10;
3002 case ARM::Q6: return ARM::D12;
3003 case ARM::Q7: return ARM::D14;
3004 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003005 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003006 case ARM::Q10: return ARM::D20;
3007 case ARM::Q11: return ARM::D22;
3008 case ARM::Q12: return ARM::D24;
3009 case ARM::Q13: return ARM::D26;
3010 case ARM::Q14: return ARM::D28;
3011 case ARM::Q15: return ARM::D30;
3012 }
3013}
3014
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003015/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003016bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003017parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003018 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003019 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003020 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003021 Parser.Lex(); // Eat '{' token.
3022 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003023
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003024 // Check the first register in the list to see what register class
3025 // this is a list of.
3026 int Reg = tryParseRegister();
3027 if (Reg == -1)
3028 return Error(RegLoc, "register expected");
3029
Jim Grosbach85a23432011-11-11 21:27:40 +00003030 // The reglist instructions have at most 16 registers, so reserve
3031 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003032 int EReg = 0;
3033 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003034
3035 // Allow Q regs and just interpret them as the two D sub-registers.
3036 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3037 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003038 EReg = MRI->getEncodingValue(Reg);
3039 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003040 ++Reg;
3041 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003042 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003043 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3044 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3045 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3046 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3047 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3048 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3049 else
3050 return Error(RegLoc, "invalid register in register list");
3051
Jim Grosbach85a23432011-11-11 21:27:40 +00003052 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003053 EReg = MRI->getEncodingValue(Reg);
3054 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003055
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003056 // This starts immediately after the first register token in the list,
3057 // so we can see either a comma or a minus (range separator) as a legal
3058 // next token.
3059 while (Parser.getTok().is(AsmToken::Comma) ||
3060 Parser.getTok().is(AsmToken::Minus)) {
3061 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003062 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003063 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003064 int EndReg = tryParseRegister();
3065 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003066 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003067 // Allow Q regs and just interpret them as the two D sub-registers.
3068 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3069 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003070 // If the register is the same as the start reg, there's nothing
3071 // more to do.
3072 if (Reg == EndReg)
3073 continue;
3074 // The register must be in the same register class as the first.
3075 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003076 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003077 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003078 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003079 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003080
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003081 // Add all the registers in the range to the register list.
3082 while (Reg != EndReg) {
3083 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003084 EReg = MRI->getEncodingValue(Reg);
3085 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003086 }
3087 continue;
3088 }
3089 Parser.Lex(); // Eat the comma.
3090 RegLoc = Parser.getTok().getLoc();
3091 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003092 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003093 Reg = tryParseRegister();
3094 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003095 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003096 // Allow Q regs and just interpret them as the two D sub-registers.
3097 bool isQReg = false;
3098 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3099 Reg = getDRegFromQReg(Reg);
3100 isQReg = true;
3101 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003102 // The register must be in the same register class as the first.
3103 if (!RC->contains(Reg))
3104 return Error(RegLoc, "invalid register in register list");
3105 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003106 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003107 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3108 Warning(RegLoc, "register list not in ascending order");
3109 else
3110 return Error(RegLoc, "register list not in ascending order");
3111 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003112 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003113 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3114 ") in register list");
3115 continue;
3116 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003117 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003118 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3119 Reg != OldReg + 1)
3120 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003121 EReg = MRI->getEncodingValue(Reg);
3122 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3123 if (isQReg) {
3124 EReg = MRI->getEncodingValue(++Reg);
3125 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3126 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003127 }
3128
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003129 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003130 return Error(Parser.getTok().getLoc(), "'}' expected");
3131 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003132 Parser.Lex(); // Eat '}' token.
3133
Jim Grosbach18bf3632011-12-13 21:48:29 +00003134 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003135 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003136
3137 // The ARM system instruction variants for LDM/STM have a '^' token here.
3138 if (Parser.getTok().is(AsmToken::Caret)) {
3139 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3140 Parser.Lex(); // Eat '^' token.
3141 }
3142
Bill Wendling2063b842010-11-18 23:43:05 +00003143 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003144}
3145
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003146// Helper function to parse the lane index for vector lists.
3147ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003148parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003149 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003150 if (Parser.getTok().is(AsmToken::LBrac)) {
3151 Parser.Lex(); // Eat the '['.
3152 if (Parser.getTok().is(AsmToken::RBrac)) {
3153 // "Dn[]" is the 'all lanes' syntax.
3154 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003155 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156 Parser.Lex(); // Eat the ']'.
3157 return MatchOperand_Success;
3158 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003159
3160 // There's an optional '#' token here. Normally there wouldn't be, but
3161 // inline assemble puts one in, and it's friendly to accept that.
3162 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003163 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003164
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003165 const MCExpr *LaneIndex;
3166 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003167 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003168 Error(Loc, "illegal expression");
3169 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003170 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003171 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3172 if (!CE) {
3173 Error(Loc, "lane index must be empty or an integer");
3174 return MatchOperand_ParseFail;
3175 }
3176 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3177 Error(Parser.getTok().getLoc(), "']' expected");
3178 return MatchOperand_ParseFail;
3179 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003180 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003181 Parser.Lex(); // Eat the ']'.
3182 int64_t Val = CE->getValue();
3183
3184 // FIXME: Make this range check context sensitive for .8, .16, .32.
3185 if (Val < 0 || Val > 7) {
3186 Error(Parser.getTok().getLoc(), "lane index out of range");
3187 return MatchOperand_ParseFail;
3188 }
3189 Index = Val;
3190 LaneKind = IndexedLane;
3191 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003192 }
3193 LaneKind = NoLanes;
3194 return MatchOperand_Success;
3195}
3196
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003197// parse a vector register list
3198ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3199parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003200 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003201 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003202 SMLoc S = Parser.getTok().getLoc();
3203 // As an extension (to match gas), support a plain D register or Q register
3204 // (without encosing curly braces) as a single or double entry list,
3205 // respectively.
3206 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003207 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003208 int Reg = tryParseRegister();
3209 if (Reg == -1)
3210 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003211 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003212 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003213 if (Res != MatchOperand_Success)
3214 return Res;
3215 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003216 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003217 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 break;
3219 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003220 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3221 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003222 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003223 case IndexedLane:
3224 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003225 LaneIndex,
3226 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003227 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003229 return MatchOperand_Success;
3230 }
3231 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3232 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003233 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003234 if (Res != MatchOperand_Success)
3235 return Res;
3236 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003237 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003238 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003239 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003240 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003241 break;
3242 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003243 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3244 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003245 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3246 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003247 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003248 case IndexedLane:
3249 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003250 LaneIndex,
3251 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003252 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003253 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003254 return MatchOperand_Success;
3255 }
3256 Error(S, "vector register expected");
3257 return MatchOperand_ParseFail;
3258 }
3259
3260 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003261 return MatchOperand_NoMatch;
3262
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003263 Parser.Lex(); // Eat '{' token.
3264 SMLoc RegLoc = Parser.getTok().getLoc();
3265
3266 int Reg = tryParseRegister();
3267 if (Reg == -1) {
3268 Error(RegLoc, "register expected");
3269 return MatchOperand_ParseFail;
3270 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003271 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003272 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003273 unsigned FirstReg = Reg;
3274 // The list is of D registers, but we also allow Q regs and just interpret
3275 // them as the two D sub-registers.
3276 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3277 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003278 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3279 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003280 ++Reg;
3281 ++Count;
3282 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003283
3284 SMLoc E;
3285 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003286 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003287
Jim Grosbache891fe82011-11-15 23:19:15 +00003288 while (Parser.getTok().is(AsmToken::Comma) ||
3289 Parser.getTok().is(AsmToken::Minus)) {
3290 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003291 if (!Spacing)
3292 Spacing = 1; // Register range implies a single spaced list.
3293 else if (Spacing == 2) {
3294 Error(Parser.getTok().getLoc(),
3295 "sequential registers in double spaced list");
3296 return MatchOperand_ParseFail;
3297 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003298 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003299 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003300 int EndReg = tryParseRegister();
3301 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003302 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003303 return MatchOperand_ParseFail;
3304 }
3305 // Allow Q regs and just interpret them as the two D sub-registers.
3306 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3307 EndReg = getDRegFromQReg(EndReg) + 1;
3308 // If the register is the same as the start reg, there's nothing
3309 // more to do.
3310 if (Reg == EndReg)
3311 continue;
3312 // The register must be in the same register class as the first.
3313 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003314 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003315 return MatchOperand_ParseFail;
3316 }
3317 // Ranges must go from low to high.
3318 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003319 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003320 return MatchOperand_ParseFail;
3321 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003322 // Parse the lane specifier if present.
3323 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003324 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003325 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3326 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003327 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003328 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003329 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003330 return MatchOperand_ParseFail;
3331 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003332
3333 // Add all the registers in the range to the register list.
3334 Count += EndReg - Reg;
3335 Reg = EndReg;
3336 continue;
3337 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003338 Parser.Lex(); // Eat the comma.
3339 RegLoc = Parser.getTok().getLoc();
3340 int OldReg = Reg;
3341 Reg = tryParseRegister();
3342 if (Reg == -1) {
3343 Error(RegLoc, "register expected");
3344 return MatchOperand_ParseFail;
3345 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003346 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003347 // It's OK to use the enumeration values directly here rather, as the
3348 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003349 //
3350 // The list is of D registers, but we also allow Q regs and just interpret
3351 // them as the two D sub-registers.
3352 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003353 if (!Spacing)
3354 Spacing = 1; // Register range implies a single spaced list.
3355 else if (Spacing == 2) {
3356 Error(RegLoc,
3357 "invalid register in double-spaced list (must be 'D' register')");
3358 return MatchOperand_ParseFail;
3359 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003360 Reg = getDRegFromQReg(Reg);
3361 if (Reg != OldReg + 1) {
3362 Error(RegLoc, "non-contiguous register range");
3363 return MatchOperand_ParseFail;
3364 }
3365 ++Reg;
3366 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003367 // Parse the lane specifier if present.
3368 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003369 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003370 SMLoc LaneLoc = Parser.getTok().getLoc();
3371 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3372 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003373 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003374 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003375 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 return MatchOperand_ParseFail;
3377 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003378 continue;
3379 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003380 // Normal D register.
3381 // Figure out the register spacing (single or double) of the list if
3382 // we don't know it already.
3383 if (!Spacing)
3384 Spacing = 1 + (Reg == OldReg + 2);
3385
3386 // Just check that it's contiguous and keep going.
3387 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003388 Error(RegLoc, "non-contiguous register range");
3389 return MatchOperand_ParseFail;
3390 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003391 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003392 // Parse the lane specifier if present.
3393 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003394 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003395 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003396 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003397 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003398 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003399 Error(EndLoc, "mismatched lane index in register list");
3400 return MatchOperand_ParseFail;
3401 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003402 }
3403
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003404 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003405 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003406 return MatchOperand_ParseFail;
3407 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003408 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003409 Parser.Lex(); // Eat '}' token.
3410
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003411 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003412 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003413 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003414 // composite register classes.
3415 if (Count == 2) {
3416 const MCRegisterClass *RC = (Spacing == 1) ?
3417 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3418 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3419 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3420 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003421
Jim Grosbach2f50e922011-12-15 21:44:33 +00003422 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3423 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003424 break;
3425 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003426 // Two-register operands have been converted to the
3427 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003428 if (Count == 2) {
3429 const MCRegisterClass *RC = (Spacing == 1) ?
3430 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3431 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003432 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3433 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003434 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003435 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003436 S, E));
3437 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003438 case IndexedLane:
3439 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003440 LaneIndex,
3441 (Spacing == 2),
3442 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003443 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003444 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003445 return MatchOperand_Success;
3446}
3447
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003448/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003449ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003450parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003451 SMLoc S = Parser.getTok().getLoc();
3452 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003453 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003454
Jiangning Liu288e1af2012-08-02 08:21:27 +00003455 if (Tok.is(AsmToken::Identifier)) {
3456 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003457
Jiangning Liu288e1af2012-08-02 08:21:27 +00003458 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3459 .Case("sy", ARM_MB::SY)
3460 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003461 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003462 .Case("sh", ARM_MB::ISH)
3463 .Case("ish", ARM_MB::ISH)
3464 .Case("shst", ARM_MB::ISHST)
3465 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003466 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003467 .Case("nsh", ARM_MB::NSH)
3468 .Case("un", ARM_MB::NSH)
3469 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003470 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003471 .Case("unst", ARM_MB::NSHST)
3472 .Case("osh", ARM_MB::OSH)
3473 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003474 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003475 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003476
Joey Gouly926d3f52013-09-05 15:35:24 +00003477 // ishld, oshld, nshld and ld are only available from ARMv8.
3478 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3479 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3480 Opt = ~0U;
3481
Jiangning Liu288e1af2012-08-02 08:21:27 +00003482 if (Opt == ~0U)
3483 return MatchOperand_NoMatch;
3484
3485 Parser.Lex(); // Eat identifier token.
3486 } else if (Tok.is(AsmToken::Hash) ||
3487 Tok.is(AsmToken::Dollar) ||
3488 Tok.is(AsmToken::Integer)) {
3489 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003490 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003491 SMLoc Loc = Parser.getTok().getLoc();
3492
3493 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003494 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003495 Error(Loc, "illegal expression");
3496 return MatchOperand_ParseFail;
3497 }
3498
3499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3500 if (!CE) {
3501 Error(Loc, "constant expression expected");
3502 return MatchOperand_ParseFail;
3503 }
3504
3505 int Val = CE->getValue();
3506 if (Val & ~0xf) {
3507 Error(Loc, "immediate value out of range");
3508 return MatchOperand_ParseFail;
3509 }
3510
3511 Opt = ARM_MB::RESERVED_0 + Val;
3512 } else
3513 return MatchOperand_ParseFail;
3514
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003515 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003516 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003517}
3518
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003519/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3520ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3521parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3522 SMLoc S = Parser.getTok().getLoc();
3523 const AsmToken &Tok = Parser.getTok();
3524 unsigned Opt;
3525
3526 if (Tok.is(AsmToken::Identifier)) {
3527 StringRef OptStr = Tok.getString();
3528
3529 if (OptStr.lower() == "sy")
3530 Opt = ARM_ISB::SY;
3531 else
3532 return MatchOperand_NoMatch;
3533
3534 Parser.Lex(); // Eat identifier token.
3535 } else if (Tok.is(AsmToken::Hash) ||
3536 Tok.is(AsmToken::Dollar) ||
3537 Tok.is(AsmToken::Integer)) {
3538 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003539 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003540 SMLoc Loc = Parser.getTok().getLoc();
3541
3542 const MCExpr *ISBarrierID;
3543 if (getParser().parseExpression(ISBarrierID)) {
3544 Error(Loc, "illegal expression");
3545 return MatchOperand_ParseFail;
3546 }
3547
3548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3549 if (!CE) {
3550 Error(Loc, "constant expression expected");
3551 return MatchOperand_ParseFail;
3552 }
3553
3554 int Val = CE->getValue();
3555 if (Val & ~0xf) {
3556 Error(Loc, "immediate value out of range");
3557 return MatchOperand_ParseFail;
3558 }
3559
3560 Opt = ARM_ISB::RESERVED_0 + Val;
3561 } else
3562 return MatchOperand_ParseFail;
3563
3564 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3565 (ARM_ISB::InstSyncBOpt)Opt, S));
3566 return MatchOperand_Success;
3567}
3568
3569
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003570/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003571ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003572parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003573 SMLoc S = Parser.getTok().getLoc();
3574 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003575 if (!Tok.is(AsmToken::Identifier))
3576 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003577 StringRef IFlagsStr = Tok.getString();
3578
Owen Anderson10c5b122011-10-05 17:16:40 +00003579 // An iflags string of "none" is interpreted to mean that none of the AIF
3580 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003581 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003582 if (IFlagsStr != "none") {
3583 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3584 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3585 .Case("a", ARM_PROC::A)
3586 .Case("i", ARM_PROC::I)
3587 .Case("f", ARM_PROC::F)
3588 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003589
Owen Anderson10c5b122011-10-05 17:16:40 +00003590 // If some specific iflag is already set, it means that some letter is
3591 // present more than once, this is not acceptable.
3592 if (Flag == ~0U || (IFlags & Flag))
3593 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003594
Owen Anderson10c5b122011-10-05 17:16:40 +00003595 IFlags |= Flag;
3596 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003597 }
3598
3599 Parser.Lex(); // Eat identifier token.
3600 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3601 return MatchOperand_Success;
3602}
3603
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003604/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003605ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003606parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003607 SMLoc S = Parser.getTok().getLoc();
3608 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003609 if (!Tok.is(AsmToken::Identifier))
3610 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003611 StringRef Mask = Tok.getString();
3612
James Molloy21efa7d2011-09-28 14:21:38 +00003613 if (isMClass()) {
3614 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003615 std::string Name = Mask.lower();
3616 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003617 // Note: in the documentation:
3618 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3619 // for MSR APSR_nzcvq.
3620 // but we do make it an alias here. This is so to get the "mask encoding"
3621 // bits correct on MSR APSR writes.
3622 //
3623 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3624 // should really only be allowed when writing a special register. Note
3625 // they get dropped in the MRS instruction reading a special register as
3626 // the SYSm field is only 8 bits.
3627 //
3628 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3629 // includes the DSP extension but that is not checked.
3630 .Case("apsr", 0x800)
3631 .Case("apsr_nzcvq", 0x800)
3632 .Case("apsr_g", 0x400)
3633 .Case("apsr_nzcvqg", 0xc00)
3634 .Case("iapsr", 0x801)
3635 .Case("iapsr_nzcvq", 0x801)
3636 .Case("iapsr_g", 0x401)
3637 .Case("iapsr_nzcvqg", 0xc01)
3638 .Case("eapsr", 0x802)
3639 .Case("eapsr_nzcvq", 0x802)
3640 .Case("eapsr_g", 0x402)
3641 .Case("eapsr_nzcvqg", 0xc02)
3642 .Case("xpsr", 0x803)
3643 .Case("xpsr_nzcvq", 0x803)
3644 .Case("xpsr_g", 0x403)
3645 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003646 .Case("ipsr", 0x805)
3647 .Case("epsr", 0x806)
3648 .Case("iepsr", 0x807)
3649 .Case("msp", 0x808)
3650 .Case("psp", 0x809)
3651 .Case("primask", 0x810)
3652 .Case("basepri", 0x811)
3653 .Case("basepri_max", 0x812)
3654 .Case("faultmask", 0x813)
3655 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003656 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003657
James Molloy21efa7d2011-09-28 14:21:38 +00003658 if (FlagsVal == ~0U)
3659 return MatchOperand_NoMatch;
3660
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003661 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003662 // basepri, basepri_max and faultmask only valid for V7m.
3663 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003664
James Molloy21efa7d2011-09-28 14:21:38 +00003665 Parser.Lex(); // Eat identifier token.
3666 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3667 return MatchOperand_Success;
3668 }
3669
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003670 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3671 size_t Start = 0, Next = Mask.find('_');
3672 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003673 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003674 if (Next != StringRef::npos)
3675 Flags = Mask.slice(Next+1, Mask.size());
3676
3677 // FlagsVal contains the complete mask:
3678 // 3-0: Mask
3679 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3680 unsigned FlagsVal = 0;
3681
3682 if (SpecReg == "apsr") {
3683 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003684 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003685 .Case("g", 0x4) // same as CPSR_s
3686 .Case("nzcvqg", 0xc) // same as CPSR_fs
3687 .Default(~0U);
3688
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003689 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003690 if (!Flags.empty())
3691 return MatchOperand_NoMatch;
3692 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003693 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003694 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003695 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003696 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3697 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003698 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003699 for (int i = 0, e = Flags.size(); i != e; ++i) {
3700 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3701 .Case("c", 1)
3702 .Case("x", 2)
3703 .Case("s", 4)
3704 .Case("f", 8)
3705 .Default(~0U);
3706
3707 // If some specific flag is already set, it means that some letter is
3708 // present more than once, this is not acceptable.
3709 if (FlagsVal == ~0U || (FlagsVal & Flag))
3710 return MatchOperand_NoMatch;
3711 FlagsVal |= Flag;
3712 }
3713 } else // No match for special register.
3714 return MatchOperand_NoMatch;
3715
Owen Anderson03a173e2011-10-21 18:43:28 +00003716 // Special register without flags is NOT equivalent to "fc" flags.
3717 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3718 // two lines would enable gas compatibility at the expense of breaking
3719 // round-tripping.
3720 //
3721 // if (!FlagsVal)
3722 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003723
3724 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3725 if (SpecReg == "spsr")
3726 FlagsVal |= 16;
3727
3728 Parser.Lex(); // Eat identifier token.
3729 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3730 return MatchOperand_Success;
3731}
3732
Jim Grosbach27c1e252011-07-21 17:23:04 +00003733ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3734parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3735 int Low, int High) {
3736 const AsmToken &Tok = Parser.getTok();
3737 if (Tok.isNot(AsmToken::Identifier)) {
3738 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3739 return MatchOperand_ParseFail;
3740 }
3741 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003742 std::string LowerOp = Op.lower();
3743 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003744 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3745 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3746 return MatchOperand_ParseFail;
3747 }
3748 Parser.Lex(); // Eat shift type token.
3749
3750 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003751 if (Parser.getTok().isNot(AsmToken::Hash) &&
3752 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003753 Error(Parser.getTok().getLoc(), "'#' expected");
3754 return MatchOperand_ParseFail;
3755 }
3756 Parser.Lex(); // Eat hash token.
3757
3758 const MCExpr *ShiftAmount;
3759 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003760 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003761 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003762 Error(Loc, "illegal expression");
3763 return MatchOperand_ParseFail;
3764 }
3765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3766 if (!CE) {
3767 Error(Loc, "constant expression expected");
3768 return MatchOperand_ParseFail;
3769 }
3770 int Val = CE->getValue();
3771 if (Val < Low || Val > High) {
3772 Error(Loc, "immediate value out of range");
3773 return MatchOperand_ParseFail;
3774 }
3775
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003776 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003777
3778 return MatchOperand_Success;
3779}
3780
Jim Grosbach0a547702011-07-22 17:44:50 +00003781ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3782parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3783 const AsmToken &Tok = Parser.getTok();
3784 SMLoc S = Tok.getLoc();
3785 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003786 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003787 return MatchOperand_ParseFail;
3788 }
Tim Northover4d141442013-05-31 15:58:45 +00003789 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003790 .Case("be", 1)
3791 .Case("le", 0)
3792 .Default(-1);
3793 Parser.Lex(); // Eat the token.
3794
3795 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003796 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003797 return MatchOperand_ParseFail;
3798 }
3799 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3800 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003801 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003802 return MatchOperand_Success;
3803}
3804
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003805/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3806/// instructions. Legal values are:
3807/// lsl #n 'n' in [0,31]
3808/// asr #n 'n' in [1,32]
3809/// n == 32 encoded as n == 0.
3810ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3811parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3812 const AsmToken &Tok = Parser.getTok();
3813 SMLoc S = Tok.getLoc();
3814 if (Tok.isNot(AsmToken::Identifier)) {
3815 Error(S, "shift operator 'asr' or 'lsl' expected");
3816 return MatchOperand_ParseFail;
3817 }
3818 StringRef ShiftName = Tok.getString();
3819 bool isASR;
3820 if (ShiftName == "lsl" || ShiftName == "LSL")
3821 isASR = false;
3822 else if (ShiftName == "asr" || ShiftName == "ASR")
3823 isASR = true;
3824 else {
3825 Error(S, "shift operator 'asr' or 'lsl' expected");
3826 return MatchOperand_ParseFail;
3827 }
3828 Parser.Lex(); // Eat the operator.
3829
3830 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003831 if (Parser.getTok().isNot(AsmToken::Hash) &&
3832 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003833 Error(Parser.getTok().getLoc(), "'#' expected");
3834 return MatchOperand_ParseFail;
3835 }
3836 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003837 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003838
3839 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003840 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003841 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003842 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003843 return MatchOperand_ParseFail;
3844 }
3845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3846 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003847 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003848 return MatchOperand_ParseFail;
3849 }
3850
3851 int64_t Val = CE->getValue();
3852 if (isASR) {
3853 // Shift amount must be in [1,32]
3854 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003855 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003856 return MatchOperand_ParseFail;
3857 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003858 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3859 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003860 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003861 return MatchOperand_ParseFail;
3862 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003863 if (Val == 32) Val = 0;
3864 } else {
3865 // Shift amount must be in [1,32]
3866 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003867 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003868 return MatchOperand_ParseFail;
3869 }
3870 }
3871
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003872 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003873
3874 return MatchOperand_Success;
3875}
3876
Jim Grosbach833b9d32011-07-27 20:15:40 +00003877/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3878/// of instructions. Legal values are:
3879/// ror #n 'n' in {0, 8, 16, 24}
3880ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3881parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3882 const AsmToken &Tok = Parser.getTok();
3883 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003884 if (Tok.isNot(AsmToken::Identifier))
3885 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003886 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003887 if (ShiftName != "ror" && ShiftName != "ROR")
3888 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003889 Parser.Lex(); // Eat the operator.
3890
3891 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003892 if (Parser.getTok().isNot(AsmToken::Hash) &&
3893 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003894 Error(Parser.getTok().getLoc(), "'#' expected");
3895 return MatchOperand_ParseFail;
3896 }
3897 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003898 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003899
3900 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003901 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003902 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003903 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003904 return MatchOperand_ParseFail;
3905 }
3906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3907 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003908 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003909 return MatchOperand_ParseFail;
3910 }
3911
3912 int64_t Val = CE->getValue();
3913 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3914 // normally, zero is represented in asm by omitting the rotate operand
3915 // entirely.
3916 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003917 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003918 return MatchOperand_ParseFail;
3919 }
3920
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003921 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003922
3923 return MatchOperand_Success;
3924}
3925
Jim Grosbach864b6092011-07-28 21:34:26 +00003926ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3927parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3928 SMLoc S = Parser.getTok().getLoc();
3929 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003930 if (Parser.getTok().isNot(AsmToken::Hash) &&
3931 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003932 Error(Parser.getTok().getLoc(), "'#' expected");
3933 return MatchOperand_ParseFail;
3934 }
3935 Parser.Lex(); // Eat hash token.
3936
3937 const MCExpr *LSBExpr;
3938 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003939 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003940 Error(E, "malformed immediate expression");
3941 return MatchOperand_ParseFail;
3942 }
3943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3944 if (!CE) {
3945 Error(E, "'lsb' operand must be an immediate");
3946 return MatchOperand_ParseFail;
3947 }
3948
3949 int64_t LSB = CE->getValue();
3950 // The LSB must be in the range [0,31]
3951 if (LSB < 0 || LSB > 31) {
3952 Error(E, "'lsb' operand must be in the range [0,31]");
3953 return MatchOperand_ParseFail;
3954 }
3955 E = Parser.getTok().getLoc();
3956
3957 // Expect another immediate operand.
3958 if (Parser.getTok().isNot(AsmToken::Comma)) {
3959 Error(Parser.getTok().getLoc(), "too few operands");
3960 return MatchOperand_ParseFail;
3961 }
3962 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003963 if (Parser.getTok().isNot(AsmToken::Hash) &&
3964 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003965 Error(Parser.getTok().getLoc(), "'#' expected");
3966 return MatchOperand_ParseFail;
3967 }
3968 Parser.Lex(); // Eat hash token.
3969
3970 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003971 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003972 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003973 Error(E, "malformed immediate expression");
3974 return MatchOperand_ParseFail;
3975 }
3976 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3977 if (!CE) {
3978 Error(E, "'width' operand must be an immediate");
3979 return MatchOperand_ParseFail;
3980 }
3981
3982 int64_t Width = CE->getValue();
3983 // The LSB must be in the range [1,32-lsb]
3984 if (Width < 1 || Width > 32 - LSB) {
3985 Error(E, "'width' operand must be in the range [1,32-lsb]");
3986 return MatchOperand_ParseFail;
3987 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003988
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003989 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003990
3991 return MatchOperand_Success;
3992}
3993
Jim Grosbachd3595712011-08-03 23:50:40 +00003994ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3995parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3996 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003997 // postidx_reg := '+' register {, shift}
3998 // | '-' register {, shift}
3999 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004000
4001 // This method must return MatchOperand_NoMatch without consuming any tokens
4002 // in the case where there is no match, as other alternatives take other
4003 // parse methods.
4004 AsmToken Tok = Parser.getTok();
4005 SMLoc S = Tok.getLoc();
4006 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004007 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004008 if (Tok.is(AsmToken::Plus)) {
4009 Parser.Lex(); // Eat the '+' token.
4010 haveEaten = true;
4011 } else if (Tok.is(AsmToken::Minus)) {
4012 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004013 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004014 haveEaten = true;
4015 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004016
4017 SMLoc E = Parser.getTok().getEndLoc();
4018 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004019 if (Reg == -1) {
4020 if (!haveEaten)
4021 return MatchOperand_NoMatch;
4022 Error(Parser.getTok().getLoc(), "register expected");
4023 return MatchOperand_ParseFail;
4024 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004025
Jim Grosbachc320c852011-08-05 21:28:30 +00004026 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4027 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004028 if (Parser.getTok().is(AsmToken::Comma)) {
4029 Parser.Lex(); // Eat the ','.
4030 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4031 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004032
4033 // FIXME: Only approximates end...may include intervening whitespace.
4034 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004035 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004036
4037 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4038 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004039
4040 return MatchOperand_Success;
4041}
4042
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004043ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4044parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4045 // Check for a post-index addressing register operand. Specifically:
4046 // am3offset := '+' register
4047 // | '-' register
4048 // | register
4049 // | # imm
4050 // | # + imm
4051 // | # - imm
4052
4053 // This method must return MatchOperand_NoMatch without consuming any tokens
4054 // in the case where there is no match, as other alternatives take other
4055 // parse methods.
4056 AsmToken Tok = Parser.getTok();
4057 SMLoc S = Tok.getLoc();
4058
4059 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004060 if (Parser.getTok().is(AsmToken::Hash) ||
4061 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004062 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004063 // Explicitly look for a '-', as we need to encode negative zero
4064 // differently.
4065 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4066 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004067 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004068 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004069 return MatchOperand_ParseFail;
4070 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4071 if (!CE) {
4072 Error(S, "constant expression expected");
4073 return MatchOperand_ParseFail;
4074 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004075 // Negative zero is encoded as the flag value INT32_MIN.
4076 int32_t Val = CE->getValue();
4077 if (isNegative && Val == 0)
4078 Val = INT32_MIN;
4079
4080 Operands.push_back(
4081 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4082
4083 return MatchOperand_Success;
4084 }
4085
4086
4087 bool haveEaten = false;
4088 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004089 if (Tok.is(AsmToken::Plus)) {
4090 Parser.Lex(); // Eat the '+' token.
4091 haveEaten = true;
4092 } else if (Tok.is(AsmToken::Minus)) {
4093 Parser.Lex(); // Eat the '-' token.
4094 isAdd = false;
4095 haveEaten = true;
4096 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004097
4098 Tok = Parser.getTok();
4099 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004100 if (Reg == -1) {
4101 if (!haveEaten)
4102 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004103 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004104 return MatchOperand_ParseFail;
4105 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004106
4107 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004108 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004109
4110 return MatchOperand_Success;
4111}
4112
Tim Northovereb5e4d52013-07-22 09:06:12 +00004113/// Convert parsed operands to MCInst. Needed here because this instruction
4114/// only has two register operands, but multiplication is commutative so
4115/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004116void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004117cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004118 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004119 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4120 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004121 // If we have a three-operand form, make sure to set Rn to be the operand
4122 // that isn't the same as Rd.
4123 unsigned RegOp = 4;
4124 if (Operands.size() == 6 &&
4125 ((ARMOperand*)Operands[4])->getReg() ==
4126 ((ARMOperand*)Operands[3])->getReg())
4127 RegOp = 5;
4128 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4129 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004130 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004131}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004132
Mihai Popaad18d3c2013-08-09 10:38:32 +00004133void ARMAsmParser::
4134cvtThumbBranches(MCInst &Inst,
4135 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4136 int CondOp = -1, ImmOp = -1;
4137 switch(Inst.getOpcode()) {
4138 case ARM::tB:
4139 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4140
4141 case ARM::t2B:
4142 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4143
4144 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4145 }
4146 // first decide whether or not the branch should be conditional
4147 // by looking at it's location relative to an IT block
4148 if(inITBlock()) {
4149 // inside an IT block we cannot have any conditional branches. any
4150 // such instructions needs to be converted to unconditional form
4151 switch(Inst.getOpcode()) {
4152 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4153 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4154 }
4155 } else {
4156 // outside IT blocks we can only have unconditional branches with AL
4157 // condition code or conditional branches with non-AL condition code
4158 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4159 switch(Inst.getOpcode()) {
4160 case ARM::tB:
4161 case ARM::tBcc:
4162 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4163 break;
4164 case ARM::t2B:
4165 case ARM::t2Bcc:
4166 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4167 break;
4168 }
4169 }
4170
4171 // now decide on encoding size based on branch target range
4172 switch(Inst.getOpcode()) {
4173 // classify tB as either t2B or t1B based on range of immediate operand
4174 case ARM::tB: {
4175 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4176 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4177 Inst.setOpcode(ARM::t2B);
4178 break;
4179 }
4180 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4181 case ARM::tBcc: {
4182 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4183 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4184 Inst.setOpcode(ARM::t2Bcc);
4185 break;
4186 }
4187 }
4188 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4189 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4190}
4191
Bill Wendlinge18980a2010-11-06 22:36:58 +00004192/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004193/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004194bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004195parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004196 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004197 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004198 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004199 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004200 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004201
Sean Callanan936b0d32010-01-19 21:44:56 +00004202 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004203 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004204 if (BaseRegNum == -1)
4205 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004206
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004207 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004208 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004209 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4210 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004211 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004212
Jim Grosbachd3595712011-08-03 23:50:40 +00004213 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004214 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004215 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004216
Jim Grosbachd3595712011-08-03 23:50:40 +00004217 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004218 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004219
Jim Grosbach40700e02011-09-19 18:42:21 +00004220 // If there's a pre-indexing writeback marker, '!', just add it as a token
4221 // operand. It's rather odd, but syntactically valid.
4222 if (Parser.getTok().is(AsmToken::Exclaim)) {
4223 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4224 Parser.Lex(); // Eat the '!'.
4225 }
4226
Jim Grosbachd3595712011-08-03 23:50:40 +00004227 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004228 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004229
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004230 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4231 "Lost colon or comma in memory operand?!");
4232 if (Tok.is(AsmToken::Comma)) {
4233 Parser.Lex(); // Eat the comma.
4234 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004235
Jim Grosbacha95ec992011-10-11 17:29:55 +00004236 // If we have a ':', it's an alignment specifier.
4237 if (Parser.getTok().is(AsmToken::Colon)) {
4238 Parser.Lex(); // Eat the ':'.
4239 E = Parser.getTok().getLoc();
4240
4241 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004242 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004243 return true;
4244
4245 // The expression has to be a constant. Memory references with relocations
4246 // don't come through here, as they use the <label> forms of the relevant
4247 // instructions.
4248 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4249 if (!CE)
4250 return Error (E, "constant expression expected");
4251
4252 unsigned Align = 0;
4253 switch (CE->getValue()) {
4254 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004255 return Error(E,
4256 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4257 case 16: Align = 2; break;
4258 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004259 case 64: Align = 8; break;
4260 case 128: Align = 16; break;
4261 case 256: Align = 32; break;
4262 }
4263
4264 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004265 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004266 return Error(Parser.getTok().getLoc(), "']' expected");
4267 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004268 Parser.Lex(); // Eat right bracket token.
4269
4270 // Don't worry about range checking the value here. That's handled by
4271 // the is*() predicates.
4272 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4273 ARM_AM::no_shift, 0, Align,
4274 false, S, E));
4275
4276 // If there's a pre-indexing writeback marker, '!', just add it as a token
4277 // operand.
4278 if (Parser.getTok().is(AsmToken::Exclaim)) {
4279 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4280 Parser.Lex(); // Eat the '!'.
4281 }
4282
4283 return false;
4284 }
4285
4286 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004287 // offset. Be friendly and also accept a plain integer (without a leading
4288 // hash) for gas compatibility.
4289 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004290 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004291 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004292 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004293 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004294 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004295
Owen Anderson967674d2011-08-29 19:36:44 +00004296 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004297 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004298 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004299 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004300
4301 // The expression has to be a constant. Memory references with relocations
4302 // don't come through here, as they use the <label> forms of the relevant
4303 // instructions.
4304 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4305 if (!CE)
4306 return Error (E, "constant expression expected");
4307
Owen Anderson967674d2011-08-29 19:36:44 +00004308 // If the constant was #-0, represent it as INT32_MIN.
4309 int32_t Val = CE->getValue();
4310 if (isNegative && Val == 0)
4311 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4312
Jim Grosbachd3595712011-08-03 23:50:40 +00004313 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004314 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004315 return Error(Parser.getTok().getLoc(), "']' expected");
4316 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004317 Parser.Lex(); // Eat right bracket token.
4318
4319 // Don't worry about range checking the value here. That's handled by
4320 // the is*() predicates.
4321 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004322 ARM_AM::no_shift, 0, 0,
4323 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004324
4325 // If there's a pre-indexing writeback marker, '!', just add it as a token
4326 // operand.
4327 if (Parser.getTok().is(AsmToken::Exclaim)) {
4328 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4329 Parser.Lex(); // Eat the '!'.
4330 }
4331
4332 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004333 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004334
4335 // The register offset is optionally preceded by a '+' or '-'
4336 bool isNegative = false;
4337 if (Parser.getTok().is(AsmToken::Minus)) {
4338 isNegative = true;
4339 Parser.Lex(); // Eat the '-'.
4340 } else if (Parser.getTok().is(AsmToken::Plus)) {
4341 // Nothing to do.
4342 Parser.Lex(); // Eat the '+'.
4343 }
4344
4345 E = Parser.getTok().getLoc();
4346 int OffsetRegNum = tryParseRegister();
4347 if (OffsetRegNum == -1)
4348 return Error(E, "register expected");
4349
4350 // If there's a shift operator, handle it.
4351 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004352 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004353 if (Parser.getTok().is(AsmToken::Comma)) {
4354 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004355 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004356 return true;
4357 }
4358
4359 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004360 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004361 return Error(Parser.getTok().getLoc(), "']' expected");
4362 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004363 Parser.Lex(); // Eat right bracket token.
4364
4365 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004366 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004367 S, E));
4368
Jim Grosbachc320c852011-08-05 21:28:30 +00004369 // If there's a pre-indexing writeback marker, '!', just add it as a token
4370 // operand.
4371 if (Parser.getTok().is(AsmToken::Exclaim)) {
4372 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4373 Parser.Lex(); // Eat the '!'.
4374 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004375
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004376 return false;
4377}
4378
Jim Grosbachd3595712011-08-03 23:50:40 +00004379/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004380/// ( lsl | lsr | asr | ror ) , # shift_amount
4381/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004382/// return true if it parses a shift otherwise it returns false.
4383bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4384 unsigned &Amount) {
4385 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004386 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004387 if (Tok.isNot(AsmToken::Identifier))
4388 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004389 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004390 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4391 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004392 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004393 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004394 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004395 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004396 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004397 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004398 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004399 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004400 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004401 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004402 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004403 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004404
Jim Grosbachd3595712011-08-03 23:50:40 +00004405 // rrx stands alone.
4406 Amount = 0;
4407 if (St != ARM_AM::rrx) {
4408 Loc = Parser.getTok().getLoc();
4409 // A '#' and a shift amount.
4410 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004411 if (HashTok.isNot(AsmToken::Hash) &&
4412 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004413 return Error(HashTok.getLoc(), "'#' expected");
4414 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004415
Jim Grosbachd3595712011-08-03 23:50:40 +00004416 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004417 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004418 return true;
4419 // Range check the immediate.
4420 // lsl, ror: 0 <= imm <= 31
4421 // lsr, asr: 0 <= imm <= 32
4422 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4423 if (!CE)
4424 return Error(Loc, "shift amount must be an immediate");
4425 int64_t Imm = CE->getValue();
4426 if (Imm < 0 ||
4427 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4428 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4429 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004430 // If <ShiftTy> #0, turn it into a no_shift.
4431 if (Imm == 0)
4432 St = ARM_AM::lsl;
4433 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4434 if (Imm == 32)
4435 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004436 Amount = Imm;
4437 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004438
4439 return false;
4440}
4441
Jim Grosbache7fbce72011-10-03 23:38:36 +00004442/// parseFPImm - A floating point immediate expression operand.
4443ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4444parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004445 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004446 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004447 // integer only.
4448 //
4449 // This routine still creates a generic Immediate operand, containing
4450 // a bitcast of the 64-bit floating point value. The various operands
4451 // that accept floats can check whether the value is valid for them
4452 // via the standard is*() predicates.
4453
Jim Grosbache7fbce72011-10-03 23:38:36 +00004454 SMLoc S = Parser.getTok().getLoc();
4455
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004456 if (Parser.getTok().isNot(AsmToken::Hash) &&
4457 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004458 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004459
4460 // Disambiguate the VMOV forms that can accept an FP immediate.
4461 // vmov.f32 <sreg>, #imm
4462 // vmov.f64 <dreg>, #imm
4463 // vmov.f32 <dreg>, #imm @ vector f32x2
4464 // vmov.f32 <qreg>, #imm @ vector f32x4
4465 //
4466 // There are also the NEON VMOV instructions which expect an
4467 // integer constant. Make sure we don't try to parse an FPImm
4468 // for these:
4469 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4470 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4471 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4472 TyOp->getToken() != ".f64"))
4473 return MatchOperand_NoMatch;
4474
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004475 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004476
4477 // Handle negation, as that still comes through as a separate token.
4478 bool isNegative = false;
4479 if (Parser.getTok().is(AsmToken::Minus)) {
4480 isNegative = true;
4481 Parser.Lex();
4482 }
4483 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004484 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004485 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004486 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004487 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4488 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004489 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004490 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004491 Operands.push_back(ARMOperand::CreateImm(
4492 MCConstantExpr::Create(IntVal, getContext()),
4493 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004494 return MatchOperand_Success;
4495 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004496 // Also handle plain integers. Instructions which allow floating point
4497 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004498 if (Tok.is(AsmToken::Integer)) {
4499 int64_t Val = Tok.getIntVal();
4500 Parser.Lex(); // Eat the token.
4501 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004502 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004503 return MatchOperand_ParseFail;
4504 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004505 double RealVal = ARM_AM::getFPImmFloat(Val);
4506 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4507 Operands.push_back(ARMOperand::CreateImm(
4508 MCConstantExpr::Create(Val, getContext()), S,
4509 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004510 return MatchOperand_Success;
4511 }
4512
Jim Grosbach235c8d22012-01-19 02:47:30 +00004513 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004514 return MatchOperand_ParseFail;
4515}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004516
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004517/// Parse a arm instruction operand. For now this parses the operand regardless
4518/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004519bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004520 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004521 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004522
4523 // Check if the current operand has a custom associated parser, if so, try to
4524 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004525 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4526 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004527 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004528 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4529 // there was a match, but an error occurred, in which case, just return that
4530 // the operand parsing failed.
4531 if (ResTy == MatchOperand_ParseFail)
4532 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004533
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004534 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004535 default:
4536 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004537 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004538 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004539 // If we've seen a branch mnemonic, the next operand must be a label. This
4540 // is true even if the label is a register name. So "br r1" means branch to
4541 // label "r1".
4542 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4543 if (!ExpectLabel) {
4544 if (!tryParseRegisterWithWriteBack(Operands))
4545 return false;
4546 int Res = tryParseShiftRegister(Operands);
4547 if (Res == 0) // success
4548 return false;
4549 else if (Res == -1) // irrecoverable error
4550 return true;
4551 // If this is VMRS, check for the apsr_nzcv operand.
4552 if (Mnemonic == "vmrs" &&
4553 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4554 S = Parser.getTok().getLoc();
4555 Parser.Lex();
4556 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4557 return false;
4558 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004559 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004560
4561 // Fall though for the Identifier case that is not a register or a
4562 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004563 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004564 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004565 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004566 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004567 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004568 // This was not a register so parse other operands that start with an
4569 // identifier (like labels) as expressions and create them as immediates.
4570 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004571 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004572 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004573 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004574 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004575 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4576 return false;
4577 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004578 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004579 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004580 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004581 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004582 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004583 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004584 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004585 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004586 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004587
4588 if (Parser.getTok().isNot(AsmToken::Colon)) {
4589 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4590 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004591 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004592 return true;
4593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4594 if (CE) {
4595 int32_t Val = CE->getValue();
4596 if (isNegative && Val == 0)
4597 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4598 }
4599 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4600 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004601
4602 // There can be a trailing '!' on operands that we want as a separate
4603 // '!' Token operand. Handle that here. For example, the compatibilty
4604 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4605 if (Parser.getTok().is(AsmToken::Exclaim)) {
4606 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4607 Parser.getTok().getLoc()));
4608 Parser.Lex(); // Eat exclaim token
4609 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004610 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004611 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004612 // w/ a ':' after the '#', it's just like a plain ':'.
4613 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004614 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004615 case AsmToken::Colon: {
4616 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004617 // FIXME: Check it's an expression prefix,
4618 // e.g. (FOO - :lower16:BAR) isn't legal.
4619 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004620 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004621 return true;
4622
Evan Cheng965b3c72011-01-13 07:58:56 +00004623 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004624 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004625 return true;
4626
Evan Cheng965b3c72011-01-13 07:58:56 +00004627 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004628 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004629 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004630 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004631 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004632 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004633 }
4634}
4635
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004636// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004637// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004638bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004639 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004640
4641 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004642 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004643 Parser.Lex(); // Eat ':'
4644
4645 if (getLexer().isNot(AsmToken::Identifier)) {
4646 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4647 return true;
4648 }
4649
4650 StringRef IDVal = Parser.getTok().getIdentifier();
4651 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004652 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004653 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004654 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004655 } else {
4656 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4657 return true;
4658 }
4659 Parser.Lex();
4660
4661 if (getLexer().isNot(AsmToken::Colon)) {
4662 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4663 return true;
4664 }
4665 Parser.Lex(); // Eat the last ':'
4666 return false;
4667}
4668
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004669/// \brief Given a mnemonic, split out possible predication code and carry
4670/// setting letters to form a canonical mnemonic and flags.
4671//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004672// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004673// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004674StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004675 unsigned &PredicationCode,
4676 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004677 unsigned &ProcessorIMod,
4678 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004679 PredicationCode = ARMCC::AL;
4680 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004681 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004682
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004683 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004684 //
4685 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004686 if ((Mnemonic == "movs" && isThumb()) ||
4687 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4688 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4689 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4690 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004691 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004692 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4693 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004694 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004695 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004696 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4697 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4698 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004699 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004700
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004701 // First, split out any predication code. Ignore mnemonics we know aren't
4702 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004703 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004704 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004705 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004706 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004707 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4708 .Case("eq", ARMCC::EQ)
4709 .Case("ne", ARMCC::NE)
4710 .Case("hs", ARMCC::HS)
4711 .Case("cs", ARMCC::HS)
4712 .Case("lo", ARMCC::LO)
4713 .Case("cc", ARMCC::LO)
4714 .Case("mi", ARMCC::MI)
4715 .Case("pl", ARMCC::PL)
4716 .Case("vs", ARMCC::VS)
4717 .Case("vc", ARMCC::VC)
4718 .Case("hi", ARMCC::HI)
4719 .Case("ls", ARMCC::LS)
4720 .Case("ge", ARMCC::GE)
4721 .Case("lt", ARMCC::LT)
4722 .Case("gt", ARMCC::GT)
4723 .Case("le", ARMCC::LE)
4724 .Case("al", ARMCC::AL)
4725 .Default(~0U);
4726 if (CC != ~0U) {
4727 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4728 PredicationCode = CC;
4729 }
Bill Wendling193961b2010-10-29 23:50:21 +00004730 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004731
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004732 // Next, determine if we have a carry setting bit. We explicitly ignore all
4733 // the instructions we know end in 's'.
4734 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004735 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004736 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4737 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4738 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004739 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004740 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004741 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004742 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004743 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004744 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004745 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4746 CarrySetting = true;
4747 }
4748
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004749 // The "cps" instruction can have a interrupt mode operand which is glued into
4750 // the mnemonic. Check if this is the case, split it and parse the imod op
4751 if (Mnemonic.startswith("cps")) {
4752 // Split out any imod code.
4753 unsigned IMod =
4754 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4755 .Case("ie", ARM_PROC::IE)
4756 .Case("id", ARM_PROC::ID)
4757 .Default(~0U);
4758 if (IMod != ~0U) {
4759 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4760 ProcessorIMod = IMod;
4761 }
4762 }
4763
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004764 // The "it" instruction has the condition mask on the end of the mnemonic.
4765 if (Mnemonic.startswith("it")) {
4766 ITMask = Mnemonic.slice(2, Mnemonic.size());
4767 Mnemonic = Mnemonic.slice(0, 2);
4768 }
4769
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004770 return Mnemonic;
4771}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004772
4773/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4774/// inclusion of carry set or predication code operands.
4775//
4776// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004777void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004778getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4779 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004780 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4781 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004782 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004783 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004784 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004785 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004786 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004787 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004788 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004789 Mnemonic == "mla" || Mnemonic == "smlal" ||
4790 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004791 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004792 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004793 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004794
Tim Northover2c45a382013-06-26 16:52:40 +00004795 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4796 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004797 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004798 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4799 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004800 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4801 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004802 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4803 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4804 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004805 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004806 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004807 } else if (!isThumb()) {
4808 // Some instructions are only predicable in Thumb mode
4809 CanAcceptPredicationCode
4810 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4811 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4812 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4813 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4814 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4815 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4816 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4817 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004818 if (hasV6MOps())
4819 CanAcceptPredicationCode = Mnemonic != "movs";
4820 else
4821 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004822 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004823 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004824}
4825
Jim Grosbach7283da92011-08-16 21:12:37 +00004826bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4827 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004828 // FIXME: This is all horribly hacky. We really need a better way to deal
4829 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004830
4831 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4832 // another does not. Specifically, the MOVW instruction does not. So we
4833 // special case it here and remove the defaulted (non-setting) cc_out
4834 // operand if that's the instruction we're trying to match.
4835 //
4836 // We do this as post-processing of the explicit operands rather than just
4837 // conditionally adding the cc_out in the first place because we need
4838 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004839 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004840 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4841 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4842 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4843 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004844
4845 // Register-register 'add' for thumb does not have a cc_out operand
4846 // when there are only two register operands.
4847 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4848 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4849 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4850 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4851 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004852 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004853 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4854 // have to check the immediate range here since Thumb2 has a variant
4855 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004856 if (((isThumb() && Mnemonic == "add") ||
4857 (isThumbTwo() && Mnemonic == "sub")) &&
4858 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004859 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4860 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4861 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004862 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004863 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004864 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004865 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004866 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4867 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004868 // selecting via the generic "add" mnemonic, so to know that we
4869 // should remove the cc_out operand, we have to explicitly check that
4870 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004871 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4872 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004873 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4874 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4875 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4876 // Nest conditions rather than one big 'if' statement for readability.
4877 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004878 // If both registers are low, we're in an IT block, and the immediate is
4879 // in range, we should use encoding T1 instead, which has a cc_out.
4880 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004881 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004882 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4883 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4884 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004885 // Check against T3. If the second register is the PC, this is an
4886 // alternate form of ADR, which uses encoding T4, so check for that too.
4887 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4888 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4889 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004890
4891 // Otherwise, we use encoding T4, which does not have a cc_out
4892 // operand.
4893 return true;
4894 }
4895
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004896 // The thumb2 multiply instruction doesn't have a CCOut register, so
4897 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4898 // use the 16-bit encoding or not.
4899 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4900 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4901 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4902 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4903 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4904 // If the registers aren't low regs, the destination reg isn't the
4905 // same as one of the source regs, or the cc_out operand is zero
4906 // outside of an IT block, we have to use the 32-bit encoding, so
4907 // remove the cc_out operand.
4908 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4909 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004910 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004911 !inITBlock() ||
4912 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4913 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4914 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4915 static_cast<ARMOperand*>(Operands[4])->getReg())))
4916 return true;
4917
Jim Grosbachefa7e952011-11-15 19:55:16 +00004918 // Also check the 'mul' syntax variant that doesn't specify an explicit
4919 // destination register.
4920 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4921 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4922 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4923 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4924 // If the registers aren't low regs or the cc_out operand is zero
4925 // outside of an IT block, we have to use the 32-bit encoding, so
4926 // remove the cc_out operand.
4927 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4928 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4929 !inITBlock()))
4930 return true;
4931
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004932
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004933
Jim Grosbach4b701af2011-08-24 21:42:27 +00004934 // Register-register 'add/sub' for thumb does not have a cc_out operand
4935 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4936 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4937 // right, this will result in better diagnostics (which operand is off)
4938 // anyway.
4939 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4940 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004941 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4942 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004943 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4944 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4945 (Operands.size() == 6 &&
4946 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004947 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004948
Jim Grosbach7283da92011-08-16 21:12:37 +00004949 return false;
4950}
4951
Joey Goulye8602552013-07-19 16:34:16 +00004952bool ARMAsmParser::shouldOmitPredicateOperand(
4953 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4954 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4955 unsigned RegIdx = 3;
4956 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4957 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4958 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4959 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4960 RegIdx = 4;
4961
4962 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4963 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4964 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4965 ARMMCRegisterClasses[ARM::QPRRegClassID]
4966 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4967 return true;
4968 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004969 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004970}
4971
Jim Grosbach12952fe2011-11-11 23:08:10 +00004972static bool isDataTypeToken(StringRef Tok) {
4973 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4974 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4975 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4976 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4977 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4978 Tok == ".f" || Tok == ".d";
4979}
4980
4981// FIXME: This bit should probably be handled via an explicit match class
4982// in the .td files that matches the suffix instead of having it be
4983// a literal string token the way it is now.
4984static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4985 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4986}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004987static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4988 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004989/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004990bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4991 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004992 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004993 // Apply mnemonic aliases before doing anything else, as the destination
4994 // mnemnonic may include suffices and we want to handle them normally.
4995 // The generic tblgen'erated code does this later, at the start of
4996 // MatchInstructionImpl(), but that's too late for aliases that include
4997 // any sort of suffix.
4998 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00004999 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5000 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005001
Jim Grosbachab5830e2011-12-14 02:16:11 +00005002 // First check for the ARM-specific .req directive.
5003 if (Parser.getTok().is(AsmToken::Identifier) &&
5004 Parser.getTok().getIdentifier() == ".req") {
5005 parseDirectiveReq(Name, NameLoc);
5006 // We always return 'error' for this, as we're done with this
5007 // statement and don't need to match the 'instruction."
5008 return true;
5009 }
5010
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005011 // Create the leading tokens for the mnemonic, split by '.' characters.
5012 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005013 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005014
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005015 // Split out the predication code and carry setting flag from the mnemonic.
5016 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005017 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005018 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005019 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005020 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005021 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005022
Jim Grosbach1c171b12011-08-25 17:23:55 +00005023 // In Thumb1, only the branch (B) instruction can be predicated.
5024 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005025 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005026 return Error(NameLoc, "conditional execution not supported in Thumb1");
5027 }
5028
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005029 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5030
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005031 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5032 // is the mask as it will be for the IT encoding if the conditional
5033 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5034 // where the conditional bit0 is zero, the instruction post-processing
5035 // will adjust the mask accordingly.
5036 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005037 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5038 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005039 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005040 return Error(Loc, "too many conditions on IT instruction");
5041 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005042 unsigned Mask = 8;
5043 for (unsigned i = ITMask.size(); i != 0; --i) {
5044 char pos = ITMask[i - 1];
5045 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005046 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005047 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005048 }
5049 Mask >>= 1;
5050 if (ITMask[i - 1] == 't')
5051 Mask |= 8;
5052 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005053 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005054 }
5055
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005056 // FIXME: This is all a pretty gross hack. We should automatically handle
5057 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005058
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005059 // Next, add the CCOut and ConditionCode operands, if needed.
5060 //
5061 // For mnemonics which can ever incorporate a carry setting bit or predication
5062 // code, our matching model involves us always generating CCOut and
5063 // ConditionCode operands to match the mnemonic "as written" and then we let
5064 // the matcher deal with finding the right instruction or generating an
5065 // appropriate error.
5066 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005067 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005068
Jim Grosbach03a8a162011-07-14 22:04:21 +00005069 // If we had a carry-set on an instruction that can't do that, issue an
5070 // error.
5071 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005072 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005073 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005074 "' can not set flags, but 's' suffix specified");
5075 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005076 // If we had a predication code on an instruction that can't do that, issue an
5077 // error.
5078 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005079 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005080 return Error(NameLoc, "instruction '" + Mnemonic +
5081 "' is not predicable, but condition code specified");
5082 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005083
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005084 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005085 if (CanAcceptCarrySet) {
5086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005087 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005088 Loc));
5089 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005090
5091 // Add the predication code operand, if necessary.
5092 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005093 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5094 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005095 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005096 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005097 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005098
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005099 // Add the processor imod operand, if necessary.
5100 if (ProcessorIMod) {
5101 Operands.push_back(ARMOperand::CreateImm(
5102 MCConstantExpr::Create(ProcessorIMod, getContext()),
5103 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005104 }
5105
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005106 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005107 while (Next != StringRef::npos) {
5108 Start = Next;
5109 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005110 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005111
Jim Grosbach12952fe2011-11-11 23:08:10 +00005112 // Some NEON instructions have an optional datatype suffix that is
5113 // completely ignored. Check for that.
5114 if (isDataTypeToken(ExtraToken) &&
5115 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5116 continue;
5117
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005118 // For for ARM mode generate an error if the .n qualifier is used.
5119 if (ExtraToken == ".n" && !isThumb()) {
5120 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5121 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5122 "arm mode");
5123 }
5124
5125 // The .n qualifier is always discarded as that is what the tables
5126 // and matcher expect. In ARM mode the .w qualifier has no effect,
5127 // so discard it to avoid errors that can be caused by the matcher.
5128 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005129 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5130 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5131 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005132 }
5133
5134 // Read the remaining operands.
5135 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005136 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005137 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005138 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005139 return true;
5140 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005141
5142 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005143 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005144
5145 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005146 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005147 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005148 return true;
5149 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005150 }
5151 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005152
Chris Lattnera2a9d162010-09-11 16:18:25 +00005153 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005154 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005155 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005156 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005157 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005158
Chris Lattner91689c12010-09-08 05:10:46 +00005159 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005160
Jim Grosbach7283da92011-08-16 21:12:37 +00005161 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5162 // do and don't have a cc_out optional-def operand. With some spot-checks
5163 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005164 // parse and adjust accordingly before actually matching. We shouldn't ever
5165 // try to remove a cc_out operand that was explicitly set on the the
5166 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5167 // table driven matcher doesn't fit well with the ARM instruction set.
5168 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005169 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5170 Operands.erase(Operands.begin() + 1);
5171 delete Op;
5172 }
5173
Joey Goulye8602552013-07-19 16:34:16 +00005174 // Some instructions have the same mnemonic, but don't always
5175 // have a predicate. Distinguish them here and delete the
5176 // predicate if needed.
5177 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5178 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5179 Operands.erase(Operands.begin() + 1);
5180 delete Op;
5181 }
5182
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005183 // ARM mode 'blx' need special handling, as the register operand version
5184 // is predicable, but the label operand version is not. So, we can't rely
5185 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005186 // a k_CondCode operand in the list. If we're trying to match the label
5187 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005188 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5189 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5190 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5191 Operands.erase(Operands.begin() + 1);
5192 delete Op;
5193 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005194
Weiming Zhao8f56f882012-11-16 21:55:34 +00005195 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5196 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5197 // a single GPRPair reg operand is used in the .td file to replace the two
5198 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5199 // expressed as a GPRPair, so we have to manually merge them.
5200 // FIXME: We would really like to be able to tablegen'erate this.
5201 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005202 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5203 Mnemonic == "stlexd")) {
5204 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005205 unsigned Idx = isLoad ? 2 : 3;
5206 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5207 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5208
5209 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5210 // Adjust only if Op1 and Op2 are GPRs.
5211 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5212 MRC.contains(Op2->getReg())) {
5213 unsigned Reg1 = Op1->getReg();
5214 unsigned Reg2 = Op2->getReg();
5215 unsigned Rt = MRI->getEncodingValue(Reg1);
5216 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5217
5218 // Rt2 must be Rt + 1 and Rt must be even.
5219 if (Rt + 1 != Rt2 || (Rt & 1)) {
5220 Error(Op2->getStartLoc(), isLoad ?
5221 "destination operands must be sequential" :
5222 "source operands must be sequential");
5223 return true;
5224 }
5225 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5226 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5227 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5228 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5229 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5230 delete Op1;
5231 delete Op2;
5232 }
5233 }
5234
Kevin Enderby78f95722013-07-31 21:05:30 +00005235 // FIXME: As said above, this is all a pretty gross hack. This instruction
5236 // does not fit with other "subs" and tblgen.
5237 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5238 // so the Mnemonic is the original name "subs" and delete the predicate
5239 // operand so it will match the table entry.
5240 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5241 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5242 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5243 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5244 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5245 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5246 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5247 Operands.erase(Operands.begin());
5248 delete Op0;
5249 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5250
5251 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5252 Operands.erase(Operands.begin() + 1);
5253 delete Op1;
5254 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005255 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005256}
5257
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005258// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005259
5260// return 'true' if register list contains non-low GPR registers,
5261// 'false' otherwise. If Reg is in the register list or is HiReg, set
5262// 'containsReg' to true.
5263static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5264 unsigned HiReg, bool &containsReg) {
5265 containsReg = false;
5266 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5267 unsigned OpReg = Inst.getOperand(i).getReg();
5268 if (OpReg == Reg)
5269 containsReg = true;
5270 // Anything other than a low register isn't legal here.
5271 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5272 return true;
5273 }
5274 return false;
5275}
5276
Jim Grosbacha31f2232011-09-07 18:05:34 +00005277// Check if the specified regisgter is in the register list of the inst,
5278// starting at the indicated operand number.
5279static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5280 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5281 unsigned OpReg = Inst.getOperand(i).getReg();
5282 if (OpReg == Reg)
5283 return true;
5284 }
5285 return false;
5286}
5287
Richard Barton8d519fe2013-09-05 14:14:19 +00005288// Return true if instruction has the interesting property of being
5289// allowed in IT blocks, but not being predicable.
5290static bool instIsBreakpoint(const MCInst &Inst) {
5291 return Inst.getOpcode() == ARM::tBKPT ||
5292 Inst.getOpcode() == ARM::BKPT ||
5293 Inst.getOpcode() == ARM::tHLT ||
5294 Inst.getOpcode() == ARM::HLT;
5295
5296}
5297
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005298// FIXME: We would really like to be able to tablegen'erate this.
5299bool ARMAsmParser::
5300validateInstruction(MCInst &Inst,
5301 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005302 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005303 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005304
Jim Grosbached16ec42011-08-29 22:24:09 +00005305 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005306 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005307 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005308 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005309 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005310 if (ITState.FirstCond)
5311 ITState.FirstCond = false;
5312 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005313 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005314 // The instruction must be predicable.
5315 if (!MCID.isPredicable())
5316 return Error(Loc, "instructions in IT block must be predicable");
5317 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005318 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005319 ARMCC::getOppositeCondition(ITState.Cond);
5320 if (Cond != ITCond) {
5321 // Find the condition code Operand to get its SMLoc information.
5322 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005323 for (unsigned I = 1; I < Operands.size(); ++I)
5324 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5325 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005326 return Error(CondLoc, "incorrect condition in IT block; got '" +
5327 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5328 "', but expected '" +
5329 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5330 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005331 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005332 } else if (isThumbTwo() && MCID.isPredicable() &&
5333 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005334 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5335 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005336 return Error(Loc, "predicated instructions must be in IT block");
5337
Tilmann Scheller255722b2013-09-30 16:11:48 +00005338 const unsigned Opcode = Inst.getOpcode();
5339 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005340 case ARM::LDRD:
5341 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005342 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005343 const unsigned RtReg = Inst.getOperand(0).getReg();
5344
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005345 // Rt can't be R14.
5346 if (RtReg == ARM::LR)
5347 return Error(Operands[3]->getStartLoc(),
5348 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005349
5350 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005351 // Rt must be even-numbered.
5352 if ((Rt & 1) == 1)
5353 return Error(Operands[3]->getStartLoc(),
5354 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005355
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005356 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005357 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005358 if (Rt2 != Rt + 1)
5359 return Error(Operands[3]->getStartLoc(),
5360 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005361
5362 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5363 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5364 // For addressing modes with writeback, the base register needs to be
5365 // different from the destination registers.
5366 if (Rn == Rt || Rn == Rt2)
5367 return Error(Operands[3]->getStartLoc(),
5368 "base register needs to be different from destination "
5369 "registers");
5370 }
5371
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005372 return false;
5373 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005374 case ARM::t2LDRDi8:
5375 case ARM::t2LDRD_PRE:
5376 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005377 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005378 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5379 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5380 if (Rt2 == Rt)
5381 return Error(Operands[3]->getStartLoc(),
5382 "destination operands can't be identical");
5383 return false;
5384 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005385 case ARM::STRD: {
5386 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005387 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5388 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005389 if (Rt2 != Rt + 1)
5390 return Error(Operands[3]->getStartLoc(),
5391 "source operands must be sequential");
5392 return false;
5393 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005394 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005395 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005396 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005397 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5398 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005399 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005400 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005401 "source operands must be sequential");
5402 return false;
5403 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005404 case ARM::SBFX:
5405 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005406 // Width must be in range [1, 32-lsb].
5407 unsigned LSB = Inst.getOperand(2).getImm();
5408 unsigned Widthm1 = Inst.getOperand(3).getImm();
5409 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005410 return Error(Operands[5]->getStartLoc(),
5411 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005412 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005413 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005414 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005415 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005416 // most cases that are normally illegal for a Thumb1 LDM instruction.
5417 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005418 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005419 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005420 // in the register list.
5421 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005422 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005423 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5424 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005425 bool ListContainsBase;
5426 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5427 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005428 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005429 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005430 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005431 return Error(Operands[2]->getStartLoc(),
5432 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005433 // If we should not have writeback, there must not be a '!'. This is
5434 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005435 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005436 return Error(Operands[3]->getStartLoc(),
5437 "writeback operator '!' not allowed when base register "
5438 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005439
5440 break;
5441 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005442 case ARM::t2LDMIA_UPD: {
5443 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5444 return Error(Operands[4]->getStartLoc(),
5445 "writeback operator '!' not allowed when base register "
5446 "in register list");
5447 break;
5448 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005449 case ARM::tMUL: {
5450 // The second source operand must be the same register as the destination
5451 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005452 //
5453 // In this case, we must directly check the parsed operands because the
5454 // cvtThumbMultiply() function is written in such a way that it guarantees
5455 // this first statement is always true for the new Inst. Essentially, the
5456 // destination is unconditionally copied into the second source operand
5457 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005458 if (Operands.size() == 6 &&
5459 (((ARMOperand*)Operands[3])->getReg() !=
5460 ((ARMOperand*)Operands[5])->getReg()) &&
5461 (((ARMOperand*)Operands[3])->getReg() !=
5462 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005463 return Error(Operands[3]->getStartLoc(),
5464 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005465 }
5466 break;
5467 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005468 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5469 // so only issue a diagnostic for thumb1. The instructions will be
5470 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005471 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005472 bool ListContainsBase;
5473 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005474 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005475 return Error(Operands[2]->getStartLoc(),
5476 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005477 break;
5478 }
5479 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005480 bool ListContainsBase;
5481 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005482 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005483 return Error(Operands[2]->getStartLoc(),
5484 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005485 break;
5486 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005487 case ARM::tSTMIA_UPD: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005488 bool ListContainsBase;
5489 if (checkLowRegisterList(Inst, 4, 0, 0, ListContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005490 return Error(Operands[4]->getStartLoc(),
5491 "registers must be in range r0-r7");
5492 break;
5493 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005494 case ARM::tADDrSP: {
5495 // If the non-SP source operand and the destination operand are not the
5496 // same, we need thumb2 (for the wide encoding), or we have an error.
5497 if (!isThumbTwo() &&
5498 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5499 return Error(Operands[4]->getStartLoc(),
5500 "source register must be the same as destination");
5501 }
5502 break;
5503 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005504 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005505 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005506 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5507 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005508 break;
5509 case ARM::t2B: {
5510 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005511 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5512 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005513 break;
5514 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005515 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005516 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005517 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5518 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005519 break;
5520 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005521 int Op = (Operands[2]->isImm()) ? 2 : 3;
5522 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5523 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005524 break;
5525 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005526 }
5527
5528 return false;
5529}
5530
Jim Grosbach1a747242012-01-23 23:45:44 +00005531static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005532 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005533 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005534 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005535 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5536 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5537 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5538 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5539 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5540 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5541 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5542 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5543 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005544
5545 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005546 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5547 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5548 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5549 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5550 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005551
Jim Grosbach1e946a42012-01-24 00:43:12 +00005552 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5553 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5554 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5555 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5556 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005557
Jim Grosbach1e946a42012-01-24 00:43:12 +00005558 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5559 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5560 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5561 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5562 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005563
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005564 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005565 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5566 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5567 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5568 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5569 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5570 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5571 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5572 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5573 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5574 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5575 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5576 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5577 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5578 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5579 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005580
Jim Grosbach1a747242012-01-23 23:45:44 +00005581 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005582 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5583 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5584 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5585 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5586 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5587 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5588 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5589 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5590 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5591 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5592 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5593 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5594 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5595 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5596 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5597 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5598 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5599 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005600
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005601 // VST4LN
5602 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5603 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5604 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5605 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5606 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5607 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5608 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5609 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5610 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5611 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5612 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5613 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5614 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5615 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5616 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5617
Jim Grosbachda70eac2012-01-24 00:58:13 +00005618 // VST4
5619 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5620 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5621 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5622 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5623 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5624 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5625 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5626 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5627 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5628 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5629 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5630 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5631 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5632 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5633 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5634 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5635 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5636 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005637 }
5638}
5639
Jim Grosbach1a747242012-01-23 23:45:44 +00005640static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005641 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005642 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005643 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005644 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5645 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5646 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5647 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5648 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5649 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5650 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5651 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5652 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005653
5654 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005655 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5656 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5657 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5658 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5659 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5660 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5661 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5662 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5663 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5664 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5665 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5666 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5667 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5668 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5669 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005670
Jim Grosbachb78403c2012-01-24 23:47:04 +00005671 // VLD3DUP
5672 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5673 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5674 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5675 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5676 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5677 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5678 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5679 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5680 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5681 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5682 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5683 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5684 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5685 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5686 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5687 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5688 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5689 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5690
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005691 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005692 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5693 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5694 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5695 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5696 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5697 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5698 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5699 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5700 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5701 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5702 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5703 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5704 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5705 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5706 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005707
5708 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005709 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5710 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5711 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5712 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5713 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5714 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5715 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5716 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5717 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5718 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5719 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5720 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5721 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5722 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5723 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5724 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5725 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5726 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005727
Jim Grosbach14952a02012-01-24 18:37:25 +00005728 // VLD4LN
5729 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5730 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5731 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5732 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5733 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5734 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5735 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5736 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5737 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5738 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5739 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5740 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5741 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5742 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5743 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5744
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005745 // VLD4DUP
5746 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5747 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5748 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5749 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5750 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5751 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5752 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5753 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5754 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5755 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5756 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5757 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5758 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5759 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5760 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5761 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5762 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5763 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5764
Jim Grosbached561fc2012-01-24 00:43:17 +00005765 // VLD4
5766 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5767 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5768 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5769 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5770 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5771 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5772 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5773 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5774 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5775 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5776 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5777 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5778 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5779 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5780 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5781 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5782 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5783 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005784 }
5785}
5786
Jim Grosbachafad0532011-11-10 23:42:14 +00005787bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005788processInstruction(MCInst &Inst,
5789 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5790 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005791 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5792 case ARM::ADDri: {
5793 if (Inst.getOperand(1).getReg() != ARM::PC ||
5794 Inst.getOperand(5).getReg() != 0)
5795 return false;
5796 MCInst TmpInst;
5797 TmpInst.setOpcode(ARM::ADR);
5798 TmpInst.addOperand(Inst.getOperand(0));
5799 TmpInst.addOperand(Inst.getOperand(2));
5800 TmpInst.addOperand(Inst.getOperand(3));
5801 TmpInst.addOperand(Inst.getOperand(4));
5802 Inst = TmpInst;
5803 return true;
5804 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005805 // Aliases for alternate PC+imm syntax of LDR instructions.
5806 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005807 // Select the narrow version if the immediate will fit.
5808 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005809 Inst.getOperand(1).getImm() <= 0xff &&
5810 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5811 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005812 Inst.setOpcode(ARM::tLDRpci);
5813 else
5814 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005815 return true;
5816 case ARM::t2LDRBpcrel:
5817 Inst.setOpcode(ARM::t2LDRBpci);
5818 return true;
5819 case ARM::t2LDRHpcrel:
5820 Inst.setOpcode(ARM::t2LDRHpci);
5821 return true;
5822 case ARM::t2LDRSBpcrel:
5823 Inst.setOpcode(ARM::t2LDRSBpci);
5824 return true;
5825 case ARM::t2LDRSHpcrel:
5826 Inst.setOpcode(ARM::t2LDRSHpci);
5827 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005828 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005829 case ARM::VST1LNdWB_register_Asm_8:
5830 case ARM::VST1LNdWB_register_Asm_16:
5831 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005832 MCInst TmpInst;
5833 // Shuffle the operands around so the lane index operand is in the
5834 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005835 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005836 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005837 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5838 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5839 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5840 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5841 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5842 TmpInst.addOperand(Inst.getOperand(1)); // lane
5843 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5844 TmpInst.addOperand(Inst.getOperand(6));
5845 Inst = TmpInst;
5846 return true;
5847 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005848
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005849 case ARM::VST2LNdWB_register_Asm_8:
5850 case ARM::VST2LNdWB_register_Asm_16:
5851 case ARM::VST2LNdWB_register_Asm_32:
5852 case ARM::VST2LNqWB_register_Asm_16:
5853 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005854 MCInst TmpInst;
5855 // Shuffle the operands around so the lane index operand is in the
5856 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005857 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005858 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005859 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5860 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5861 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5862 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5863 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5865 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005866 TmpInst.addOperand(Inst.getOperand(1)); // lane
5867 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5868 TmpInst.addOperand(Inst.getOperand(6));
5869 Inst = TmpInst;
5870 return true;
5871 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005872
5873 case ARM::VST3LNdWB_register_Asm_8:
5874 case ARM::VST3LNdWB_register_Asm_16:
5875 case ARM::VST3LNdWB_register_Asm_32:
5876 case ARM::VST3LNqWB_register_Asm_16:
5877 case ARM::VST3LNqWB_register_Asm_32: {
5878 MCInst TmpInst;
5879 // Shuffle the operands around so the lane index operand is in the
5880 // right place.
5881 unsigned Spacing;
5882 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5883 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5884 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5885 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5886 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5887 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5889 Spacing));
5890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5891 Spacing * 2));
5892 TmpInst.addOperand(Inst.getOperand(1)); // lane
5893 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5894 TmpInst.addOperand(Inst.getOperand(6));
5895 Inst = TmpInst;
5896 return true;
5897 }
5898
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005899 case ARM::VST4LNdWB_register_Asm_8:
5900 case ARM::VST4LNdWB_register_Asm_16:
5901 case ARM::VST4LNdWB_register_Asm_32:
5902 case ARM::VST4LNqWB_register_Asm_16:
5903 case ARM::VST4LNqWB_register_Asm_32: {
5904 MCInst TmpInst;
5905 // Shuffle the operands around so the lane index operand is in the
5906 // right place.
5907 unsigned Spacing;
5908 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5909 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5910 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5911 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5912 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5913 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5914 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5915 Spacing));
5916 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5917 Spacing * 2));
5918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5919 Spacing * 3));
5920 TmpInst.addOperand(Inst.getOperand(1)); // lane
5921 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5922 TmpInst.addOperand(Inst.getOperand(6));
5923 Inst = TmpInst;
5924 return true;
5925 }
5926
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005927 case ARM::VST1LNdWB_fixed_Asm_8:
5928 case ARM::VST1LNdWB_fixed_Asm_16:
5929 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005930 MCInst TmpInst;
5931 // Shuffle the operands around so the lane index operand is in the
5932 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005933 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005934 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005935 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5938 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5939 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5940 TmpInst.addOperand(Inst.getOperand(1)); // lane
5941 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5942 TmpInst.addOperand(Inst.getOperand(5));
5943 Inst = TmpInst;
5944 return true;
5945 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005946
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005947 case ARM::VST2LNdWB_fixed_Asm_8:
5948 case ARM::VST2LNdWB_fixed_Asm_16:
5949 case ARM::VST2LNdWB_fixed_Asm_32:
5950 case ARM::VST2LNqWB_fixed_Asm_16:
5951 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005952 MCInst TmpInst;
5953 // Shuffle the operands around so the lane index operand is in the
5954 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005955 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005956 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005957 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5958 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5959 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5960 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5961 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005962 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5963 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005964 TmpInst.addOperand(Inst.getOperand(1)); // lane
5965 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5966 TmpInst.addOperand(Inst.getOperand(5));
5967 Inst = TmpInst;
5968 return true;
5969 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005970
5971 case ARM::VST3LNdWB_fixed_Asm_8:
5972 case ARM::VST3LNdWB_fixed_Asm_16:
5973 case ARM::VST3LNdWB_fixed_Asm_32:
5974 case ARM::VST3LNqWB_fixed_Asm_16:
5975 case ARM::VST3LNqWB_fixed_Asm_32: {
5976 MCInst TmpInst;
5977 // Shuffle the operands around so the lane index operand is in the
5978 // right place.
5979 unsigned Spacing;
5980 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5981 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5982 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5983 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5984 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5987 Spacing));
5988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5989 Spacing * 2));
5990 TmpInst.addOperand(Inst.getOperand(1)); // lane
5991 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5992 TmpInst.addOperand(Inst.getOperand(5));
5993 Inst = TmpInst;
5994 return true;
5995 }
5996
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005997 case ARM::VST4LNdWB_fixed_Asm_8:
5998 case ARM::VST4LNdWB_fixed_Asm_16:
5999 case ARM::VST4LNdWB_fixed_Asm_32:
6000 case ARM::VST4LNqWB_fixed_Asm_16:
6001 case ARM::VST4LNqWB_fixed_Asm_32: {
6002 MCInst TmpInst;
6003 // Shuffle the operands around so the lane index operand is in the
6004 // right place.
6005 unsigned Spacing;
6006 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6007 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6008 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6009 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6010 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6011 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6013 Spacing));
6014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6015 Spacing * 2));
6016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 Spacing * 3));
6018 TmpInst.addOperand(Inst.getOperand(1)); // lane
6019 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6020 TmpInst.addOperand(Inst.getOperand(5));
6021 Inst = TmpInst;
6022 return true;
6023 }
6024
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006025 case ARM::VST1LNdAsm_8:
6026 case ARM::VST1LNdAsm_16:
6027 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006028 MCInst TmpInst;
6029 // Shuffle the operands around so the lane index operand is in the
6030 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006031 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006032 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006033 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6034 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6035 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6036 TmpInst.addOperand(Inst.getOperand(1)); // lane
6037 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6038 TmpInst.addOperand(Inst.getOperand(5));
6039 Inst = TmpInst;
6040 return true;
6041 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006042
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006043 case ARM::VST2LNdAsm_8:
6044 case ARM::VST2LNdAsm_16:
6045 case ARM::VST2LNdAsm_32:
6046 case ARM::VST2LNqAsm_16:
6047 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006048 MCInst TmpInst;
6049 // Shuffle the operands around so the lane index operand is in the
6050 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006051 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006052 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006053 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6054 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6055 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6057 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006058 TmpInst.addOperand(Inst.getOperand(1)); // lane
6059 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6060 TmpInst.addOperand(Inst.getOperand(5));
6061 Inst = TmpInst;
6062 return true;
6063 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006064
6065 case ARM::VST3LNdAsm_8:
6066 case ARM::VST3LNdAsm_16:
6067 case ARM::VST3LNdAsm_32:
6068 case ARM::VST3LNqAsm_16:
6069 case ARM::VST3LNqAsm_32: {
6070 MCInst TmpInst;
6071 // Shuffle the operands around so the lane index operand is in the
6072 // right place.
6073 unsigned Spacing;
6074 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6075 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6076 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6077 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 Spacing));
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing * 2));
6082 TmpInst.addOperand(Inst.getOperand(1)); // lane
6083 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6084 TmpInst.addOperand(Inst.getOperand(5));
6085 Inst = TmpInst;
6086 return true;
6087 }
6088
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006089 case ARM::VST4LNdAsm_8:
6090 case ARM::VST4LNdAsm_16:
6091 case ARM::VST4LNdAsm_32:
6092 case ARM::VST4LNqAsm_16:
6093 case ARM::VST4LNqAsm_32: {
6094 MCInst TmpInst;
6095 // Shuffle the operands around so the lane index operand is in the
6096 // right place.
6097 unsigned Spacing;
6098 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6099 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6100 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6101 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6103 Spacing));
6104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6105 Spacing * 2));
6106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6107 Spacing * 3));
6108 TmpInst.addOperand(Inst.getOperand(1)); // lane
6109 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6110 TmpInst.addOperand(Inst.getOperand(5));
6111 Inst = TmpInst;
6112 return true;
6113 }
6114
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006115 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006116 case ARM::VLD1LNdWB_register_Asm_8:
6117 case ARM::VLD1LNdWB_register_Asm_16:
6118 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006119 MCInst TmpInst;
6120 // Shuffle the operands around so the lane index operand is in the
6121 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006122 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006123 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006124 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6125 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6126 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6127 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6128 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6129 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6130 TmpInst.addOperand(Inst.getOperand(1)); // lane
6131 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6132 TmpInst.addOperand(Inst.getOperand(6));
6133 Inst = TmpInst;
6134 return true;
6135 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006136
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006137 case ARM::VLD2LNdWB_register_Asm_8:
6138 case ARM::VLD2LNdWB_register_Asm_16:
6139 case ARM::VLD2LNdWB_register_Asm_32:
6140 case ARM::VLD2LNqWB_register_Asm_16:
6141 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006142 MCInst TmpInst;
6143 // Shuffle the operands around so the lane index operand is in the
6144 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006145 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006146 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006147 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006148 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6149 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006150 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6151 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6152 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6153 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6154 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6156 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006157 TmpInst.addOperand(Inst.getOperand(1)); // lane
6158 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6159 TmpInst.addOperand(Inst.getOperand(6));
6160 Inst = TmpInst;
6161 return true;
6162 }
6163
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006164 case ARM::VLD3LNdWB_register_Asm_8:
6165 case ARM::VLD3LNdWB_register_Asm_16:
6166 case ARM::VLD3LNdWB_register_Asm_32:
6167 case ARM::VLD3LNqWB_register_Asm_16:
6168 case ARM::VLD3LNqWB_register_Asm_32: {
6169 MCInst TmpInst;
6170 // Shuffle the operands around so the lane index operand is in the
6171 // right place.
6172 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006173 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006174 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6176 Spacing));
6177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006178 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006179 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6180 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6181 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6182 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6183 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 Spacing));
6186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006187 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006188 TmpInst.addOperand(Inst.getOperand(1)); // lane
6189 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6190 TmpInst.addOperand(Inst.getOperand(6));
6191 Inst = TmpInst;
6192 return true;
6193 }
6194
Jim Grosbach14952a02012-01-24 18:37:25 +00006195 case ARM::VLD4LNdWB_register_Asm_8:
6196 case ARM::VLD4LNdWB_register_Asm_16:
6197 case ARM::VLD4LNdWB_register_Asm_32:
6198 case ARM::VLD4LNqWB_register_Asm_16:
6199 case ARM::VLD4LNqWB_register_Asm_32: {
6200 MCInst TmpInst;
6201 // Shuffle the operands around so the lane index operand is in the
6202 // right place.
6203 unsigned Spacing;
6204 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6205 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 Spacing));
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6209 Spacing * 2));
6210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6211 Spacing * 3));
6212 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6213 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6214 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6215 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6216 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6218 Spacing));
6219 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6220 Spacing * 2));
6221 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6222 Spacing * 3));
6223 TmpInst.addOperand(Inst.getOperand(1)); // lane
6224 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6225 TmpInst.addOperand(Inst.getOperand(6));
6226 Inst = TmpInst;
6227 return true;
6228 }
6229
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006230 case ARM::VLD1LNdWB_fixed_Asm_8:
6231 case ARM::VLD1LNdWB_fixed_Asm_16:
6232 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006233 MCInst TmpInst;
6234 // Shuffle the operands around so the lane index operand is in the
6235 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006236 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006237 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006238 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6239 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6240 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6241 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6242 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6243 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6244 TmpInst.addOperand(Inst.getOperand(1)); // lane
6245 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6246 TmpInst.addOperand(Inst.getOperand(5));
6247 Inst = TmpInst;
6248 return true;
6249 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006250
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006251 case ARM::VLD2LNdWB_fixed_Asm_8:
6252 case ARM::VLD2LNdWB_fixed_Asm_16:
6253 case ARM::VLD2LNdWB_fixed_Asm_32:
6254 case ARM::VLD2LNqWB_fixed_Asm_16:
6255 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006256 MCInst TmpInst;
6257 // Shuffle the operands around so the lane index operand is in the
6258 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006259 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006260 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006261 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6263 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006264 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6265 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6266 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6267 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6268 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006271 TmpInst.addOperand(Inst.getOperand(1)); // lane
6272 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6273 TmpInst.addOperand(Inst.getOperand(5));
6274 Inst = TmpInst;
6275 return true;
6276 }
6277
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006278 case ARM::VLD3LNdWB_fixed_Asm_8:
6279 case ARM::VLD3LNdWB_fixed_Asm_16:
6280 case ARM::VLD3LNdWB_fixed_Asm_32:
6281 case ARM::VLD3LNqWB_fixed_Asm_16:
6282 case ARM::VLD3LNqWB_fixed_Asm_32: {
6283 MCInst TmpInst;
6284 // Shuffle the operands around so the lane index operand is in the
6285 // right place.
6286 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006287 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006288 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6290 Spacing));
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006292 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006293 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6294 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6295 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6296 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6297 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing));
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006301 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006302 TmpInst.addOperand(Inst.getOperand(1)); // lane
6303 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6304 TmpInst.addOperand(Inst.getOperand(5));
6305 Inst = TmpInst;
6306 return true;
6307 }
6308
Jim Grosbach14952a02012-01-24 18:37:25 +00006309 case ARM::VLD4LNdWB_fixed_Asm_8:
6310 case ARM::VLD4LNdWB_fixed_Asm_16:
6311 case ARM::VLD4LNdWB_fixed_Asm_32:
6312 case ARM::VLD4LNqWB_fixed_Asm_16:
6313 case ARM::VLD4LNqWB_fixed_Asm_32: {
6314 MCInst TmpInst;
6315 // Shuffle the operands around so the lane index operand is in the
6316 // right place.
6317 unsigned Spacing;
6318 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6319 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6320 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6321 Spacing));
6322 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6323 Spacing * 2));
6324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 Spacing * 3));
6326 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6327 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6329 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6330 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 Spacing));
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 Spacing * 2));
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6336 Spacing * 3));
6337 TmpInst.addOperand(Inst.getOperand(1)); // lane
6338 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6339 TmpInst.addOperand(Inst.getOperand(5));
6340 Inst = TmpInst;
6341 return true;
6342 }
6343
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006344 case ARM::VLD1LNdAsm_8:
6345 case ARM::VLD1LNdAsm_16:
6346 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006347 MCInst TmpInst;
6348 // Shuffle the operands around so the lane index operand is in the
6349 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006350 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006351 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006352 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6353 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6354 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6355 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6356 TmpInst.addOperand(Inst.getOperand(1)); // lane
6357 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6358 TmpInst.addOperand(Inst.getOperand(5));
6359 Inst = TmpInst;
6360 return true;
6361 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006362
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006363 case ARM::VLD2LNdAsm_8:
6364 case ARM::VLD2LNdAsm_16:
6365 case ARM::VLD2LNdAsm_32:
6366 case ARM::VLD2LNqAsm_16:
6367 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006368 MCInst TmpInst;
6369 // Shuffle the operands around so the lane index operand is in the
6370 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006371 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006372 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006373 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006376 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6377 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6378 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006381 TmpInst.addOperand(Inst.getOperand(1)); // lane
6382 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(5));
6384 Inst = TmpInst;
6385 return true;
6386 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006387
6388 case ARM::VLD3LNdAsm_8:
6389 case ARM::VLD3LNdAsm_16:
6390 case ARM::VLD3LNdAsm_32:
6391 case ARM::VLD3LNqAsm_16:
6392 case ARM::VLD3LNqAsm_32: {
6393 MCInst TmpInst;
6394 // Shuffle the operands around so the lane index operand is in the
6395 // right place.
6396 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006397 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006398 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 Spacing));
6401 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006402 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006403 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6404 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6405 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 Spacing));
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006409 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006410 TmpInst.addOperand(Inst.getOperand(1)); // lane
6411 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6412 TmpInst.addOperand(Inst.getOperand(5));
6413 Inst = TmpInst;
6414 return true;
6415 }
6416
Jim Grosbach14952a02012-01-24 18:37:25 +00006417 case ARM::VLD4LNdAsm_8:
6418 case ARM::VLD4LNdAsm_16:
6419 case ARM::VLD4LNdAsm_32:
6420 case ARM::VLD4LNqAsm_16:
6421 case ARM::VLD4LNqAsm_32: {
6422 MCInst TmpInst;
6423 // Shuffle the operands around so the lane index operand is in the
6424 // right place.
6425 unsigned Spacing;
6426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6429 Spacing));
6430 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6431 Spacing * 2));
6432 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6433 Spacing * 3));
6434 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6435 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6436 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing));
6439 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6440 Spacing * 2));
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6442 Spacing * 3));
6443 TmpInst.addOperand(Inst.getOperand(1)); // lane
6444 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6445 TmpInst.addOperand(Inst.getOperand(5));
6446 Inst = TmpInst;
6447 return true;
6448 }
6449
Jim Grosbachb78403c2012-01-24 23:47:04 +00006450 // VLD3DUP single 3-element structure to all lanes instructions.
6451 case ARM::VLD3DUPdAsm_8:
6452 case ARM::VLD3DUPdAsm_16:
6453 case ARM::VLD3DUPdAsm_32:
6454 case ARM::VLD3DUPqAsm_8:
6455 case ARM::VLD3DUPqAsm_16:
6456 case ARM::VLD3DUPqAsm_32: {
6457 MCInst TmpInst;
6458 unsigned Spacing;
6459 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6460 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6461 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6462 Spacing));
6463 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6464 Spacing * 2));
6465 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6466 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6467 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6468 TmpInst.addOperand(Inst.getOperand(4));
6469 Inst = TmpInst;
6470 return true;
6471 }
6472
6473 case ARM::VLD3DUPdWB_fixed_Asm_8:
6474 case ARM::VLD3DUPdWB_fixed_Asm_16:
6475 case ARM::VLD3DUPdWB_fixed_Asm_32:
6476 case ARM::VLD3DUPqWB_fixed_Asm_8:
6477 case ARM::VLD3DUPqWB_fixed_Asm_16:
6478 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6479 MCInst TmpInst;
6480 unsigned Spacing;
6481 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6482 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6483 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6484 Spacing));
6485 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6486 Spacing * 2));
6487 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6488 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6489 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6490 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6491 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6492 TmpInst.addOperand(Inst.getOperand(4));
6493 Inst = TmpInst;
6494 return true;
6495 }
6496
6497 case ARM::VLD3DUPdWB_register_Asm_8:
6498 case ARM::VLD3DUPdWB_register_Asm_16:
6499 case ARM::VLD3DUPdWB_register_Asm_32:
6500 case ARM::VLD3DUPqWB_register_Asm_8:
6501 case ARM::VLD3DUPqWB_register_Asm_16:
6502 case ARM::VLD3DUPqWB_register_Asm_32: {
6503 MCInst TmpInst;
6504 unsigned Spacing;
6505 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6506 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6507 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6508 Spacing));
6509 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6510 Spacing * 2));
6511 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6512 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6513 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6514 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6515 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6516 TmpInst.addOperand(Inst.getOperand(5));
6517 Inst = TmpInst;
6518 return true;
6519 }
6520
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006521 // VLD3 multiple 3-element structure instructions.
6522 case ARM::VLD3dAsm_8:
6523 case ARM::VLD3dAsm_16:
6524 case ARM::VLD3dAsm_32:
6525 case ARM::VLD3qAsm_8:
6526 case ARM::VLD3qAsm_16:
6527 case ARM::VLD3qAsm_32: {
6528 MCInst TmpInst;
6529 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006530 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006531 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 Spacing));
6534 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6535 Spacing * 2));
6536 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6537 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6538 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(4));
6540 Inst = TmpInst;
6541 return true;
6542 }
6543
6544 case ARM::VLD3dWB_fixed_Asm_8:
6545 case ARM::VLD3dWB_fixed_Asm_16:
6546 case ARM::VLD3dWB_fixed_Asm_32:
6547 case ARM::VLD3qWB_fixed_Asm_8:
6548 case ARM::VLD3qWB_fixed_Asm_16:
6549 case ARM::VLD3qWB_fixed_Asm_32: {
6550 MCInst TmpInst;
6551 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing));
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 Spacing * 2));
6558 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6559 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6560 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6561 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6562 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6563 TmpInst.addOperand(Inst.getOperand(4));
6564 Inst = TmpInst;
6565 return true;
6566 }
6567
6568 case ARM::VLD3dWB_register_Asm_8:
6569 case ARM::VLD3dWB_register_Asm_16:
6570 case ARM::VLD3dWB_register_Asm_32:
6571 case ARM::VLD3qWB_register_Asm_8:
6572 case ARM::VLD3qWB_register_Asm_16:
6573 case ARM::VLD3qWB_register_Asm_32: {
6574 MCInst TmpInst;
6575 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006576 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006577 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 Spacing));
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 Spacing * 2));
6582 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6587 TmpInst.addOperand(Inst.getOperand(5));
6588 Inst = TmpInst;
6589 return true;
6590 }
6591
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006592 // VLD4DUP single 3-element structure to all lanes instructions.
6593 case ARM::VLD4DUPdAsm_8:
6594 case ARM::VLD4DUPdAsm_16:
6595 case ARM::VLD4DUPdAsm_32:
6596 case ARM::VLD4DUPqAsm_8:
6597 case ARM::VLD4DUPqAsm_16:
6598 case ARM::VLD4DUPqAsm_32: {
6599 MCInst TmpInst;
6600 unsigned Spacing;
6601 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6602 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 Spacing));
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing * 2));
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 Spacing * 3));
6609 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6610 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6611 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6612 TmpInst.addOperand(Inst.getOperand(4));
6613 Inst = TmpInst;
6614 return true;
6615 }
6616
6617 case ARM::VLD4DUPdWB_fixed_Asm_8:
6618 case ARM::VLD4DUPdWB_fixed_Asm_16:
6619 case ARM::VLD4DUPdWB_fixed_Asm_32:
6620 case ARM::VLD4DUPqWB_fixed_Asm_8:
6621 case ARM::VLD4DUPqWB_fixed_Asm_16:
6622 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6623 MCInst TmpInst;
6624 unsigned Spacing;
6625 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6626 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6627 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6628 Spacing));
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6630 Spacing * 2));
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6632 Spacing * 3));
6633 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6634 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6635 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6636 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6637 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(4));
6639 Inst = TmpInst;
6640 return true;
6641 }
6642
6643 case ARM::VLD4DUPdWB_register_Asm_8:
6644 case ARM::VLD4DUPdWB_register_Asm_16:
6645 case ARM::VLD4DUPdWB_register_Asm_32:
6646 case ARM::VLD4DUPqWB_register_Asm_8:
6647 case ARM::VLD4DUPqWB_register_Asm_16:
6648 case ARM::VLD4DUPqWB_register_Asm_32: {
6649 MCInst TmpInst;
6650 unsigned Spacing;
6651 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6652 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6653 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6654 Spacing));
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 Spacing * 2));
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6658 Spacing * 3));
6659 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6660 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6661 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6662 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6663 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6664 TmpInst.addOperand(Inst.getOperand(5));
6665 Inst = TmpInst;
6666 return true;
6667 }
6668
6669 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006670 case ARM::VLD4dAsm_8:
6671 case ARM::VLD4dAsm_16:
6672 case ARM::VLD4dAsm_32:
6673 case ARM::VLD4qAsm_8:
6674 case ARM::VLD4qAsm_16:
6675 case ARM::VLD4qAsm_32: {
6676 MCInst TmpInst;
6677 unsigned Spacing;
6678 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 Spacing));
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 Spacing * 2));
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6685 Spacing * 3));
6686 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6687 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6688 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6689 TmpInst.addOperand(Inst.getOperand(4));
6690 Inst = TmpInst;
6691 return true;
6692 }
6693
6694 case ARM::VLD4dWB_fixed_Asm_8:
6695 case ARM::VLD4dWB_fixed_Asm_16:
6696 case ARM::VLD4dWB_fixed_Asm_32:
6697 case ARM::VLD4qWB_fixed_Asm_8:
6698 case ARM::VLD4qWB_fixed_Asm_16:
6699 case ARM::VLD4qWB_fixed_Asm_32: {
6700 MCInst TmpInst;
6701 unsigned Spacing;
6702 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6703 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6705 Spacing));
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6707 Spacing * 2));
6708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6709 Spacing * 3));
6710 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6711 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6712 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6713 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6714 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6715 TmpInst.addOperand(Inst.getOperand(4));
6716 Inst = TmpInst;
6717 return true;
6718 }
6719
6720 case ARM::VLD4dWB_register_Asm_8:
6721 case ARM::VLD4dWB_register_Asm_16:
6722 case ARM::VLD4dWB_register_Asm_32:
6723 case ARM::VLD4qWB_register_Asm_8:
6724 case ARM::VLD4qWB_register_Asm_16:
6725 case ARM::VLD4qWB_register_Asm_32: {
6726 MCInst TmpInst;
6727 unsigned Spacing;
6728 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6729 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6731 Spacing));
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 Spacing * 2));
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 Spacing * 3));
6736 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6737 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6738 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6739 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6740 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6741 TmpInst.addOperand(Inst.getOperand(5));
6742 Inst = TmpInst;
6743 return true;
6744 }
6745
Jim Grosbach1a747242012-01-23 23:45:44 +00006746 // VST3 multiple 3-element structure instructions.
6747 case ARM::VST3dAsm_8:
6748 case ARM::VST3dAsm_16:
6749 case ARM::VST3dAsm_32:
6750 case ARM::VST3qAsm_8:
6751 case ARM::VST3qAsm_16:
6752 case ARM::VST3qAsm_32: {
6753 MCInst TmpInst;
6754 unsigned Spacing;
6755 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6756 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6757 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6758 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6760 Spacing));
6761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6762 Spacing * 2));
6763 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(4));
6765 Inst = TmpInst;
6766 return true;
6767 }
6768
6769 case ARM::VST3dWB_fixed_Asm_8:
6770 case ARM::VST3dWB_fixed_Asm_16:
6771 case ARM::VST3dWB_fixed_Asm_32:
6772 case ARM::VST3qWB_fixed_Asm_8:
6773 case ARM::VST3qWB_fixed_Asm_16:
6774 case ARM::VST3qWB_fixed_Asm_32: {
6775 MCInst TmpInst;
6776 unsigned Spacing;
6777 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6778 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6779 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6780 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6781 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6782 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6784 Spacing));
6785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6786 Spacing * 2));
6787 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6788 TmpInst.addOperand(Inst.getOperand(4));
6789 Inst = TmpInst;
6790 return true;
6791 }
6792
6793 case ARM::VST3dWB_register_Asm_8:
6794 case ARM::VST3dWB_register_Asm_16:
6795 case ARM::VST3dWB_register_Asm_32:
6796 case ARM::VST3qWB_register_Asm_8:
6797 case ARM::VST3qWB_register_Asm_16:
6798 case ARM::VST3qWB_register_Asm_32: {
6799 MCInst TmpInst;
6800 unsigned Spacing;
6801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6802 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6803 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6804 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6805 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6808 Spacing));
6809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6810 Spacing * 2));
6811 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6812 TmpInst.addOperand(Inst.getOperand(5));
6813 Inst = TmpInst;
6814 return true;
6815 }
6816
Jim Grosbachda70eac2012-01-24 00:58:13 +00006817 // VST4 multiple 3-element structure instructions.
6818 case ARM::VST4dAsm_8:
6819 case ARM::VST4dAsm_16:
6820 case ARM::VST4dAsm_32:
6821 case ARM::VST4qAsm_8:
6822 case ARM::VST4qAsm_16:
6823 case ARM::VST4qAsm_32: {
6824 MCInst TmpInst;
6825 unsigned Spacing;
6826 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6827 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6828 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6829 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6831 Spacing));
6832 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6833 Spacing * 2));
6834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6835 Spacing * 3));
6836 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6837 TmpInst.addOperand(Inst.getOperand(4));
6838 Inst = TmpInst;
6839 return true;
6840 }
6841
6842 case ARM::VST4dWB_fixed_Asm_8:
6843 case ARM::VST4dWB_fixed_Asm_16:
6844 case ARM::VST4dWB_fixed_Asm_32:
6845 case ARM::VST4qWB_fixed_Asm_8:
6846 case ARM::VST4qWB_fixed_Asm_16:
6847 case ARM::VST4qWB_fixed_Asm_32: {
6848 MCInst TmpInst;
6849 unsigned Spacing;
6850 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6851 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6852 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6853 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6854 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6855 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6857 Spacing));
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6859 Spacing * 2));
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6861 Spacing * 3));
6862 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6863 TmpInst.addOperand(Inst.getOperand(4));
6864 Inst = TmpInst;
6865 return true;
6866 }
6867
6868 case ARM::VST4dWB_register_Asm_8:
6869 case ARM::VST4dWB_register_Asm_16:
6870 case ARM::VST4dWB_register_Asm_32:
6871 case ARM::VST4qWB_register_Asm_8:
6872 case ARM::VST4qWB_register_Asm_16:
6873 case ARM::VST4qWB_register_Asm_32: {
6874 MCInst TmpInst;
6875 unsigned Spacing;
6876 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6877 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6879 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6880 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6881 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6883 Spacing));
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6885 Spacing * 2));
6886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6887 Spacing * 3));
6888 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6889 TmpInst.addOperand(Inst.getOperand(5));
6890 Inst = TmpInst;
6891 return true;
6892 }
6893
Jim Grosbachad66de12012-04-11 00:15:16 +00006894 // Handle encoding choice for the shift-immediate instructions.
6895 case ARM::t2LSLri:
6896 case ARM::t2LSRri:
6897 case ARM::t2ASRri: {
6898 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6899 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6900 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6901 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6902 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6903 unsigned NewOpc;
6904 switch (Inst.getOpcode()) {
6905 default: llvm_unreachable("unexpected opcode");
6906 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6907 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6908 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6909 }
6910 // The Thumb1 operands aren't in the same order. Awesome, eh?
6911 MCInst TmpInst;
6912 TmpInst.setOpcode(NewOpc);
6913 TmpInst.addOperand(Inst.getOperand(0));
6914 TmpInst.addOperand(Inst.getOperand(5));
6915 TmpInst.addOperand(Inst.getOperand(1));
6916 TmpInst.addOperand(Inst.getOperand(2));
6917 TmpInst.addOperand(Inst.getOperand(3));
6918 TmpInst.addOperand(Inst.getOperand(4));
6919 Inst = TmpInst;
6920 return true;
6921 }
6922 return false;
6923 }
6924
Jim Grosbach485e5622011-12-13 22:45:11 +00006925 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006926 case ARM::t2MOVsr:
6927 case ARM::t2MOVSsr: {
6928 // Which instruction to expand to depends on the CCOut operand and
6929 // whether we're in an IT block if the register operands are low
6930 // registers.
6931 bool isNarrow = false;
6932 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6933 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6934 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6935 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6936 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6937 isNarrow = true;
6938 MCInst TmpInst;
6939 unsigned newOpc;
6940 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6941 default: llvm_unreachable("unexpected opcode!");
6942 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6943 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6944 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6945 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6946 }
6947 TmpInst.setOpcode(newOpc);
6948 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6949 if (isNarrow)
6950 TmpInst.addOperand(MCOperand::CreateReg(
6951 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6953 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6954 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6955 TmpInst.addOperand(Inst.getOperand(5));
6956 if (!isNarrow)
6957 TmpInst.addOperand(MCOperand::CreateReg(
6958 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6959 Inst = TmpInst;
6960 return true;
6961 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006962 case ARM::t2MOVsi:
6963 case ARM::t2MOVSsi: {
6964 // Which instruction to expand to depends on the CCOut operand and
6965 // whether we're in an IT block if the register operands are low
6966 // registers.
6967 bool isNarrow = false;
6968 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6969 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6970 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6971 isNarrow = true;
6972 MCInst TmpInst;
6973 unsigned newOpc;
6974 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6975 default: llvm_unreachable("unexpected opcode!");
6976 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6977 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6978 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6979 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006980 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006981 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006982 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6983 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006984 TmpInst.setOpcode(newOpc);
6985 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6986 if (isNarrow)
6987 TmpInst.addOperand(MCOperand::CreateReg(
6988 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6989 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006990 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006991 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006992 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6993 TmpInst.addOperand(Inst.getOperand(4));
6994 if (!isNarrow)
6995 TmpInst.addOperand(MCOperand::CreateReg(
6996 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6997 Inst = TmpInst;
6998 return true;
6999 }
7000 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007001 case ARM::ASRr:
7002 case ARM::LSRr:
7003 case ARM::LSLr:
7004 case ARM::RORr: {
7005 ARM_AM::ShiftOpc ShiftTy;
7006 switch(Inst.getOpcode()) {
7007 default: llvm_unreachable("unexpected opcode!");
7008 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7009 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7010 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7011 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7012 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007013 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7014 MCInst TmpInst;
7015 TmpInst.setOpcode(ARM::MOVsr);
7016 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7017 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7018 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7019 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7020 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7021 TmpInst.addOperand(Inst.getOperand(4));
7022 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7023 Inst = TmpInst;
7024 return true;
7025 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007026 case ARM::ASRi:
7027 case ARM::LSRi:
7028 case ARM::LSLi:
7029 case ARM::RORi: {
7030 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007031 switch(Inst.getOpcode()) {
7032 default: llvm_unreachable("unexpected opcode!");
7033 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7034 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7035 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7036 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7037 }
7038 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007039 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007040 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007041 // A shift by 32 should be encoded as 0 when permitted
7042 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7043 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007044 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007045 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007046 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007047 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7048 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007049 if (Opc == ARM::MOVsi)
7050 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007051 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7052 TmpInst.addOperand(Inst.getOperand(4));
7053 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7054 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007055 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007056 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007057 case ARM::RRXi: {
7058 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7059 MCInst TmpInst;
7060 TmpInst.setOpcode(ARM::MOVsi);
7061 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7062 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7063 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7064 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7065 TmpInst.addOperand(Inst.getOperand(3));
7066 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7067 Inst = TmpInst;
7068 return true;
7069 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007070 case ARM::t2LDMIA_UPD: {
7071 // If this is a load of a single register, then we should use
7072 // a post-indexed LDR instruction instead, per the ARM ARM.
7073 if (Inst.getNumOperands() != 5)
7074 return false;
7075 MCInst TmpInst;
7076 TmpInst.setOpcode(ARM::t2LDR_POST);
7077 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7078 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7079 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7080 TmpInst.addOperand(MCOperand::CreateImm(4));
7081 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7082 TmpInst.addOperand(Inst.getOperand(3));
7083 Inst = TmpInst;
7084 return true;
7085 }
7086 case ARM::t2STMDB_UPD: {
7087 // If this is a store of a single register, then we should use
7088 // a pre-indexed STR instruction instead, per the ARM ARM.
7089 if (Inst.getNumOperands() != 5)
7090 return false;
7091 MCInst TmpInst;
7092 TmpInst.setOpcode(ARM::t2STR_PRE);
7093 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7094 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7095 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7096 TmpInst.addOperand(MCOperand::CreateImm(-4));
7097 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7098 TmpInst.addOperand(Inst.getOperand(3));
7099 Inst = TmpInst;
7100 return true;
7101 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007102 case ARM::LDMIA_UPD:
7103 // If this is a load of a single register via a 'pop', then we should use
7104 // a post-indexed LDR instruction instead, per the ARM ARM.
7105 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7106 Inst.getNumOperands() == 5) {
7107 MCInst TmpInst;
7108 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7109 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7110 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7111 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7112 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7113 TmpInst.addOperand(MCOperand::CreateImm(4));
7114 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7115 TmpInst.addOperand(Inst.getOperand(3));
7116 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007117 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007118 }
7119 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007120 case ARM::STMDB_UPD:
7121 // If this is a store of a single register via a 'push', then we should use
7122 // a pre-indexed STR instruction instead, per the ARM ARM.
7123 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7124 Inst.getNumOperands() == 5) {
7125 MCInst TmpInst;
7126 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7127 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7128 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7129 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7130 TmpInst.addOperand(MCOperand::CreateImm(-4));
7131 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7132 TmpInst.addOperand(Inst.getOperand(3));
7133 Inst = TmpInst;
7134 }
7135 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007136 case ARM::t2ADDri12:
7137 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7138 // mnemonic was used (not "addw"), encoding T3 is preferred.
7139 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7140 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7141 break;
7142 Inst.setOpcode(ARM::t2ADDri);
7143 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7144 break;
7145 case ARM::t2SUBri12:
7146 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7147 // mnemonic was used (not "subw"), encoding T3 is preferred.
7148 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7149 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7150 break;
7151 Inst.setOpcode(ARM::t2SUBri);
7152 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7153 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007154 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007155 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007156 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7157 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7158 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007159 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007160 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007161 return true;
7162 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007163 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007164 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007165 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007166 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7167 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7168 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007169 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007170 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007171 return true;
7172 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007173 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007174 case ARM::t2ADDri:
7175 case ARM::t2SUBri: {
7176 // If the destination and first source operand are the same, and
7177 // the flags are compatible with the current IT status, use encoding T2
7178 // instead of T3. For compatibility with the system 'as'. Make sure the
7179 // wide encoding wasn't explicit.
7180 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007181 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007182 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7183 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7184 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7185 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7186 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7187 break;
7188 MCInst TmpInst;
7189 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7190 ARM::tADDi8 : ARM::tSUBi8);
7191 TmpInst.addOperand(Inst.getOperand(0));
7192 TmpInst.addOperand(Inst.getOperand(5));
7193 TmpInst.addOperand(Inst.getOperand(0));
7194 TmpInst.addOperand(Inst.getOperand(2));
7195 TmpInst.addOperand(Inst.getOperand(3));
7196 TmpInst.addOperand(Inst.getOperand(4));
7197 Inst = TmpInst;
7198 return true;
7199 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007200 case ARM::t2ADDrr: {
7201 // If the destination and first source operand are the same, and
7202 // there's no setting of the flags, use encoding T2 instead of T3.
7203 // Note that this is only for ADD, not SUB. This mirrors the system
7204 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7205 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7206 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007207 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7208 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007209 break;
7210 MCInst TmpInst;
7211 TmpInst.setOpcode(ARM::tADDhirr);
7212 TmpInst.addOperand(Inst.getOperand(0));
7213 TmpInst.addOperand(Inst.getOperand(0));
7214 TmpInst.addOperand(Inst.getOperand(2));
7215 TmpInst.addOperand(Inst.getOperand(3));
7216 TmpInst.addOperand(Inst.getOperand(4));
7217 Inst = TmpInst;
7218 return true;
7219 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007220 case ARM::tADDrSP: {
7221 // If the non-SP source operand and the destination operand are not the
7222 // same, we need to use the 32-bit encoding if it's available.
7223 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7224 Inst.setOpcode(ARM::t2ADDrr);
7225 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7226 return true;
7227 }
7228 break;
7229 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007230 case ARM::tB:
7231 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007232 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007233 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007234 return true;
7235 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007236 break;
7237 case ARM::t2B:
7238 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007239 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007240 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007241 return true;
7242 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007243 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007244 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007245 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007246 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007247 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007248 return true;
7249 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007250 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007251 case ARM::tBcc:
7252 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007253 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007254 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007255 return true;
7256 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007257 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007258 case ARM::tLDMIA: {
7259 // If the register list contains any high registers, or if the writeback
7260 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7261 // instead if we're in Thumb2. Otherwise, this should have generated
7262 // an error in validateInstruction().
7263 unsigned Rn = Inst.getOperand(0).getReg();
7264 bool hasWritebackToken =
7265 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7266 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7267 bool listContainsBase;
7268 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7269 (!listContainsBase && !hasWritebackToken) ||
7270 (listContainsBase && hasWritebackToken)) {
7271 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7272 assert (isThumbTwo());
7273 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7274 // If we're switching to the updating version, we need to insert
7275 // the writeback tied operand.
7276 if (hasWritebackToken)
7277 Inst.insert(Inst.begin(),
7278 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007279 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007280 }
7281 break;
7282 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007283 case ARM::tSTMIA_UPD: {
7284 // If the register list contains any high registers, we need to use
7285 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7286 // should have generated an error in validateInstruction().
7287 unsigned Rn = Inst.getOperand(0).getReg();
7288 bool listContainsBase;
7289 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7290 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7291 assert (isThumbTwo());
7292 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007293 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007294 }
7295 break;
7296 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007297 case ARM::tPOP: {
7298 bool listContainsBase;
7299 // If the register list contains any high registers, we need to use
7300 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7301 // should have generated an error in validateInstruction().
7302 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007303 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007304 assert (isThumbTwo());
7305 Inst.setOpcode(ARM::t2LDMIA_UPD);
7306 // Add the base register and writeback operands.
7307 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7308 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007309 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007310 }
7311 case ARM::tPUSH: {
7312 bool listContainsBase;
7313 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007314 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007315 assert (isThumbTwo());
7316 Inst.setOpcode(ARM::t2STMDB_UPD);
7317 // Add the base register and writeback operands.
7318 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7319 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007320 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007321 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007322 case ARM::t2MOVi: {
7323 // If we can use the 16-bit encoding and the user didn't explicitly
7324 // request the 32-bit variant, transform it here.
7325 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007326 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007327 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7328 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7329 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007330 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7331 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7332 // The operands aren't in the same order for tMOVi8...
7333 MCInst TmpInst;
7334 TmpInst.setOpcode(ARM::tMOVi8);
7335 TmpInst.addOperand(Inst.getOperand(0));
7336 TmpInst.addOperand(Inst.getOperand(4));
7337 TmpInst.addOperand(Inst.getOperand(1));
7338 TmpInst.addOperand(Inst.getOperand(2));
7339 TmpInst.addOperand(Inst.getOperand(3));
7340 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007341 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007342 }
7343 break;
7344 }
7345 case ARM::t2MOVr: {
7346 // If we can use the 16-bit encoding and the user didn't explicitly
7347 // request the 32-bit variant, transform it here.
7348 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7349 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7350 Inst.getOperand(2).getImm() == ARMCC::AL &&
7351 Inst.getOperand(4).getReg() == ARM::CPSR &&
7352 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7353 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7354 // The operands aren't the same for tMOV[S]r... (no cc_out)
7355 MCInst TmpInst;
7356 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7357 TmpInst.addOperand(Inst.getOperand(0));
7358 TmpInst.addOperand(Inst.getOperand(1));
7359 TmpInst.addOperand(Inst.getOperand(2));
7360 TmpInst.addOperand(Inst.getOperand(3));
7361 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007362 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007363 }
7364 break;
7365 }
Jim Grosbach82213192011-09-19 20:29:33 +00007366 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007367 case ARM::t2SXTB:
7368 case ARM::t2UXTH:
7369 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007370 // If we can use the 16-bit encoding and the user didn't explicitly
7371 // request the 32-bit variant, transform it here.
7372 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7373 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7374 Inst.getOperand(2).getImm() == 0 &&
7375 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7376 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007377 unsigned NewOpc;
7378 switch (Inst.getOpcode()) {
7379 default: llvm_unreachable("Illegal opcode!");
7380 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7381 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7382 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7383 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7384 }
Jim Grosbach82213192011-09-19 20:29:33 +00007385 // The operands aren't the same for thumb1 (no rotate operand).
7386 MCInst TmpInst;
7387 TmpInst.setOpcode(NewOpc);
7388 TmpInst.addOperand(Inst.getOperand(0));
7389 TmpInst.addOperand(Inst.getOperand(1));
7390 TmpInst.addOperand(Inst.getOperand(3));
7391 TmpInst.addOperand(Inst.getOperand(4));
7392 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007393 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007394 }
7395 break;
7396 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007397 case ARM::MOVsi: {
7398 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007399 // rrx shifts and asr/lsr of #32 is encoded as 0
7400 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7401 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007402 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7403 // Shifting by zero is accepted as a vanilla 'MOVr'
7404 MCInst TmpInst;
7405 TmpInst.setOpcode(ARM::MOVr);
7406 TmpInst.addOperand(Inst.getOperand(0));
7407 TmpInst.addOperand(Inst.getOperand(1));
7408 TmpInst.addOperand(Inst.getOperand(3));
7409 TmpInst.addOperand(Inst.getOperand(4));
7410 TmpInst.addOperand(Inst.getOperand(5));
7411 Inst = TmpInst;
7412 return true;
7413 }
7414 return false;
7415 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007416 case ARM::ANDrsi:
7417 case ARM::ORRrsi:
7418 case ARM::EORrsi:
7419 case ARM::BICrsi:
7420 case ARM::SUBrsi:
7421 case ARM::ADDrsi: {
7422 unsigned newOpc;
7423 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7424 if (SOpc == ARM_AM::rrx) return false;
7425 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007426 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007427 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7428 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7429 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7430 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7431 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7432 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7433 }
7434 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007435 // The exception is for right shifts, where 0 == 32
7436 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7437 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007438 MCInst TmpInst;
7439 TmpInst.setOpcode(newOpc);
7440 TmpInst.addOperand(Inst.getOperand(0));
7441 TmpInst.addOperand(Inst.getOperand(1));
7442 TmpInst.addOperand(Inst.getOperand(2));
7443 TmpInst.addOperand(Inst.getOperand(4));
7444 TmpInst.addOperand(Inst.getOperand(5));
7445 TmpInst.addOperand(Inst.getOperand(6));
7446 Inst = TmpInst;
7447 return true;
7448 }
7449 return false;
7450 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007451 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007452 case ARM::t2IT: {
7453 // The mask bits for all but the first condition are represented as
7454 // the low bit of the condition code value implies 't'. We currently
7455 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007456 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007457 MCOperand &MO = Inst.getOperand(1);
7458 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007459 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007460 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007461 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007462 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007463 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007464 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007465 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007466
7467 // Set up the IT block state according to the IT instruction we just
7468 // matched.
7469 assert(!inITBlock() && "nested IT blocks?!");
7470 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7471 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7472 ITState.CurPosition = 0;
7473 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007474 break;
7475 }
Richard Bartona39625e2012-07-09 16:12:24 +00007476 case ARM::t2LSLrr:
7477 case ARM::t2LSRrr:
7478 case ARM::t2ASRrr:
7479 case ARM::t2SBCrr:
7480 case ARM::t2RORrr:
7481 case ARM::t2BICrr:
7482 {
Richard Bartond5660372012-07-09 16:14:28 +00007483 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007484 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7485 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7486 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007487 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7488 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007489 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7490 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7491 unsigned NewOpc;
7492 switch (Inst.getOpcode()) {
7493 default: llvm_unreachable("unexpected opcode");
7494 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7495 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7496 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7497 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7498 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7499 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7500 }
7501 MCInst TmpInst;
7502 TmpInst.setOpcode(NewOpc);
7503 TmpInst.addOperand(Inst.getOperand(0));
7504 TmpInst.addOperand(Inst.getOperand(5));
7505 TmpInst.addOperand(Inst.getOperand(1));
7506 TmpInst.addOperand(Inst.getOperand(2));
7507 TmpInst.addOperand(Inst.getOperand(3));
7508 TmpInst.addOperand(Inst.getOperand(4));
7509 Inst = TmpInst;
7510 return true;
7511 }
7512 return false;
7513 }
7514 case ARM::t2ANDrr:
7515 case ARM::t2EORrr:
7516 case ARM::t2ADCrr:
7517 case ARM::t2ORRrr:
7518 {
Richard Bartond5660372012-07-09 16:14:28 +00007519 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007520 // These instructions are special in that they are commutable, so shorter encodings
7521 // are available more often.
7522 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7523 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7524 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7525 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007526 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7527 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007528 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7529 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7530 unsigned NewOpc;
7531 switch (Inst.getOpcode()) {
7532 default: llvm_unreachable("unexpected opcode");
7533 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7534 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7535 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7536 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7537 }
7538 MCInst TmpInst;
7539 TmpInst.setOpcode(NewOpc);
7540 TmpInst.addOperand(Inst.getOperand(0));
7541 TmpInst.addOperand(Inst.getOperand(5));
7542 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7543 TmpInst.addOperand(Inst.getOperand(1));
7544 TmpInst.addOperand(Inst.getOperand(2));
7545 } else {
7546 TmpInst.addOperand(Inst.getOperand(2));
7547 TmpInst.addOperand(Inst.getOperand(1));
7548 }
7549 TmpInst.addOperand(Inst.getOperand(3));
7550 TmpInst.addOperand(Inst.getOperand(4));
7551 Inst = TmpInst;
7552 return true;
7553 }
7554 return false;
7555 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007556 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007557 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007558}
7559
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007560unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7561 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7562 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007563 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007564 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007565 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7566 assert(MCID.hasOptionalDef() &&
7567 "optionally flag setting instruction missing optional def operand");
7568 assert(MCID.NumOperands == Inst.getNumOperands() &&
7569 "operand count mismatch!");
7570 // Find the optional-def operand (cc_out).
7571 unsigned OpNo;
7572 for (OpNo = 0;
7573 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7574 ++OpNo)
7575 ;
7576 // If we're parsing Thumb1, reject it completely.
7577 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7578 return Match_MnemonicFail;
7579 // If we're parsing Thumb2, which form is legal depends on whether we're
7580 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007581 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7582 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007583 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007584 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7585 inITBlock())
7586 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007587 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007588 // Some high-register supporting Thumb1 encodings only allow both registers
7589 // to be from r0-r7 when in Thumb2.
7590 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7591 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7592 isARMLowRegister(Inst.getOperand(2).getReg()))
7593 return Match_RequiresThumb2;
7594 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007595 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007596 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7597 isARMLowRegister(Inst.getOperand(1).getReg()))
7598 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007599 return Match_Success;
7600}
7601
Jim Grosbach5117ef72012-04-24 22:40:08 +00007602static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007603bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007604MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007605 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007606 MCStreamer &Out, unsigned &ErrorInfo,
7607 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007608 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007609 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007610
Chad Rosier2f480a82012-10-12 22:53:36 +00007611 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007612 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007613 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007614 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007615 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007616 // Context sensitive operand constraints aren't handled by the matcher,
7617 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007618 if (validateInstruction(Inst, Operands)) {
7619 // Still progress the IT block, otherwise one wrong condition causes
7620 // nasty cascading errors.
7621 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007622 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007623 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007624
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007625 { // processInstruction() updates inITBlock state, we need to save it away
7626 bool wasInITBlock = inITBlock();
7627
7628 // Some instructions need post-processing to, for example, tweak which
7629 // encoding is selected. Loop on it while changes happen so the
7630 // individual transformations can chain off each other. E.g.,
7631 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7632 while (processInstruction(Inst, Operands))
7633 ;
7634
7635 // Only after the instruction is fully processed, we can validate it
7636 if (wasInITBlock && hasV8Ops() && isThumb() &&
7637 !isV8EligibleForIT(&Inst, 2)) {
7638 Warning(IDLoc, "deprecated instruction in IT block");
7639 }
7640 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007641
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007642 // Only move forward at the very end so that everything in validate
7643 // and process gets a consistent answer about whether we're in an IT
7644 // block.
7645 forwardITPosition();
7646
Jim Grosbach82f76d12012-01-25 19:52:01 +00007647 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7648 // doesn't actually encode.
7649 if (Inst.getOpcode() == ARM::ITasm)
7650 return false;
7651
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007652 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007653 Out.EmitInstruction(Inst);
7654 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007655 case Match_MissingFeature: {
7656 assert(ErrorInfo && "Unknown missing feature!");
7657 // Special case the error message for the very common case where only
7658 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7659 std::string Msg = "instruction requires:";
7660 unsigned Mask = 1;
7661 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7662 if (ErrorInfo & Mask) {
7663 Msg += " ";
7664 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7665 }
7666 Mask <<= 1;
7667 }
7668 return Error(IDLoc, Msg);
7669 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007670 case Match_InvalidOperand: {
7671 SMLoc ErrorLoc = IDLoc;
7672 if (ErrorInfo != ~0U) {
7673 if (ErrorInfo >= Operands.size())
7674 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007675
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007676 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7677 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7678 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007679
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007680 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007681 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007682 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007683 return Error(IDLoc, "invalid instruction",
7684 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007685 case Match_RequiresNotITBlock:
7686 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007687 case Match_RequiresITBlock:
7688 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007689 case Match_RequiresV6:
7690 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7691 case Match_RequiresThumb2:
7692 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007693 case Match_ImmRange0_15: {
7694 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7695 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7696 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7697 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007698 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007699
Eric Christopher91d7b902010-10-29 09:26:59 +00007700 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007701}
7702
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007703/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007704bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7705 StringRef IDVal = DirectiveID.getIdentifier();
7706 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007707 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007708 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007709 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007710 else if (IDVal == ".arm")
7711 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007712 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007713 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007714 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007715 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007716 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007717 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007718 else if (IDVal == ".unreq")
7719 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007720 else if (IDVal == ".arch")
7721 return parseDirectiveArch(DirectiveID.getLoc());
7722 else if (IDVal == ".eabi_attribute")
7723 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007724 else if (IDVal == ".fnstart")
7725 return parseDirectiveFnStart(DirectiveID.getLoc());
7726 else if (IDVal == ".fnend")
7727 return parseDirectiveFnEnd(DirectiveID.getLoc());
7728 else if (IDVal == ".cantunwind")
7729 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7730 else if (IDVal == ".personality")
7731 return parseDirectivePersonality(DirectiveID.getLoc());
7732 else if (IDVal == ".handlerdata")
7733 return parseDirectiveHandlerData(DirectiveID.getLoc());
7734 else if (IDVal == ".setfp")
7735 return parseDirectiveSetFP(DirectiveID.getLoc());
7736 else if (IDVal == ".pad")
7737 return parseDirectivePad(DirectiveID.getLoc());
7738 else if (IDVal == ".save")
7739 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7740 else if (IDVal == ".vsave")
7741 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007742 return true;
7743}
7744
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007745/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007746/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007747bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007748 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7749 for (;;) {
7750 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007751 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007752 return true;
7753
Eric Christopherbf7bc492013-01-09 03:52:05 +00007754 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007755
7756 if (getLexer().is(AsmToken::EndOfStatement))
7757 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007758
Kevin Enderbyccab3172009-09-15 00:27:25 +00007759 // FIXME: Improve diagnostic.
7760 if (getLexer().isNot(AsmToken::Comma))
7761 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007762 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007763 }
7764 }
7765
Sean Callanana83fd7d2010-01-19 20:27:46 +00007766 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007767 return false;
7768}
7769
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007770/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007771/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007772bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007773 if (getLexer().isNot(AsmToken::EndOfStatement))
7774 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007775 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007776
Tim Northovera2292d02013-06-10 23:20:58 +00007777 if (!hasThumb())
7778 return Error(L, "target does not support Thumb mode");
7779
Jim Grosbach7f882392011-12-07 18:04:19 +00007780 if (!isThumb())
7781 SwitchMode();
7782 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7783 return false;
7784}
7785
7786/// parseDirectiveARM
7787/// ::= .arm
7788bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7789 if (getLexer().isNot(AsmToken::EndOfStatement))
7790 return Error(L, "unexpected token in directive");
7791 Parser.Lex();
7792
Tim Northovera2292d02013-06-10 23:20:58 +00007793 if (!hasARM())
7794 return Error(L, "target does not support ARM mode");
7795
Jim Grosbach7f882392011-12-07 18:04:19 +00007796 if (isThumb())
7797 SwitchMode();
7798 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007799 return false;
7800}
7801
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007802/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007803/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007804bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007805 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7806 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007807 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007808 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007809
Jim Grosbach1152cc02011-12-21 22:30:16 +00007810 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007811 // ELF doesn't
7812 if (isMachO) {
7813 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007814 if (Tok.isNot(AsmToken::EndOfStatement)) {
7815 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7816 return Error(L, "unexpected token in .thumb_func directive");
7817 Name = Tok.getIdentifier();
7818 Parser.Lex(); // Consume the identifier token.
7819 needFuncName = false;
7820 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007821 }
7822
Jim Grosbach1152cc02011-12-21 22:30:16 +00007823 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007824 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007825
7826 // Eat the end of statement and any blank lines that follow.
7827 while (getLexer().is(AsmToken::EndOfStatement))
7828 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007829
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007830 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007831 // We really should be checking the next symbol definition even if there's
7832 // stuff in between.
7833 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007834 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007835 }
7836
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007837 // Mark symbol as a thumb symbol.
7838 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7839 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007840 return false;
7841}
7842
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007843/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007844/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007845bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007846 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007847 if (Tok.isNot(AsmToken::Identifier))
7848 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007849 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007850 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007851 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007852 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007853 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007854 else
7855 return Error(L, "unrecognized syntax mode in .syntax directive");
7856
7857 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007858 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007859 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007860
7861 // TODO tell the MC streamer the mode
7862 // getParser().getStreamer().Emit???();
7863 return false;
7864}
7865
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007866/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007867/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007868bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007869 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007870 if (Tok.isNot(AsmToken::Integer))
7871 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007872 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007873 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007874 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007875 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007876 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007877 else
7878 return Error(L, "invalid operand to .code directive");
7879
7880 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007881 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007882 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007883
Evan Cheng284b4672011-07-08 22:36:29 +00007884 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007885 if (!hasThumb())
7886 return Error(L, "target does not support Thumb mode");
7887
Jim Grosbachf471ac32011-09-06 18:46:23 +00007888 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007889 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007890 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007891 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007892 if (!hasARM())
7893 return Error(L, "target does not support ARM mode");
7894
Jim Grosbachf471ac32011-09-06 18:46:23 +00007895 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007896 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007897 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007898 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007899
Kevin Enderby146dcf22009-10-15 20:48:48 +00007900 return false;
7901}
7902
Jim Grosbachab5830e2011-12-14 02:16:11 +00007903/// parseDirectiveReq
7904/// ::= name .req registername
7905bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7906 Parser.Lex(); // Eat the '.req' token.
7907 unsigned Reg;
7908 SMLoc SRegLoc, ERegLoc;
7909 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007910 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007911 return Error(SRegLoc, "register name expected");
7912 }
7913
7914 // Shouldn't be anything else.
7915 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007916 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007917 return Error(Parser.getTok().getLoc(),
7918 "unexpected input in .req directive.");
7919 }
7920
7921 Parser.Lex(); // Consume the EndOfStatement
7922
7923 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7924 return Error(SRegLoc, "redefinition of '" + Name +
7925 "' does not match original.");
7926
7927 return false;
7928}
7929
7930/// parseDirectiveUneq
7931/// ::= .unreq registername
7932bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7933 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007934 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007935 return Error(L, "unexpected input in .unreq directive.");
7936 }
7937 RegisterReqs.erase(Parser.getTok().getIdentifier());
7938 Parser.Lex(); // Eat the identifier.
7939 return false;
7940}
7941
Jason W Kim135d2442011-12-20 17:38:12 +00007942/// parseDirectiveArch
7943/// ::= .arch token
7944bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7945 return true;
7946}
7947
7948/// parseDirectiveEabiAttr
7949/// ::= .eabi_attribute int, int
7950bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7951 return true;
7952}
7953
Logan Chien4ea23b52013-05-10 16:17:24 +00007954/// parseDirectiveFnStart
7955/// ::= .fnstart
7956bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7957 if (FnStartLoc.isValid()) {
7958 Error(L, ".fnstart starts before the end of previous one");
7959 Error(FnStartLoc, "previous .fnstart starts here");
7960 return true;
7961 }
7962
7963 FnStartLoc = L;
7964 getParser().getStreamer().EmitFnStart();
7965 return false;
7966}
7967
7968/// parseDirectiveFnEnd
7969/// ::= .fnend
7970bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7971 // Check the ordering of unwind directives
7972 if (!FnStartLoc.isValid())
7973 return Error(L, ".fnstart must precede .fnend directive");
7974
7975 // Reset the unwind directives parser state
7976 resetUnwindDirectiveParserState();
7977
7978 getParser().getStreamer().EmitFnEnd();
7979 return false;
7980}
7981
7982/// parseDirectiveCantUnwind
7983/// ::= .cantunwind
7984bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7985 // Check the ordering of unwind directives
7986 CantUnwindLoc = L;
7987 if (!FnStartLoc.isValid())
7988 return Error(L, ".fnstart must precede .cantunwind directive");
7989 if (HandlerDataLoc.isValid()) {
7990 Error(L, ".cantunwind can't be used with .handlerdata directive");
7991 Error(HandlerDataLoc, ".handlerdata was specified here");
7992 return true;
7993 }
7994 if (PersonalityLoc.isValid()) {
7995 Error(L, ".cantunwind can't be used with .personality directive");
7996 Error(PersonalityLoc, ".personality was specified here");
7997 return true;
7998 }
7999
8000 getParser().getStreamer().EmitCantUnwind();
8001 return false;
8002}
8003
8004/// parseDirectivePersonality
8005/// ::= .personality name
8006bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8007 // Check the ordering of unwind directives
8008 PersonalityLoc = L;
8009 if (!FnStartLoc.isValid())
8010 return Error(L, ".fnstart must precede .personality directive");
8011 if (CantUnwindLoc.isValid()) {
8012 Error(L, ".personality can't be used with .cantunwind directive");
8013 Error(CantUnwindLoc, ".cantunwind was specified here");
8014 return true;
8015 }
8016 if (HandlerDataLoc.isValid()) {
8017 Error(L, ".personality must precede .handlerdata directive");
8018 Error(HandlerDataLoc, ".handlerdata was specified here");
8019 return true;
8020 }
8021
8022 // Parse the name of the personality routine
8023 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8024 Parser.eatToEndOfStatement();
8025 return Error(L, "unexpected input in .personality directive.");
8026 }
8027 StringRef Name(Parser.getTok().getIdentifier());
8028 Parser.Lex();
8029
8030 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8031 getParser().getStreamer().EmitPersonality(PR);
8032 return false;
8033}
8034
8035/// parseDirectiveHandlerData
8036/// ::= .handlerdata
8037bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8038 // Check the ordering of unwind directives
8039 HandlerDataLoc = L;
8040 if (!FnStartLoc.isValid())
8041 return Error(L, ".fnstart must precede .personality directive");
8042 if (CantUnwindLoc.isValid()) {
8043 Error(L, ".handlerdata can't be used with .cantunwind directive");
8044 Error(CantUnwindLoc, ".cantunwind was specified here");
8045 return true;
8046 }
8047
8048 getParser().getStreamer().EmitHandlerData();
8049 return false;
8050}
8051
8052/// parseDirectiveSetFP
8053/// ::= .setfp fpreg, spreg [, offset]
8054bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8055 // Check the ordering of unwind directives
8056 if (!FnStartLoc.isValid())
8057 return Error(L, ".fnstart must precede .setfp directive");
8058 if (HandlerDataLoc.isValid())
8059 return Error(L, ".setfp must precede .handlerdata directive");
8060
8061 // Parse fpreg
8062 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8063 int NewFPReg = tryParseRegister();
8064 if (NewFPReg == -1)
8065 return Error(NewFPRegLoc, "frame pointer register expected");
8066
8067 // Consume comma
8068 if (!Parser.getTok().is(AsmToken::Comma))
8069 return Error(Parser.getTok().getLoc(), "comma expected");
8070 Parser.Lex(); // skip comma
8071
8072 // Parse spreg
8073 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8074 int NewSPReg = tryParseRegister();
8075 if (NewSPReg == -1)
8076 return Error(NewSPRegLoc, "stack pointer register expected");
8077
8078 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8079 return Error(NewSPRegLoc,
8080 "register should be either $sp or the latest fp register");
8081
8082 // Update the frame pointer register
8083 FPReg = NewFPReg;
8084
8085 // Parse offset
8086 int64_t Offset = 0;
8087 if (Parser.getTok().is(AsmToken::Comma)) {
8088 Parser.Lex(); // skip comma
8089
8090 if (Parser.getTok().isNot(AsmToken::Hash) &&
8091 Parser.getTok().isNot(AsmToken::Dollar)) {
8092 return Error(Parser.getTok().getLoc(), "'#' expected");
8093 }
8094 Parser.Lex(); // skip hash token.
8095
8096 const MCExpr *OffsetExpr;
8097 SMLoc ExLoc = Parser.getTok().getLoc();
8098 SMLoc EndLoc;
8099 if (getParser().parseExpression(OffsetExpr, EndLoc))
8100 return Error(ExLoc, "malformed setfp offset");
8101 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8102 if (!CE)
8103 return Error(ExLoc, "setfp offset must be an immediate");
8104
8105 Offset = CE->getValue();
8106 }
8107
8108 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8109 static_cast<unsigned>(NewSPReg),
8110 Offset);
8111 return false;
8112}
8113
8114/// parseDirective
8115/// ::= .pad offset
8116bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8117 // Check the ordering of unwind directives
8118 if (!FnStartLoc.isValid())
8119 return Error(L, ".fnstart must precede .pad directive");
8120 if (HandlerDataLoc.isValid())
8121 return Error(L, ".pad must precede .handlerdata directive");
8122
8123 // Parse the offset
8124 if (Parser.getTok().isNot(AsmToken::Hash) &&
8125 Parser.getTok().isNot(AsmToken::Dollar)) {
8126 return Error(Parser.getTok().getLoc(), "'#' expected");
8127 }
8128 Parser.Lex(); // skip hash token.
8129
8130 const MCExpr *OffsetExpr;
8131 SMLoc ExLoc = Parser.getTok().getLoc();
8132 SMLoc EndLoc;
8133 if (getParser().parseExpression(OffsetExpr, EndLoc))
8134 return Error(ExLoc, "malformed pad offset");
8135 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8136 if (!CE)
8137 return Error(ExLoc, "pad offset must be an immediate");
8138
8139 getParser().getStreamer().EmitPad(CE->getValue());
8140 return false;
8141}
8142
8143/// parseDirectiveRegSave
8144/// ::= .save { registers }
8145/// ::= .vsave { registers }
8146bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8147 // Check the ordering of unwind directives
8148 if (!FnStartLoc.isValid())
8149 return Error(L, ".fnstart must precede .save or .vsave directives");
8150 if (HandlerDataLoc.isValid())
8151 return Error(L, ".save or .vsave must precede .handlerdata directive");
8152
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008153 // RAII object to make sure parsed operands are deleted.
8154 struct CleanupObject {
8155 SmallVector<MCParsedAsmOperand *, 1> Operands;
8156 ~CleanupObject() {
8157 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8158 delete Operands[I];
8159 }
8160 } CO;
8161
Logan Chien4ea23b52013-05-10 16:17:24 +00008162 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008163 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008164 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008165 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008166 if (!IsVector && !Op->isRegList())
8167 return Error(L, ".save expects GPR registers");
8168 if (IsVector && !Op->isDPRRegList())
8169 return Error(L, ".vsave expects DPR registers");
8170
8171 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8172 return false;
8173}
8174
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008175/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008176extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008177 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8178 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008179}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008180
Chris Lattner3e4582a2010-09-06 19:11:01 +00008181#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008182#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008183#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008184#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008185
8186// Define this matcher function after the auto-generated include so we
8187// have the match class enum definitions.
8188unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8189 unsigned Kind) {
8190 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8191 // If the kind is a token for a literal immediate, check if our asm
8192 // operand matches. This is for InstAliases which have a fixed-value
8193 // immediate in the syntax.
8194 if (Kind == MCK__35_0 && Op->isImm()) {
8195 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8196 if (!CE)
8197 return Match_InvalidOperand;
8198 if (CE->getValue() == 0)
8199 return Match_Success;
8200 }
8201 return Match_InvalidOperand;
8202}