blob: edb7ccdc293574daff61b8118750e05d7905f071 [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000027#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/MC/MCParser/MCAsmLexer.h"
29#include "llvm/MC/MCParser/MCAsmParser.h"
30#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
31#include "llvm/MC/MCRegisterInfo.h"
32#include "llvm/MC/MCStreamer.h"
33#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000034#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/Support/MathExtras.h"
36#include "llvm/Support/SourceMgr.h"
37#include "llvm/Support/TargetRegistry.h"
38#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000039
Kevin Enderbyccab3172009-09-15 00:27:25 +000040using namespace llvm;
41
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000042namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000043
44class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000045
Jim Grosbach04945c42011-12-02 00:35:16 +000046enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000047
Evan Cheng11424442011-07-26 00:24:13 +000048class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000049 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000050 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +000051 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000052 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000053
Logan Chien4ea23b52013-05-10 16:17:24 +000054 // Unwind directives state
55 SMLoc FnStartLoc;
56 SMLoc CantUnwindLoc;
57 SMLoc PersonalityLoc;
58 SMLoc HandlerDataLoc;
59 int FPReg;
60 void resetUnwindDirectiveParserState() {
61 FnStartLoc = SMLoc();
62 CantUnwindLoc = SMLoc();
63 PersonalityLoc = SMLoc();
64 HandlerDataLoc = SMLoc();
65 FPReg = -1;
66 }
67
Jim Grosbachab5830e2011-12-14 02:16:11 +000068 // Map of register aliases registers via the .req directive.
69 StringMap<unsigned> RegisterReqs;
70
Jim Grosbached16ec42011-08-29 22:24:09 +000071 struct {
72 ARMCC::CondCodes Cond; // Condition for IT block.
73 unsigned Mask:4; // Condition mask for instructions.
74 // Starting at first 1 (from lsb).
75 // '1' condition as indicated in IT.
76 // '0' inverse of condition (else).
77 // Count of instructions in IT block is
78 // 4 - trailingzeroes(mask)
79
80 bool FirstCond; // Explicit flag for when we're parsing the
81 // First instruction in the IT block. It's
82 // implied in the mask, so needs special
83 // handling.
84
85 unsigned CurPosition; // Current position in parsing of IT
86 // block. In range [0,3]. Initialized
87 // according to count of instructions in block.
88 // ~0U if no active IT block.
89 } ITState;
90 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000091 void forwardITPosition() {
92 if (!inITBlock()) return;
93 // Move to the next instruction in the IT block, if there is one. If not,
94 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000095 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000096 if (++ITState.CurPosition == 5 - TZ)
97 ITState.CurPosition = ~0U; // Done with the IT block after this.
98 }
Jim Grosbached16ec42011-08-29 22:24:09 +000099
100
Kevin Enderbyccab3172009-09-15 00:27:25 +0000101 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000102 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
103
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000105 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000106 return Parser.Warning(L, Msg, Ranges);
107 }
108 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000109 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000110 return Parser.Error(L, Msg, Ranges);
111 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000112
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000113 int tryParseRegister();
114 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000115 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000117 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000118 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
119 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000120 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
121 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000122 bool parseDirectiveWord(unsigned Size, SMLoc L);
123 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000124 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000125 bool parseDirectiveThumbFunc(SMLoc L);
126 bool parseDirectiveCode(SMLoc L);
127 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000128 bool parseDirectiveReq(StringRef Name, SMLoc L);
129 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000130 bool parseDirectiveArch(SMLoc L);
131 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000132 bool parseDirectiveFnStart(SMLoc L);
133 bool parseDirectiveFnEnd(SMLoc L);
134 bool parseDirectiveCantUnwind(SMLoc L);
135 bool parseDirectivePersonality(SMLoc L);
136 bool parseDirectiveHandlerData(SMLoc L);
137 bool parseDirectiveSetFP(SMLoc L);
138 bool parseDirectivePad(SMLoc L);
139 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000140
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000141 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000142 bool &CarrySetting, unsigned &ProcessorIMod,
143 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000144 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
145 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000146 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000147
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 bool isThumb() const {
149 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000152 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000154 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000155 bool isThumbTwo() const {
156 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
157 }
Tim Northovera2292d02013-06-10 23:20:58 +0000158 bool hasThumb() const {
159 return STI.getFeatureBits() & ARM::HasV4TOps;
160 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000161 bool hasV6Ops() const {
162 return STI.getFeatureBits() & ARM::HasV6Ops;
163 }
James Molloy21efa7d2011-09-28 14:21:38 +0000164 bool hasV7Ops() const {
165 return STI.getFeatureBits() & ARM::HasV7Ops;
166 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000167 bool hasV8Ops() const {
168 return STI.getFeatureBits() & ARM::HasV8Ops;
169 }
Tim Northovera2292d02013-06-10 23:20:58 +0000170 bool hasARM() const {
171 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
172 }
173
Evan Cheng284b4672011-07-08 22:36:29 +0000174 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000175 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
176 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000177 }
James Molloy21efa7d2011-09-28 14:21:38 +0000178 bool isMClass() const {
179 return STI.getFeatureBits() & ARM::FeatureMClass;
180 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000181
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000182 /// @name Auto-generated Match Functions
183 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000184
Chris Lattner3e4582a2010-09-06 19:11:01 +0000185#define GET_ASSEMBLER_HEADER
186#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000187
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000188 /// }
189
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000190 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000191 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000192 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000193 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000194 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000195 OperandMatchResultTy parseCoprocOptionOperand(
196 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000197 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000198 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000199 OperandMatchResultTy parseInstSyncBarrierOptOperand(
200 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000201 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000202 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000203 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000204 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000205 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
206 StringRef Op, int Low, int High);
207 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "lsl", 0, 31);
209 }
210 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
211 return parsePKHImm(O, "asr", 1, 32);
212 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000213 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000214 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000215 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000216 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000217 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000218 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000219 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000220 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000221 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
222 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000223
224 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000225 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000226 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000227 void cvtThumbBranches(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &);
229
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000230 bool validateInstruction(MCInst &Inst,
231 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000232 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000233 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000234 bool shouldOmitCCOutOperand(StringRef Mnemonic,
235 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000236 bool shouldOmitPredicateOperand(StringRef Mnemonic,
237 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000238public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000239 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000240 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000241 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000242 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000243 Match_RequiresThumb2,
244#define GET_OPERAND_DIAGNOSTIC_TYPES
245#include "ARMGenAsmMatcher.inc"
246
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000247 };
248
Joey Gouly0e76fa72013-09-12 10:28:05 +0000249 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
250 const MCInstrInfo &MII)
251 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000252 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000253
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000254 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000255 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000256
Evan Cheng4d1ca962011-07-08 01:53:10 +0000257 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000258 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000259
260 // Not in an ITBlock to start with.
261 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000262
263 // Set ELF header flags.
264 // FIXME: This should eventually end up somewhere else where more
265 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000266 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
267 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
268 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000269 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000270
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000271 // Implementation of the MCTargetAsmParser interface:
272 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000273 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
274 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000275 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000276 bool ParseDirective(AsmToken DirectiveID);
277
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000278 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000279 unsigned checkTargetMatchPredicate(MCInst &Inst);
280
Chad Rosier49963552012-10-13 00:26:04 +0000281 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000282 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000283 MCStreamer &Out, unsigned &ErrorInfo,
284 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000285};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000286} // end anonymous namespace
287
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000288namespace {
289
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000290/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000291/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000292class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000293 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000294 k_CondCode,
295 k_CCOut,
296 k_ITCondMask,
297 k_CoprocNum,
298 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000299 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000300 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000301 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000302 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000303 k_Memory,
304 k_PostIndexRegister,
305 k_MSRMask,
306 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000307 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000308 k_Register,
309 k_RegisterList,
310 k_DPRRegisterList,
311 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000312 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000313 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000314 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000315 k_ShiftedRegister,
316 k_ShiftedImmediate,
317 k_ShifterImmediate,
318 k_RotateImmediate,
319 k_BitfieldDescriptor,
320 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000321 } Kind;
322
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000323 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000324 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000325
Eric Christopher8996c5d2013-03-15 00:42:55 +0000326 struct CCOp {
327 ARMCC::CondCodes Val;
328 };
329
330 struct CopOp {
331 unsigned Val;
332 };
333
334 struct CoprocOptionOp {
335 unsigned Val;
336 };
337
338 struct ITMaskOp {
339 unsigned Mask:4;
340 };
341
342 struct MBOptOp {
343 ARM_MB::MemBOpt Val;
344 };
345
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000346 struct ISBOptOp {
347 ARM_ISB::InstSyncBOpt Val;
348 };
349
Eric Christopher8996c5d2013-03-15 00:42:55 +0000350 struct IFlagsOp {
351 ARM_PROC::IFlags Val;
352 };
353
354 struct MMaskOp {
355 unsigned Val;
356 };
357
358 struct TokOp {
359 const char *Data;
360 unsigned Length;
361 };
362
363 struct RegOp {
364 unsigned RegNum;
365 };
366
367 // A vector register list is a sequential list of 1 to 4 registers.
368 struct VectorListOp {
369 unsigned RegNum;
370 unsigned Count;
371 unsigned LaneIndex;
372 bool isDoubleSpaced;
373 };
374
375 struct VectorIndexOp {
376 unsigned Val;
377 };
378
379 struct ImmOp {
380 const MCExpr *Val;
381 };
382
383 /// Combined record for all forms of ARM address expressions.
384 struct MemoryOp {
385 unsigned BaseRegNum;
386 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
387 // was specified.
388 const MCConstantExpr *OffsetImm; // Offset immediate value
389 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
390 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
391 unsigned ShiftImm; // shift for OffsetReg.
392 unsigned Alignment; // 0 = no alignment specified
393 // n = alignment in bytes (2, 4, 8, 16, or 32)
394 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
395 };
396
397 struct PostIdxRegOp {
398 unsigned RegNum;
399 bool isAdd;
400 ARM_AM::ShiftOpc ShiftTy;
401 unsigned ShiftImm;
402 };
403
404 struct ShifterImmOp {
405 bool isASR;
406 unsigned Imm;
407 };
408
409 struct RegShiftedRegOp {
410 ARM_AM::ShiftOpc ShiftTy;
411 unsigned SrcReg;
412 unsigned ShiftReg;
413 unsigned ShiftImm;
414 };
415
416 struct RegShiftedImmOp {
417 ARM_AM::ShiftOpc ShiftTy;
418 unsigned SrcReg;
419 unsigned ShiftImm;
420 };
421
422 struct RotImmOp {
423 unsigned Imm;
424 };
425
426 struct BitfieldOp {
427 unsigned LSB;
428 unsigned Width;
429 };
430
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000431 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000432 struct CCOp CC;
433 struct CopOp Cop;
434 struct CoprocOptionOp CoprocOption;
435 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000436 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000437 struct ITMaskOp ITMask;
438 struct IFlagsOp IFlags;
439 struct MMaskOp MMask;
440 struct TokOp Tok;
441 struct RegOp Reg;
442 struct VectorListOp VectorList;
443 struct VectorIndexOp VectorIndex;
444 struct ImmOp Imm;
445 struct MemoryOp Memory;
446 struct PostIdxRegOp PostIdxReg;
447 struct ShifterImmOp ShifterImm;
448 struct RegShiftedRegOp RegShiftedReg;
449 struct RegShiftedImmOp RegShiftedImm;
450 struct RotImmOp RotImm;
451 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000452 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000453
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000454 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
455public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000456 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
457 Kind = o.Kind;
458 StartLoc = o.StartLoc;
459 EndLoc = o.EndLoc;
460 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000462 CC = o.CC;
463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000465 ITMask = o.ITMask;
466 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000467 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000468 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000469 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000470 case k_CCOut:
471 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000472 Reg = o.Reg;
473 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000474 case k_RegisterList:
475 case k_DPRRegisterList:
476 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000477 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000478 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000479 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000480 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000481 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000482 VectorList = o.VectorList;
483 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000484 case k_CoprocNum:
485 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000486 Cop = o.Cop;
487 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000488 case k_CoprocOption:
489 CoprocOption = o.CoprocOption;
490 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000491 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000492 Imm = o.Imm;
493 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000494 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000495 MBOpt = o.MBOpt;
496 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000497 case k_InstSyncBarrierOpt:
498 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000500 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000503 PostIdxReg = o.PostIdxReg;
504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000505 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000506 MMask = o.MMask;
507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000508 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000509 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000510 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000511 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000512 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000514 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000515 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000517 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000518 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000520 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000521 RotImm = o.RotImm;
522 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000523 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000524 Bitfield = o.Bitfield;
525 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000526 case k_VectorIndex:
527 VectorIndex = o.VectorIndex;
528 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000529 }
530 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000531
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000532 /// getStartLoc - Get the location of the first token of this operand.
533 SMLoc getStartLoc() const { return StartLoc; }
534 /// getEndLoc - Get the location of the last token of this operand.
535 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000536 /// getLocRange - Get the range between the first and last token of this
537 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000538 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
539
Daniel Dunbard8042b72010-08-11 06:36:53 +0000540 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000542 return CC.Val;
543 }
544
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000545 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000546 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000547 return Cop.Val;
548 }
549
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000550 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000552 return StringRef(Tok.Data, Tok.Length);
553 }
554
555 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000557 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000558 }
559
Bill Wendlingbed94652010-11-09 23:28:44 +0000560 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000561 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
562 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000563 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000564 }
565
Kevin Enderbyf5079942009-10-13 22:19:02 +0000566 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000567 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000568 return Imm.Val;
569 }
570
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000571 unsigned getVectorIndex() const {
572 assert(Kind == k_VectorIndex && "Invalid access!");
573 return VectorIndex.Val;
574 }
575
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000576 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000577 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000578 return MBOpt.Val;
579 }
580
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000581 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
582 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
583 return ISBOpt.Val;
584 }
585
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000586 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000587 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000588 return IFlags.Val;
589 }
590
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000591 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000592 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000593 return MMask.Val;
594 }
595
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000596 bool isCoprocNum() const { return Kind == k_CoprocNum; }
597 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000598 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 bool isCondCode() const { return Kind == k_CondCode; }
600 bool isCCOut() const { return Kind == k_CCOut; }
601 bool isITMask() const { return Kind == k_ITCondMask; }
602 bool isITCondCode() const { return Kind == k_CondCode; }
603 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000604 // checks whether this operand is an unsigned offset which fits is a field
605 // of specified width and scaled by a specific number of bits
606 template<unsigned width, unsigned scale>
607 bool isUnsignedOffset() const {
608 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000609 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000610 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
611 int64_t Val = CE->getValue();
612 int64_t Align = 1LL << scale;
613 int64_t Max = Align * ((1LL << width) - 1);
614 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
615 }
616 return false;
617 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000618 // checks whether this operand is an signed offset which fits is a field
619 // of specified width and scaled by a specific number of bits
620 template<unsigned width, unsigned scale>
621 bool isSignedOffset() const {
622 if (!isImm()) return false;
623 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
624 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
625 int64_t Val = CE->getValue();
626 int64_t Align = 1LL << scale;
627 int64_t Max = Align * ((1LL << (width-1)) - 1);
628 int64_t Min = -Align * (1LL << (width-1));
629 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
630 }
631 return false;
632 }
633
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000634 // checks whether this operand is a memory operand computed as an offset
635 // applied to PC. the offset may have 8 bits of magnitude and is represented
636 // with two bits of shift. textually it may be either [pc, #imm], #imm or
637 // relocable expression...
638 bool isThumbMemPC() const {
639 int64_t Val = 0;
640 if (isImm()) {
641 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
643 if (!CE) return false;
644 Val = CE->getValue();
645 }
646 else if (isMem()) {
647 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
648 if(Memory.BaseRegNum != ARM::PC) return false;
649 Val = Memory.OffsetImm->getValue();
650 }
651 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000652 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000653 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000654 bool isFPImm() const {
655 if (!isImm()) return false;
656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
659 return Val != -1;
660 }
Jim Grosbachea231912011-12-22 22:19:05 +0000661 bool isFBits16() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
666 return Value >= 0 && Value <= 16;
667 }
668 bool isFBits32() const {
669 if (!isImm()) return false;
670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return Value >= 1 && Value <= 32;
674 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000675 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
681 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000682 bool isImm0_4() const {
683 if (!isImm()) return false;
684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = CE->getValue();
687 return Value >= 0 && Value < 5;
688 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000689 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000690 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
695 }
696 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000697 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
702 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000703 bool isImm0_508s4Neg() const {
704 if (!isImm()) return false;
705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = -CE->getValue();
708 // explicitly exclude zero. we want that to use the normal 0_508 version.
709 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
710 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000711 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value >= 0 && Value < 256;
717 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000718 bool isImm0_4095() const {
719 if (!isImm()) return false;
720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 4096;
724 }
725 bool isImm0_4095Neg() const {
726 if (!isImm()) return false;
727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = -CE->getValue();
730 return Value > 0 && Value < 4096;
731 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000732 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000733 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value >= 0 && Value < 2;
738 }
739 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000740 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value >= 0 && Value < 4;
745 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000746 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000747 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value >= 0 && Value < 8;
752 }
753 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000754 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value >= 0 && Value < 16;
759 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000760 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000761 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value >= 0 && Value < 32;
766 }
Jim Grosbach00326402011-12-08 01:30:04 +0000767 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value >= 0 && Value < 64;
773 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000774 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value == 8;
780 }
781 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value == 16;
787 }
788 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value == 32;
794 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000795 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000796 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value > 0 && Value <= 8;
801 }
802 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value <= 16;
808 }
809 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000810 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return Value > 0 && Value <= 32;
815 }
816 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return Value > 0 && Value <= 64;
822 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000823 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000824 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return Value > 0 && Value < 8;
829 }
830 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000831 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 if (!CE) return false;
834 int64_t Value = CE->getValue();
835 return Value > 0 && Value < 16;
836 }
837 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000838 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
840 if (!CE) return false;
841 int64_t Value = CE->getValue();
842 return Value > 0 && Value < 32;
843 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000844 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000845 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
847 if (!CE) return false;
848 int64_t Value = CE->getValue();
849 return Value > 0 && Value < 17;
850 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000851 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000852 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
854 if (!CE) return false;
855 int64_t Value = CE->getValue();
856 return Value > 0 && Value < 33;
857 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000858 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000859 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
861 if (!CE) return false;
862 int64_t Value = CE->getValue();
863 return Value >= 0 && Value < 33;
864 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000865 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000866 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
868 if (!CE) return false;
869 int64_t Value = CE->getValue();
870 return Value >= 0 && Value < 65536;
871 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000872 bool isImm256_65535Expr() const {
873 if (!isImm()) return false;
874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
875 // If it's not a constant expression, it'll generate a fixup and be
876 // handled later.
877 if (!CE) return true;
878 int64_t Value = CE->getValue();
879 return Value >= 256 && Value < 65536;
880 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000881 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 // If it's not a constant expression, it'll generate a fixup and be
885 // handled later.
886 if (!CE) return true;
887 int64_t Value = CE->getValue();
888 return Value >= 0 && Value < 65536;
889 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000890 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000891 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
893 if (!CE) return false;
894 int64_t Value = CE->getValue();
895 return Value >= 0 && Value <= 0xffffff;
896 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000897 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000898 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
900 if (!CE) return false;
901 int64_t Value = CE->getValue();
902 return Value > 0 && Value < 33;
903 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000904 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000905 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Value = CE->getValue();
909 return Value >= 0 && Value < 32;
910 }
911 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000912 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
914 if (!CE) return false;
915 int64_t Value = CE->getValue();
916 return Value > 0 && Value <= 32;
917 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000918 bool isAdrLabel() const {
919 // If we have an immediate that's not a constant, treat it as a label
920 // reference needing a fixup. If it is a constant, but it can't fit
921 // into shift immediate encoding, we reject it.
922 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
923 else return (isARMSOImm() || isARMSOImmNeg());
924 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000925 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000926 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return ARM_AM::getSOImmVal(Value) != -1;
931 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000932 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000933 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
937 return ARM_AM::getSOImmVal(~Value) != -1;
938 }
Jim Grosbach30506252011-12-08 00:31:07 +0000939 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000940 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
942 if (!CE) return false;
943 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000944 // Only use this when not representable as a plain so_imm.
945 return ARM_AM::getSOImmVal(Value) == -1 &&
946 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000947 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000948 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000949 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return ARM_AM::getT2SOImmVal(Value) != -1;
954 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000955 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000956 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000960 return ARM_AM::getT2SOImmVal(Value) == -1 &&
961 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000962 }
Jim Grosbach30506252011-12-08 00:31:07 +0000963 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000964 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
966 if (!CE) return false;
967 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000968 // Only use this when not representable as a plain so_imm.
969 return ARM_AM::getT2SOImmVal(Value) == -1 &&
970 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000971 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000972 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000973 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
975 if (!CE) return false;
976 int64_t Value = CE->getValue();
977 return Value == 1 || Value == 0;
978 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000979 bool isReg() const { return Kind == k_Register; }
980 bool isRegList() const { return Kind == k_RegisterList; }
981 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
982 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
983 bool isToken() const { return Kind == k_Token; }
984 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000985 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000986 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000987 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
988 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
989 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
990 bool isRotImm() const { return Kind == k_RotateImmediate; }
991 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
992 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000993 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000994 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000995 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000996 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000997 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000998 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000999 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001000 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1001 (alignOK || Memory.Alignment == 0);
1002 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001003 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001004 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001005 return false;
1006 // Base register must be PC.
1007 if (Memory.BaseRegNum != ARM::PC)
1008 return false;
1009 // Immediate offset in range [-4095, 4095].
1010 if (!Memory.OffsetImm) return true;
1011 int64_t Val = Memory.OffsetImm->getValue();
1012 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1013 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001014 bool isAlignedMemory() const {
1015 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001016 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001017 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001018 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001019 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001020 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001021 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001022 if (!Memory.OffsetImm) return true;
1023 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001024 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001025 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001026 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001027 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001028 // Immediate offset in range [-4095, 4095].
1029 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1030 if (!CE) return false;
1031 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001032 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001033 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001034 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001035 // If we have an immediate that's not a constant, treat it as a label
1036 // reference needing a fixup. If it is a constant, it's something else
1037 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001038 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001039 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001040 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001041 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001042 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001043 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001044 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001045 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001046 if (!Memory.OffsetImm) return true;
1047 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001048 // The #-0 offset is encoded as INT32_MIN, and we have to check
1049 // for this too.
1050 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001051 }
1052 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001053 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001054 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001055 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001056 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1057 // Immediate offset in range [-255, 255].
1058 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1059 if (!CE) return false;
1060 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001061 // Special case, #-0 is INT32_MIN.
1062 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001063 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001064 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001065 // If we have an immediate that's not a constant, treat it as a label
1066 // reference needing a fixup. If it is a constant, it's something else
1067 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001068 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001069 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001070 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001071 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001072 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001073 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001074 if (!Memory.OffsetImm) return true;
1075 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001076 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001077 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001078 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001079 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001081 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001082 return false;
1083 return true;
1084 }
1085 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001086 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001087 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1088 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001089 return false;
1090 return true;
1091 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001092 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001094 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001095 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001096 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001097 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001098 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001099 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001100 return false;
1101 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001102 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001103 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001105 return false;
1106 return true;
1107 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001108 bool isMemThumbRR() const {
1109 // Thumb reg+reg addressing is simple. Just two registers, a base and
1110 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001111 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001112 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001113 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001114 return isARMLowRegister(Memory.BaseRegNum) &&
1115 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001116 }
1117 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001118 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001119 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001120 return false;
1121 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001122 if (!Memory.OffsetImm) return true;
1123 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001124 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1125 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001126 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001128 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001129 return false;
1130 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001133 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1134 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001135 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001136 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001137 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001138 return false;
1139 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001142 return Val >= 0 && Val <= 31;
1143 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001144 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001145 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001146 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001147 return false;
1148 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001149 if (!Memory.OffsetImm) return true;
1150 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001151 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001152 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001153 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001154 // If we have an immediate that's not a constant, treat it as a label
1155 // reference needing a fixup. If it is a constant, it's something else
1156 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001157 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001158 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001159 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001160 return false;
1161 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001162 if (!Memory.OffsetImm) return true;
1163 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001164 // Special case, #-0 is INT32_MIN.
1165 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001166 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001167 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001168 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001169 return false;
1170 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001173 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1174 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001175 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001177 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001178 // Base reg of PC isn't allowed for these encodings.
1179 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001180 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001181 if (!Memory.OffsetImm) return true;
1182 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001183 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001184 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001185 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001187 return false;
1188 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001191 return Val >= 0 && Val < 256;
1192 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001193 bool isMemNegImm8Offset() 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;
Jim Grosbach94298a92012-01-18 22:46:46 +00001196 // Base reg of PC isn't allowed for these encodings.
1197 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001198 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001199 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001200 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001201 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001202 }
1203 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001204 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001205 return false;
1206 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001207 if (!Memory.OffsetImm) return true;
1208 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001209 return (Val >= 0 && Val < 4096);
1210 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001211 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001212 // If we have an immediate that's not a constant, treat it as a label
1213 // reference needing a fixup. If it is a constant, it's something else
1214 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001215 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001216 return true;
1217
Chad Rosier41099832012-09-11 23:02:35 +00001218 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001219 return false;
1220 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001221 if (!Memory.OffsetImm) return true;
1222 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001223 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001224 }
1225 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001226 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001227 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1228 if (!CE) return false;
1229 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001230 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001231 }
Jim Grosbach93981412011-10-11 21:55:36 +00001232 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001233 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001234 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1235 if (!CE) return false;
1236 int64_t Val = CE->getValue();
1237 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1238 (Val == INT32_MIN);
1239 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001240
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001241 bool isMSRMask() const { return Kind == k_MSRMask; }
1242 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001243
Jim Grosbach741cd732011-10-17 22:26:03 +00001244 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001245 bool isSingleSpacedVectorList() const {
1246 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1247 }
1248 bool isDoubleSpacedVectorList() const {
1249 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1250 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001251 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001252 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001253 return VectorList.Count == 1;
1254 }
1255
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001256 bool isVecListDPair() const {
1257 if (!isSingleSpacedVectorList()) return false;
1258 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1259 .contains(VectorList.RegNum));
1260 }
1261
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001262 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001263 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001264 return VectorList.Count == 3;
1265 }
1266
Jim Grosbach846bcff2011-10-21 20:35:01 +00001267 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001268 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001269 return VectorList.Count == 4;
1270 }
1271
Jim Grosbache5307f92012-03-05 21:43:40 +00001272 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001273 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001274 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1275 .contains(VectorList.RegNum));
1276 }
1277
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001278 bool isVecListThreeQ() const {
1279 if (!isDoubleSpacedVectorList()) return false;
1280 return VectorList.Count == 3;
1281 }
1282
Jim Grosbach1e946a42012-01-24 00:43:12 +00001283 bool isVecListFourQ() const {
1284 if (!isDoubleSpacedVectorList()) return false;
1285 return VectorList.Count == 4;
1286 }
1287
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001288 bool isSingleSpacedVectorAllLanes() const {
1289 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1290 }
1291 bool isDoubleSpacedVectorAllLanes() const {
1292 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1293 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001294 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001295 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001296 return VectorList.Count == 1;
1297 }
1298
Jim Grosbach13a292c2012-03-06 22:01:44 +00001299 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001300 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001301 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1302 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001303 }
1304
Jim Grosbached428bc2012-03-06 23:10:38 +00001305 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001306 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001307 return VectorList.Count == 2;
1308 }
1309
Jim Grosbachb78403c2012-01-24 23:47:04 +00001310 bool isVecListThreeDAllLanes() const {
1311 if (!isSingleSpacedVectorAllLanes()) return false;
1312 return VectorList.Count == 3;
1313 }
1314
1315 bool isVecListThreeQAllLanes() const {
1316 if (!isDoubleSpacedVectorAllLanes()) return false;
1317 return VectorList.Count == 3;
1318 }
1319
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001320 bool isVecListFourDAllLanes() const {
1321 if (!isSingleSpacedVectorAllLanes()) return false;
1322 return VectorList.Count == 4;
1323 }
1324
1325 bool isVecListFourQAllLanes() const {
1326 if (!isDoubleSpacedVectorAllLanes()) return false;
1327 return VectorList.Count == 4;
1328 }
1329
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001330 bool isSingleSpacedVectorIndexed() const {
1331 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1332 }
1333 bool isDoubleSpacedVectorIndexed() const {
1334 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1335 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001336 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001337 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001338 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1339 }
1340
Jim Grosbachda511042011-12-14 23:35:06 +00001341 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001342 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001343 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1344 }
1345
1346 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001347 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001348 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1349 }
1350
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001351 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001352 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001353 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1354 }
1355
Jim Grosbachda511042011-12-14 23:35:06 +00001356 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001357 if (!isSingleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1359 }
1360
1361 bool isVecListTwoQWordIndexed() const {
1362 if (!isDoubleSpacedVectorIndexed()) return false;
1363 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1364 }
1365
1366 bool isVecListTwoQHWordIndexed() const {
1367 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001368 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1369 }
1370
1371 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001372 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001373 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1374 }
1375
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001376 bool isVecListThreeDByteIndexed() const {
1377 if (!isSingleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1379 }
1380
1381 bool isVecListThreeDHWordIndexed() const {
1382 if (!isSingleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1384 }
1385
1386 bool isVecListThreeQWordIndexed() const {
1387 if (!isDoubleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1389 }
1390
1391 bool isVecListThreeQHWordIndexed() const {
1392 if (!isDoubleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1394 }
1395
1396 bool isVecListThreeDWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1399 }
1400
Jim Grosbach14952a02012-01-24 18:37:25 +00001401 bool isVecListFourDByteIndexed() const {
1402 if (!isSingleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1404 }
1405
1406 bool isVecListFourDHWordIndexed() const {
1407 if (!isSingleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1409 }
1410
1411 bool isVecListFourQWordIndexed() const {
1412 if (!isDoubleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1414 }
1415
1416 bool isVecListFourQHWordIndexed() const {
1417 if (!isDoubleSpacedVectorIndexed()) return false;
1418 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1419 }
1420
1421 bool isVecListFourDWordIndexed() const {
1422 if (!isSingleSpacedVectorIndexed()) return false;
1423 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1424 }
1425
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001426 bool isVectorIndex8() const {
1427 if (Kind != k_VectorIndex) return false;
1428 return VectorIndex.Val < 8;
1429 }
1430 bool isVectorIndex16() const {
1431 if (Kind != k_VectorIndex) return false;
1432 return VectorIndex.Val < 4;
1433 }
1434 bool isVectorIndex32() const {
1435 if (Kind != k_VectorIndex) return false;
1436 return VectorIndex.Val < 2;
1437 }
1438
Jim Grosbach741cd732011-10-17 22:26:03 +00001439 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001440 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001441 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1442 // Must be a constant.
1443 if (!CE) return false;
1444 int64_t Value = CE->getValue();
1445 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1446 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001447 return Value >= 0 && Value < 256;
1448 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001449
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001450 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001451 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +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 // i16 value in the range [0,255] or [0x0100, 0xff00]
1457 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1458 }
1459
Jim Grosbach8211c052011-10-18 00:22:00 +00001460 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001461 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001462 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1463 // Must be a constant.
1464 if (!CE) return false;
1465 int64_t Value = CE->getValue();
1466 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1467 return (Value >= 0 && Value < 256) ||
1468 (Value >= 0x0100 && Value <= 0xff00) ||
1469 (Value >= 0x010000 && Value <= 0xff0000) ||
1470 (Value >= 0x01000000 && Value <= 0xff000000);
1471 }
1472
1473 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001474 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 // Must be a constant.
1477 if (!CE) return false;
1478 int64_t Value = CE->getValue();
1479 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1480 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1481 return (Value >= 0 && Value < 256) ||
1482 (Value >= 0x0100 && Value <= 0xff00) ||
1483 (Value >= 0x010000 && Value <= 0xff0000) ||
1484 (Value >= 0x01000000 && Value <= 0xff000000) ||
1485 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1486 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1487 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001488 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001489 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 // Must be a constant.
1492 if (!CE) return false;
1493 int64_t Value = ~CE->getValue();
1494 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1495 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1496 return (Value >= 0 && Value < 256) ||
1497 (Value >= 0x0100 && Value <= 0xff00) ||
1498 (Value >= 0x010000 && Value <= 0xff0000) ||
1499 (Value >= 0x01000000 && Value <= 0xff000000) ||
1500 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1501 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1502 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001503
Jim Grosbache4454e02011-10-18 16:18:11 +00001504 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001505 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1507 // Must be a constant.
1508 if (!CE) return false;
1509 uint64_t Value = CE->getValue();
1510 // i64 value with each byte being either 0 or 0xff.
1511 for (unsigned i = 0; i < 8; ++i)
1512 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1513 return true;
1514 }
1515
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001516 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001517 // Add as immediates when possible. Null MCExpr = 0.
1518 if (Expr == 0)
1519 Inst.addOperand(MCOperand::CreateImm(0));
1520 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001521 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1522 else
1523 Inst.addOperand(MCOperand::CreateExpr(Expr));
1524 }
1525
Daniel Dunbard8042b72010-08-11 06:36:53 +00001526 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001527 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001528 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001529 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1530 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001531 }
1532
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001533 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1536 }
1537
Jim Grosbach48399582011-10-12 17:34:41 +00001538 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1541 }
1542
1543 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1546 }
1547
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001548 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1551 }
1552
1553 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1556 }
1557
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001558 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 Inst.addOperand(MCOperand::CreateReg(getReg()));
1561 }
1562
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001563 void addRegOperands(MCInst &Inst, unsigned N) const {
1564 assert(N == 1 && "Invalid number of operands!");
1565 Inst.addOperand(MCOperand::CreateReg(getReg()));
1566 }
1567
Jim Grosbachac798e12011-07-25 20:49:51 +00001568 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001569 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001570 assert(isRegShiftedReg() &&
1571 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001572 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1573 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001574 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001575 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001576 }
1577
Jim Grosbachac798e12011-07-25 20:49:51 +00001578 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001579 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001580 assert(isRegShiftedImm() &&
1581 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001582 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001583 // Shift of #32 is encoded as 0 where permitted
1584 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001585 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001586 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001587 }
1588
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001589 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001590 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001591 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1592 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001593 }
1594
Bill Wendling8d2aa032010-11-08 23:49:57 +00001595 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001596 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001597 const SmallVectorImpl<unsigned> &RegList = getRegList();
1598 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001599 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1600 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001601 }
1602
Bill Wendling9898ac92010-11-17 04:32:08 +00001603 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1604 addRegListOperands(Inst, N);
1605 }
1606
1607 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1608 addRegListOperands(Inst, N);
1609 }
1610
Jim Grosbach833b9d32011-07-27 20:15:40 +00001611 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1614 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1615 }
1616
Jim Grosbach864b6092011-07-28 21:34:26 +00001617 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 // Munge the lsb/width into a bitfield mask.
1620 unsigned lsb = Bitfield.LSB;
1621 unsigned width = Bitfield.Width;
1622 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1623 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1624 (32 - (lsb + width)));
1625 Inst.addOperand(MCOperand::CreateImm(Mask));
1626 }
1627
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001628 void addImmOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 addExpr(Inst, getImm());
1631 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001632
Jim Grosbachea231912011-12-22 22:19:05 +00001633 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1636 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1637 }
1638
1639 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1640 assert(N == 1 && "Invalid number of operands!");
1641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1642 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1643 }
1644
Jim Grosbache7fbce72011-10-03 23:38:36 +00001645 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1648 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1649 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001650 }
1651
Jim Grosbach7db8d692011-09-08 22:07:06 +00001652 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 // FIXME: We really want to scale the value here, but the LDRD/STRD
1655 // instruction don't encode operands that way yet.
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1658 }
1659
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001660 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 // The immediate is scaled by four in the encoding and is stored
1663 // in the MCInst as such. Lop off the low two bits here.
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1666 }
1667
Jim Grosbach930f2f62012-04-05 20:57:13 +00001668 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 // The immediate is scaled by four in the encoding and is stored
1671 // in the MCInst as such. Lop off the low two bits here.
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1674 }
1675
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001676 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1677 assert(N == 1 && "Invalid number of operands!");
1678 // The immediate is scaled by four in the encoding and is stored
1679 // in the MCInst as such. Lop off the low two bits here.
1680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1681 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1682 }
1683
Jim Grosbach475c6db2011-07-25 23:09:14 +00001684 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1685 assert(N == 1 && "Invalid number of operands!");
1686 // The constant encodes as the immediate-1, and we store in the instruction
1687 // the bits as encoded, so subtract off one here.
1688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1690 }
1691
Jim Grosbach801e0a32011-07-22 23:16:18 +00001692 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1693 assert(N == 1 && "Invalid number of operands!");
1694 // The constant encodes as the immediate-1, and we store in the instruction
1695 // the bits as encoded, so subtract off one here.
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1698 }
1699
Jim Grosbach46dd4132011-08-17 21:51:27 +00001700 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 // The constant encodes as the immediate, except for 32, which encodes as
1703 // zero.
1704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1705 unsigned Imm = CE->getValue();
1706 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1707 }
1708
Jim Grosbach27c1e252011-07-21 17:23:04 +00001709 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 1 && "Invalid number of operands!");
1711 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1712 // the instruction as well.
1713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1714 int Val = CE->getValue();
1715 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1716 }
1717
Jim Grosbachb009a872011-10-28 22:36:30 +00001718 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 // The operand is actually a t2_so_imm, but we have its bitwise
1721 // negation in the assembly source, so twiddle it here.
1722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1723 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1724 }
1725
Jim Grosbach30506252011-12-08 00:31:07 +00001726 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 // The operand is actually a t2_so_imm, but we have its
1729 // negation in the assembly source, so twiddle it here.
1730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1731 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1732 }
1733
Jim Grosbach930f2f62012-04-05 20:57:13 +00001734 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1735 assert(N == 1 && "Invalid number of operands!");
1736 // The operand is actually an imm0_4095, but we have its
1737 // negation in the assembly source, so twiddle it here.
1738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1739 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1740 }
1741
Mihai Popad36cbaa2013-07-03 09:21:44 +00001742 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1743 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1744 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1745 return;
1746 }
1747
1748 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1749 assert(SR && "Unknown value type!");
1750 Inst.addOperand(MCOperand::CreateExpr(SR));
1751 }
1752
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001753 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1754 assert(N == 1 && "Invalid number of operands!");
1755 if (isImm()) {
1756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1757 if (CE) {
1758 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1759 return;
1760 }
1761
1762 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1763 assert(SR && "Unknown value type!");
1764 Inst.addOperand(MCOperand::CreateExpr(SR));
1765 return;
1766 }
1767
1768 assert(isMem() && "Unknown value type!");
1769 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1770 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1771 }
1772
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001773 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 // The operand is actually a so_imm, but we have its bitwise
1776 // negation in the assembly source, so twiddle it here.
1777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1778 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1779 }
1780
Jim Grosbach30506252011-12-08 00:31:07 +00001781 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 // The operand is actually a so_imm, but we have its
1784 // negation in the assembly source, so twiddle it here.
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1787 }
1788
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001789 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1792 }
1793
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001794 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1797 }
1798
Jim Grosbachd3595712011-08-03 23:50:40 +00001799 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001801 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001802 }
1803
Jim Grosbach94298a92012-01-18 22:46:46 +00001804 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1805 assert(N == 1 && "Invalid number of operands!");
1806 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001807 Inst.addOperand(MCOperand::CreateImm(Imm));
1808 }
1809
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001810 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 assert(isImm() && "Not an immediate!");
1813
1814 // If we have an immediate that's not a constant, treat it as a label
1815 // reference needing a fixup.
1816 if (!isa<MCConstantExpr>(getImm())) {
1817 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1818 return;
1819 }
1820
1821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1822 int Val = CE->getValue();
1823 Inst.addOperand(MCOperand::CreateImm(Val));
1824 }
1825
Jim Grosbacha95ec992011-10-11 17:29:55 +00001826 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1827 assert(N == 2 && "Invalid number of operands!");
1828 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1829 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1830 }
1831
Jim Grosbachd3595712011-08-03 23:50:40 +00001832 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1833 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001834 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1835 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001836 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1837 // Special case for #-0
1838 if (Val == INT32_MIN) Val = 0;
1839 if (Val < 0) Val = -Val;
1840 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1841 } else {
1842 // For register offset, we encode the shift type and negation flag
1843 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001844 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1845 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001846 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001847 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1848 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001849 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001850 }
1851
Jim Grosbachcd17c122011-08-04 23:01:30 +00001852 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1853 assert(N == 2 && "Invalid number of operands!");
1854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1855 assert(CE && "non-constant AM2OffsetImm operand!");
1856 int32_t Val = CE->getValue();
1857 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1858 // Special case for #-0
1859 if (Val == INT32_MIN) Val = 0;
1860 if (Val < 0) Val = -Val;
1861 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1862 Inst.addOperand(MCOperand::CreateReg(0));
1863 Inst.addOperand(MCOperand::CreateImm(Val));
1864 }
1865
Jim Grosbach5b96b802011-08-10 20:29:19 +00001866 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1867 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001868 // If we have an immediate that's not a constant, treat it as a label
1869 // reference needing a fixup. If it is a constant, it's something else
1870 // and we reject it.
1871 if (isImm()) {
1872 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1873 Inst.addOperand(MCOperand::CreateReg(0));
1874 Inst.addOperand(MCOperand::CreateImm(0));
1875 return;
1876 }
1877
Jim Grosbach871dff72011-10-11 15:59:20 +00001878 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1879 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001880 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1881 // Special case for #-0
1882 if (Val == INT32_MIN) Val = 0;
1883 if (Val < 0) Val = -Val;
1884 Val = ARM_AM::getAM3Opc(AddSub, Val);
1885 } else {
1886 // For register offset, we encode the shift type and negation flag
1887 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001888 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001889 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1891 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001892 Inst.addOperand(MCOperand::CreateImm(Val));
1893 }
1894
1895 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1896 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001897 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001898 int32_t Val =
1899 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1900 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1901 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001902 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001903 }
1904
1905 // Constant offset.
1906 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1907 int32_t Val = CE->getValue();
1908 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1909 // Special case for #-0
1910 if (Val == INT32_MIN) Val = 0;
1911 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001912 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001913 Inst.addOperand(MCOperand::CreateReg(0));
1914 Inst.addOperand(MCOperand::CreateImm(Val));
1915 }
1916
Jim Grosbachd3595712011-08-03 23:50:40 +00001917 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1918 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001919 // If we have an immediate that's not a constant, treat it as a label
1920 // reference needing a fixup. If it is a constant, it's something else
1921 // and we reject it.
1922 if (isImm()) {
1923 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1924 Inst.addOperand(MCOperand::CreateImm(0));
1925 return;
1926 }
1927
Jim Grosbachd3595712011-08-03 23:50:40 +00001928 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001929 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001930 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1931 // Special case for #-0
1932 if (Val == INT32_MIN) Val = 0;
1933 if (Val < 0) Val = -Val;
1934 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001935 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001936 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001937 }
1938
Jim Grosbach7db8d692011-09-08 22:07:06 +00001939 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1940 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001941 // If we have an immediate that's not a constant, treat it as a label
1942 // reference needing a fixup. If it is a constant, it's something else
1943 // and we reject it.
1944 if (isImm()) {
1945 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1946 Inst.addOperand(MCOperand::CreateImm(0));
1947 return;
1948 }
1949
Jim Grosbach871dff72011-10-11 15:59:20 +00001950 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1951 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001952 Inst.addOperand(MCOperand::CreateImm(Val));
1953 }
1954
Jim Grosbacha05627e2011-09-09 18:37:27 +00001955 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 2 && "Invalid number of operands!");
1957 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001958 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1959 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001960 Inst.addOperand(MCOperand::CreateImm(Val));
1961 }
1962
Jim Grosbachd3595712011-08-03 23:50:40 +00001963 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001965 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1966 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001967 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001968 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001969
Jim Grosbach2392c532011-09-07 23:39:14 +00001970 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1971 addMemImm8OffsetOperands(Inst, N);
1972 }
1973
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001974 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001975 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001976 }
1977
1978 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
1980 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001981 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001982 addExpr(Inst, getImm());
1983 Inst.addOperand(MCOperand::CreateImm(0));
1984 return;
1985 }
1986
1987 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001988 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001990 Inst.addOperand(MCOperand::CreateImm(Val));
1991 }
1992
Jim Grosbachd3595712011-08-03 23:50:40 +00001993 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001995 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001996 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001997 addExpr(Inst, getImm());
1998 Inst.addOperand(MCOperand::CreateImm(0));
1999 return;
2000 }
2001
2002 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2004 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002005 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002006 }
Bill Wendling811c9362010-11-30 07:44:32 +00002007
Jim Grosbach05541f42011-09-19 22:21:13 +00002008 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2011 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002012 }
2013
2014 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002016 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2017 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002018 }
2019
Jim Grosbachd3595712011-08-03 23:50:40 +00002020 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002022 unsigned Val =
2023 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2024 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2026 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002027 Inst.addOperand(MCOperand::CreateImm(Val));
2028 }
2029
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002030 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002032 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2033 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2034 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002035 }
2036
Jim Grosbachd3595712011-08-03 23:50:40 +00002037 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2038 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002039 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2040 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002041 }
2042
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002043 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2044 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002045 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2046 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002047 Inst.addOperand(MCOperand::CreateImm(Val));
2048 }
2049
Jim Grosbach26d35872011-08-19 18:55:51 +00002050 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2051 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002052 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2053 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002054 Inst.addOperand(MCOperand::CreateImm(Val));
2055 }
2056
Jim Grosbacha32c7532011-08-19 18:49:59 +00002057 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2058 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002059 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2060 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002061 Inst.addOperand(MCOperand::CreateImm(Val));
2062 }
2063
Jim Grosbach23983d62011-08-19 18:13:48 +00002064 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002066 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2067 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002068 Inst.addOperand(MCOperand::CreateImm(Val));
2069 }
2070
Jim Grosbachd3595712011-08-03 23:50:40 +00002071 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2072 assert(N == 1 && "Invalid number of operands!");
2073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2074 assert(CE && "non-constant post-idx-imm8 operand!");
2075 int Imm = CE->getValue();
2076 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002077 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002078 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2079 Inst.addOperand(MCOperand::CreateImm(Imm));
2080 }
2081
Jim Grosbach93981412011-10-11 21:55:36 +00002082 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2083 assert(N == 1 && "Invalid number of operands!");
2084 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2085 assert(CE && "non-constant post-idx-imm8s4 operand!");
2086 int Imm = CE->getValue();
2087 bool isAdd = Imm >= 0;
2088 if (Imm == INT32_MIN) Imm = 0;
2089 // Immediate is scaled by 4.
2090 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2091 Inst.addOperand(MCOperand::CreateImm(Imm));
2092 }
2093
Jim Grosbachd3595712011-08-03 23:50:40 +00002094 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2095 assert(N == 2 && "Invalid number of operands!");
2096 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002097 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2098 }
2099
2100 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2101 assert(N == 2 && "Invalid number of operands!");
2102 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2103 // The sign, shift type, and shift amount are encoded in a single operand
2104 // using the AM2 encoding helpers.
2105 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2106 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2107 PostIdxReg.ShiftTy);
2108 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002109 }
2110
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002111 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2114 }
2115
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002116 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 1 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2119 }
2120
Jim Grosbach182b6a02011-11-29 23:51:09 +00002121 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002122 assert(N == 1 && "Invalid number of operands!");
2123 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2124 }
2125
Jim Grosbach04945c42011-12-02 00:35:16 +00002126 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 2 && "Invalid number of operands!");
2128 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2129 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2130 }
2131
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002132 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2135 }
2136
2137 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2140 }
2141
2142 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2143 assert(N == 1 && "Invalid number of operands!");
2144 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2145 }
2146
Jim Grosbach741cd732011-10-17 22:26:03 +00002147 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2148 assert(N == 1 && "Invalid number of operands!");
2149 // The immediate encodes the type of constant as well as the value.
2150 // Mask in that this is an i8 splat.
2151 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2152 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2153 }
2154
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002155 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2156 assert(N == 1 && "Invalid number of operands!");
2157 // The immediate encodes the type of constant as well as the value.
2158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2159 unsigned Value = CE->getValue();
2160 if (Value >= 256)
2161 Value = (Value >> 8) | 0xa00;
2162 else
2163 Value |= 0x800;
2164 Inst.addOperand(MCOperand::CreateImm(Value));
2165 }
2166
Jim Grosbach8211c052011-10-18 00:22:00 +00002167 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2168 assert(N == 1 && "Invalid number of operands!");
2169 // The immediate encodes the type of constant as well as the value.
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 unsigned Value = CE->getValue();
2172 if (Value >= 256 && Value <= 0xff00)
2173 Value = (Value >> 8) | 0x200;
2174 else if (Value > 0xffff && Value <= 0xff0000)
2175 Value = (Value >> 16) | 0x400;
2176 else if (Value > 0xffffff)
2177 Value = (Value >> 24) | 0x600;
2178 Inst.addOperand(MCOperand::CreateImm(Value));
2179 }
2180
2181 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2182 assert(N == 1 && "Invalid number of operands!");
2183 // The immediate encodes the type of constant as well as the value.
2184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2185 unsigned Value = CE->getValue();
2186 if (Value >= 256 && Value <= 0xffff)
2187 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2188 else if (Value > 0xffff && Value <= 0xffffff)
2189 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2190 else if (Value > 0xffffff)
2191 Value = (Value >> 24) | 0x600;
2192 Inst.addOperand(MCOperand::CreateImm(Value));
2193 }
2194
Jim Grosbach045b6c72011-12-19 23:51:07 +00002195 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 1 && "Invalid number of operands!");
2197 // The immediate encodes the type of constant as well as the value.
2198 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2199 unsigned Value = ~CE->getValue();
2200 if (Value >= 256 && Value <= 0xffff)
2201 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2202 else if (Value > 0xffff && Value <= 0xffffff)
2203 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2204 else if (Value > 0xffffff)
2205 Value = (Value >> 24) | 0x600;
2206 Inst.addOperand(MCOperand::CreateImm(Value));
2207 }
2208
Jim Grosbache4454e02011-10-18 16:18:11 +00002209 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2210 assert(N == 1 && "Invalid number of operands!");
2211 // The immediate encodes the type of constant as well as the value.
2212 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2213 uint64_t Value = CE->getValue();
2214 unsigned Imm = 0;
2215 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2216 Imm |= (Value & 1) << i;
2217 }
2218 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2219 }
2220
Jim Grosbach602aa902011-07-13 15:34:57 +00002221 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002222
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002223 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002224 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002225 Op->ITMask.Mask = Mask;
2226 Op->StartLoc = S;
2227 Op->EndLoc = S;
2228 return Op;
2229 }
2230
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002231 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002232 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002233 Op->CC.Val = CC;
2234 Op->StartLoc = S;
2235 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002236 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002237 }
2238
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002239 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002240 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002241 Op->Cop.Val = CopVal;
2242 Op->StartLoc = S;
2243 Op->EndLoc = S;
2244 return Op;
2245 }
2246
2247 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002248 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002249 Op->Cop.Val = CopVal;
2250 Op->StartLoc = S;
2251 Op->EndLoc = S;
2252 return Op;
2253 }
2254
Jim Grosbach48399582011-10-12 17:34:41 +00002255 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2256 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2257 Op->Cop.Val = Val;
2258 Op->StartLoc = S;
2259 Op->EndLoc = E;
2260 return Op;
2261 }
2262
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002263 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002264 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002265 Op->Reg.RegNum = RegNum;
2266 Op->StartLoc = S;
2267 Op->EndLoc = S;
2268 return Op;
2269 }
2270
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002271 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002272 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002273 Op->Tok.Data = Str.data();
2274 Op->Tok.Length = Str.size();
2275 Op->StartLoc = S;
2276 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002277 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002278 }
2279
Bill Wendling2063b842010-11-18 23:43:05 +00002280 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002281 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002282 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002283 Op->StartLoc = S;
2284 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002285 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002286 }
2287
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002288 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2289 unsigned SrcReg,
2290 unsigned ShiftReg,
2291 unsigned ShiftImm,
2292 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002293 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002294 Op->RegShiftedReg.ShiftTy = ShTy;
2295 Op->RegShiftedReg.SrcReg = SrcReg;
2296 Op->RegShiftedReg.ShiftReg = ShiftReg;
2297 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002298 Op->StartLoc = S;
2299 Op->EndLoc = E;
2300 return Op;
2301 }
2302
Owen Andersonb595ed02011-07-21 18:54:16 +00002303 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2304 unsigned SrcReg,
2305 unsigned ShiftImm,
2306 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002307 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002308 Op->RegShiftedImm.ShiftTy = ShTy;
2309 Op->RegShiftedImm.SrcReg = SrcReg;
2310 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002311 Op->StartLoc = S;
2312 Op->EndLoc = E;
2313 return Op;
2314 }
2315
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002316 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002317 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002318 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002319 Op->ShifterImm.isASR = isASR;
2320 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002321 Op->StartLoc = S;
2322 Op->EndLoc = E;
2323 return Op;
2324 }
2325
Jim Grosbach833b9d32011-07-27 20:15:40 +00002326 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002327 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002328 Op->RotImm.Imm = Imm;
2329 Op->StartLoc = S;
2330 Op->EndLoc = E;
2331 return Op;
2332 }
2333
Jim Grosbach864b6092011-07-28 21:34:26 +00002334 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2335 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002336 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002337 Op->Bitfield.LSB = LSB;
2338 Op->Bitfield.Width = Width;
2339 Op->StartLoc = S;
2340 Op->EndLoc = E;
2341 return Op;
2342 }
2343
Bill Wendling2cae3272010-11-09 22:44:22 +00002344 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002345 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002346 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002347 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002348 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002349
Chad Rosierfa705ee2013-07-01 20:49:23 +00002350 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002351 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002352 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002353 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002354 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002355
Chad Rosierfa705ee2013-07-01 20:49:23 +00002356 // Sort based on the register encoding values.
2357 array_pod_sort(Regs.begin(), Regs.end());
2358
Bill Wendling9898ac92010-11-17 04:32:08 +00002359 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002360 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002361 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002362 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002363 Op->StartLoc = StartLoc;
2364 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002365 return Op;
2366 }
2367
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002368 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002369 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002370 ARMOperand *Op = new ARMOperand(k_VectorList);
2371 Op->VectorList.RegNum = RegNum;
2372 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002373 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002374 Op->StartLoc = S;
2375 Op->EndLoc = E;
2376 return Op;
2377 }
2378
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002379 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002380 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002381 SMLoc S, SMLoc E) {
2382 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2383 Op->VectorList.RegNum = RegNum;
2384 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002385 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002386 Op->StartLoc = S;
2387 Op->EndLoc = E;
2388 return Op;
2389 }
2390
Jim Grosbach04945c42011-12-02 00:35:16 +00002391 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002392 unsigned Index,
2393 bool isDoubleSpaced,
2394 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002395 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2396 Op->VectorList.RegNum = RegNum;
2397 Op->VectorList.Count = Count;
2398 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002399 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002400 Op->StartLoc = S;
2401 Op->EndLoc = E;
2402 return Op;
2403 }
2404
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002405 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2406 MCContext &Ctx) {
2407 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2408 Op->VectorIndex.Val = Idx;
2409 Op->StartLoc = S;
2410 Op->EndLoc = E;
2411 return Op;
2412 }
2413
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002414 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002415 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002416 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002417 Op->StartLoc = S;
2418 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002419 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002420 }
2421
Jim Grosbachd3595712011-08-03 23:50:40 +00002422 static ARMOperand *CreateMem(unsigned BaseRegNum,
2423 const MCConstantExpr *OffsetImm,
2424 unsigned OffsetRegNum,
2425 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002426 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002427 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002428 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002429 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002430 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002431 Op->Memory.BaseRegNum = BaseRegNum;
2432 Op->Memory.OffsetImm = OffsetImm;
2433 Op->Memory.OffsetRegNum = OffsetRegNum;
2434 Op->Memory.ShiftType = ShiftType;
2435 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002436 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002437 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002438 Op->StartLoc = S;
2439 Op->EndLoc = E;
2440 return Op;
2441 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002442
Jim Grosbachc320c852011-08-05 21:28:30 +00002443 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2444 ARM_AM::ShiftOpc ShiftTy,
2445 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002446 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002447 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002448 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002449 Op->PostIdxReg.isAdd = isAdd;
2450 Op->PostIdxReg.ShiftTy = ShiftTy;
2451 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002452 Op->StartLoc = S;
2453 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002454 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002455 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002456
2457 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002458 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002459 Op->MBOpt.Val = Opt;
2460 Op->StartLoc = S;
2461 Op->EndLoc = S;
2462 return Op;
2463 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002464
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002465 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2466 SMLoc S) {
2467 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2468 Op->ISBOpt.Val = Opt;
2469 Op->StartLoc = S;
2470 Op->EndLoc = S;
2471 return Op;
2472 }
2473
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002474 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002475 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002476 Op->IFlags.Val = IFlags;
2477 Op->StartLoc = S;
2478 Op->EndLoc = S;
2479 return Op;
2480 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002481
2482 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002483 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002484 Op->MMask.Val = MMask;
2485 Op->StartLoc = S;
2486 Op->EndLoc = S;
2487 return Op;
2488 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002489};
2490
2491} // end anonymous namespace.
2492
Jim Grosbach602aa902011-07-13 15:34:57 +00002493void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002494 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002495 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002496 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002497 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002498 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002499 OS << "<ccout " << getReg() << ">";
2500 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002501 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002502 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002503 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2504 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2505 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002506 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2507 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2508 break;
2509 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002510 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002511 OS << "<coprocessor number: " << getCoproc() << ">";
2512 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002513 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002514 OS << "<coprocessor register: " << getCoproc() << ">";
2515 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002516 case k_CoprocOption:
2517 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002519 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002520 OS << "<mask: " << getMSRMask() << ">";
2521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002522 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002523 getImm()->print(OS);
2524 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002525 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002526 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002527 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002528 case k_InstSyncBarrierOpt:
2529 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2530 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002531 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002532 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002533 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002534 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002536 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002537 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2538 << PostIdxReg.RegNum;
2539 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2540 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2541 << PostIdxReg.ShiftImm;
2542 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002543 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002544 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002545 OS << "<ARM_PROC::";
2546 unsigned IFlags = getProcIFlags();
2547 for (int i=2; i >= 0; --i)
2548 if (IFlags & (1 << i))
2549 OS << ARM_PROC::IFlagsToString(1 << i);
2550 OS << ">";
2551 break;
2552 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002553 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002554 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002555 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002556 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002557 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2558 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002559 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002560 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002561 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002562 << RegShiftedReg.SrcReg << " "
2563 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2564 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002565 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002566 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002567 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002568 << RegShiftedImm.SrcReg << " "
2569 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2570 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002571 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002572 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002573 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2574 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002575 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002576 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2577 << ", width: " << Bitfield.Width << ">";
2578 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002579 case k_RegisterList:
2580 case k_DPRRegisterList:
2581 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002582 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002583
Bill Wendlingbed94652010-11-09 23:28:44 +00002584 const SmallVectorImpl<unsigned> &RegList = getRegList();
2585 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002586 I = RegList.begin(), E = RegList.end(); I != E; ) {
2587 OS << *I;
2588 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002589 }
2590
2591 OS << ">";
2592 break;
2593 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002594 case k_VectorList:
2595 OS << "<vector_list " << VectorList.Count << " * "
2596 << VectorList.RegNum << ">";
2597 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002598 case k_VectorListAllLanes:
2599 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2600 << VectorList.RegNum << ">";
2601 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002602 case k_VectorListIndexed:
2603 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2604 << VectorList.Count << " * " << VectorList.RegNum << ">";
2605 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002606 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002607 OS << "'" << getToken() << "'";
2608 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002609 case k_VectorIndex:
2610 OS << "<vectorindex " << getVectorIndex() << ">";
2611 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002612 }
2613}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002614
2615/// @name Auto-generated Match Functions
2616/// {
2617
2618static unsigned MatchRegisterName(StringRef Name);
2619
2620/// }
2621
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002622bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2623 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002624 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002625 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002626 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002627
2628 return (RegNo == (unsigned)-1);
2629}
2630
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002631/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002632/// and if it is a register name the token is eaten and the register number is
2633/// returned. Otherwise return -1.
2634///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002635int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002636 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002637 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002638
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002639 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002640 unsigned RegNum = MatchRegisterName(lowerCase);
2641 if (!RegNum) {
2642 RegNum = StringSwitch<unsigned>(lowerCase)
2643 .Case("r13", ARM::SP)
2644 .Case("r14", ARM::LR)
2645 .Case("r15", ARM::PC)
2646 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002647 // Additional register name aliases for 'gas' compatibility.
2648 .Case("a1", ARM::R0)
2649 .Case("a2", ARM::R1)
2650 .Case("a3", ARM::R2)
2651 .Case("a4", ARM::R3)
2652 .Case("v1", ARM::R4)
2653 .Case("v2", ARM::R5)
2654 .Case("v3", ARM::R6)
2655 .Case("v4", ARM::R7)
2656 .Case("v5", ARM::R8)
2657 .Case("v6", ARM::R9)
2658 .Case("v7", ARM::R10)
2659 .Case("v8", ARM::R11)
2660 .Case("sb", ARM::R9)
2661 .Case("sl", ARM::R10)
2662 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002663 .Default(0);
2664 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002665 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002666 // Check for aliases registered via .req. Canonicalize to lower case.
2667 // That's more consistent since register names are case insensitive, and
2668 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2669 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002670 // If no match, return failure.
2671 if (Entry == RegisterReqs.end())
2672 return -1;
2673 Parser.Lex(); // Eat identifier token.
2674 return Entry->getValue();
2675 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002676
Chris Lattner44e5981c2010-10-30 04:09:10 +00002677 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002678
Chris Lattner44e5981c2010-10-30 04:09:10 +00002679 return RegNum;
2680}
Jim Grosbach99710a82010-11-01 16:44:21 +00002681
Jim Grosbachbb24c592011-07-13 18:49:30 +00002682// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2683// If a recoverable error occurs, return 1. If an irrecoverable error
2684// occurs, return -1. An irrecoverable error is one where tokens have been
2685// consumed in the process of trying to parse the shifter (i.e., when it is
2686// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002687int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002688 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2689 SMLoc S = Parser.getTok().getLoc();
2690 const AsmToken &Tok = Parser.getTok();
2691 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2692
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002693 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002694 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002695 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002696 .Case("lsl", ARM_AM::lsl)
2697 .Case("lsr", ARM_AM::lsr)
2698 .Case("asr", ARM_AM::asr)
2699 .Case("ror", ARM_AM::ror)
2700 .Case("rrx", ARM_AM::rrx)
2701 .Default(ARM_AM::no_shift);
2702
2703 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002704 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002705
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002706 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002707
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002708 // The source register for the shift has already been added to the
2709 // operand list, so we need to pop it off and combine it into the shifted
2710 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002711 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002712 if (!PrevOp->isReg())
2713 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2714 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002715
2716 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002717 int64_t Imm = 0;
2718 int ShiftReg = 0;
2719 if (ShiftTy == ARM_AM::rrx) {
2720 // RRX Doesn't have an explicit shift amount. The encoder expects
2721 // the shift register to be the same as the source register. Seems odd,
2722 // but OK.
2723 ShiftReg = SrcReg;
2724 } else {
2725 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002726 if (Parser.getTok().is(AsmToken::Hash) ||
2727 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002728 Parser.Lex(); // Eat hash.
2729 SMLoc ImmLoc = Parser.getTok().getLoc();
2730 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002731 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002732 Error(ImmLoc, "invalid immediate shift value");
2733 return -1;
2734 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002735 // The expression must be evaluatable as an immediate.
2736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002737 if (!CE) {
2738 Error(ImmLoc, "invalid immediate shift value");
2739 return -1;
2740 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002741 // Range check the immediate.
2742 // lsl, ror: 0 <= imm <= 31
2743 // lsr, asr: 0 <= imm <= 32
2744 Imm = CE->getValue();
2745 if (Imm < 0 ||
2746 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2747 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002748 Error(ImmLoc, "immediate shift value out of range");
2749 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002750 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002751 // shift by zero is a nop. Always send it through as lsl.
2752 // ('as' compatibility)
2753 if (Imm == 0)
2754 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002755 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002756 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002757 EndLoc = Parser.getTok().getEndLoc();
2758 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002759 if (ShiftReg == -1) {
2760 Error (L, "expected immediate or register in shift operand");
2761 return -1;
2762 }
2763 } else {
2764 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002765 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002766 return -1;
2767 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002768 }
2769
Owen Andersonb595ed02011-07-21 18:54:16 +00002770 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2771 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002772 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002773 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002774 else
2775 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002776 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002777
Jim Grosbachbb24c592011-07-13 18:49:30 +00002778 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002779}
2780
2781
Bill Wendling2063b842010-11-18 23:43:05 +00002782/// Try to parse a register name. The token must be an Identifier when called.
2783/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2784/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002785///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002786/// TODO this is likely to change to allow different register types and or to
2787/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002788bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002789tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002790 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002791 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002792 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002793 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002794
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002795 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2796 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002797
Chris Lattner44e5981c2010-10-30 04:09:10 +00002798 const AsmToken &ExclaimTok = Parser.getTok();
2799 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002800 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2801 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002802 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002803 return false;
2804 }
2805
2806 // Also check for an index operand. This is only legal for vector registers,
2807 // but that'll get caught OK in operand matching, so we don't need to
2808 // explicitly filter everything else out here.
2809 if (Parser.getTok().is(AsmToken::LBrac)) {
2810 SMLoc SIdx = Parser.getTok().getLoc();
2811 Parser.Lex(); // Eat left bracket token.
2812
2813 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002814 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002815 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002816 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002817 if (!MCE)
2818 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002819
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002820 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002821 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002822
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002823 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002824 Parser.Lex(); // Eat right bracket token.
2825
2826 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2827 SIdx, E,
2828 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002829 }
2830
Bill Wendling2063b842010-11-18 23:43:05 +00002831 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002832}
2833
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002834/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2835/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2836/// "c5", ...
2837static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002838 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2839 // but efficient.
2840 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002841 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002842 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002843 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002844 return -1;
2845 switch (Name[1]) {
2846 default: return -1;
2847 case '0': return 0;
2848 case '1': return 1;
2849 case '2': return 2;
2850 case '3': return 3;
2851 case '4': return 4;
2852 case '5': return 5;
2853 case '6': return 6;
2854 case '7': return 7;
2855 case '8': return 8;
2856 case '9': return 9;
2857 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002858 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002859 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002860 return -1;
2861 switch (Name[2]) {
2862 default: return -1;
2863 case '0': return 10;
2864 case '1': return 11;
2865 case '2': return 12;
2866 case '3': return 13;
2867 case '4': return 14;
2868 case '5': return 15;
2869 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002870 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002871}
2872
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002873/// parseITCondCode - Try to parse a condition code for an IT instruction.
2874ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2875parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2876 SMLoc S = Parser.getTok().getLoc();
2877 const AsmToken &Tok = Parser.getTok();
2878 if (!Tok.is(AsmToken::Identifier))
2879 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002880 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002881 .Case("eq", ARMCC::EQ)
2882 .Case("ne", ARMCC::NE)
2883 .Case("hs", ARMCC::HS)
2884 .Case("cs", ARMCC::HS)
2885 .Case("lo", ARMCC::LO)
2886 .Case("cc", ARMCC::LO)
2887 .Case("mi", ARMCC::MI)
2888 .Case("pl", ARMCC::PL)
2889 .Case("vs", ARMCC::VS)
2890 .Case("vc", ARMCC::VC)
2891 .Case("hi", ARMCC::HI)
2892 .Case("ls", ARMCC::LS)
2893 .Case("ge", ARMCC::GE)
2894 .Case("lt", ARMCC::LT)
2895 .Case("gt", ARMCC::GT)
2896 .Case("le", ARMCC::LE)
2897 .Case("al", ARMCC::AL)
2898 .Default(~0U);
2899 if (CC == ~0U)
2900 return MatchOperand_NoMatch;
2901 Parser.Lex(); // Eat the token.
2902
2903 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2904
2905 return MatchOperand_Success;
2906}
2907
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002908/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002909/// token must be an Identifier when called, and if it is a coprocessor
2910/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002911ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002912parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002913 SMLoc S = Parser.getTok().getLoc();
2914 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002915 if (Tok.isNot(AsmToken::Identifier))
2916 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002917
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002918 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002919 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002920 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002921
2922 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002923 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002924 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002925}
2926
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002927/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002928/// token must be an Identifier when called, and if it is a coprocessor
2929/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002930ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002931parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002932 SMLoc S = Parser.getTok().getLoc();
2933 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002934 if (Tok.isNot(AsmToken::Identifier))
2935 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002936
2937 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2938 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002939 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002940
2941 Parser.Lex(); // Eat identifier token.
2942 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002943 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002944}
2945
Jim Grosbach48399582011-10-12 17:34:41 +00002946/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2947/// coproc_option : '{' imm0_255 '}'
2948ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2949parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2950 SMLoc S = Parser.getTok().getLoc();
2951
2952 // If this isn't a '{', this isn't a coprocessor immediate operand.
2953 if (Parser.getTok().isNot(AsmToken::LCurly))
2954 return MatchOperand_NoMatch;
2955 Parser.Lex(); // Eat the '{'
2956
2957 const MCExpr *Expr;
2958 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002959 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002960 Error(Loc, "illegal expression");
2961 return MatchOperand_ParseFail;
2962 }
2963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2964 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2965 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2966 return MatchOperand_ParseFail;
2967 }
2968 int Val = CE->getValue();
2969
2970 // Check for and consume the closing '}'
2971 if (Parser.getTok().isNot(AsmToken::RCurly))
2972 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002973 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002974 Parser.Lex(); // Eat the '}'
2975
2976 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2977 return MatchOperand_Success;
2978}
2979
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002980// For register list parsing, we need to map from raw GPR register numbering
2981// to the enumeration values. The enumeration values aren't sorted by
2982// register number due to our using "sp", "lr" and "pc" as canonical names.
2983static unsigned getNextRegister(unsigned Reg) {
2984 // If this is a GPR, we need to do it manually, otherwise we can rely
2985 // on the sort ordering of the enumeration since the other reg-classes
2986 // are sane.
2987 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2988 return Reg + 1;
2989 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002990 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002991 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2992 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2993 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2994 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2995 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2996 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2997 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2998 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2999 }
3000}
3001
Jim Grosbach85a23432011-11-11 21:27:40 +00003002// Return the low-subreg of a given Q register.
3003static unsigned getDRegFromQReg(unsigned QReg) {
3004 switch (QReg) {
3005 default: llvm_unreachable("expected a Q register!");
3006 case ARM::Q0: return ARM::D0;
3007 case ARM::Q1: return ARM::D2;
3008 case ARM::Q2: return ARM::D4;
3009 case ARM::Q3: return ARM::D6;
3010 case ARM::Q4: return ARM::D8;
3011 case ARM::Q5: return ARM::D10;
3012 case ARM::Q6: return ARM::D12;
3013 case ARM::Q7: return ARM::D14;
3014 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003015 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003016 case ARM::Q10: return ARM::D20;
3017 case ARM::Q11: return ARM::D22;
3018 case ARM::Q12: return ARM::D24;
3019 case ARM::Q13: return ARM::D26;
3020 case ARM::Q14: return ARM::D28;
3021 case ARM::Q15: return ARM::D30;
3022 }
3023}
3024
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003025/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003026bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003027parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003028 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003029 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003030 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003031 Parser.Lex(); // Eat '{' token.
3032 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003033
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003034 // Check the first register in the list to see what register class
3035 // this is a list of.
3036 int Reg = tryParseRegister();
3037 if (Reg == -1)
3038 return Error(RegLoc, "register expected");
3039
Jim Grosbach85a23432011-11-11 21:27:40 +00003040 // The reglist instructions have at most 16 registers, so reserve
3041 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003042 int EReg = 0;
3043 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003044
3045 // Allow Q regs and just interpret them as the two D sub-registers.
3046 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3047 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003048 EReg = MRI->getEncodingValue(Reg);
3049 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003050 ++Reg;
3051 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003052 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003053 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3054 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3055 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3056 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3057 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3058 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3059 else
3060 return Error(RegLoc, "invalid register in register list");
3061
Jim Grosbach85a23432011-11-11 21:27:40 +00003062 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003063 EReg = MRI->getEncodingValue(Reg);
3064 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003065
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003066 // This starts immediately after the first register token in the list,
3067 // so we can see either a comma or a minus (range separator) as a legal
3068 // next token.
3069 while (Parser.getTok().is(AsmToken::Comma) ||
3070 Parser.getTok().is(AsmToken::Minus)) {
3071 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003072 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003073 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003074 int EndReg = tryParseRegister();
3075 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003076 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003077 // Allow Q regs and just interpret them as the two D sub-registers.
3078 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3079 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003080 // If the register is the same as the start reg, there's nothing
3081 // more to do.
3082 if (Reg == EndReg)
3083 continue;
3084 // The register must be in the same register class as the first.
3085 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003086 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003087 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003088 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003089 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003090
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003091 // Add all the registers in the range to the register list.
3092 while (Reg != EndReg) {
3093 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003094 EReg = MRI->getEncodingValue(Reg);
3095 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003096 }
3097 continue;
3098 }
3099 Parser.Lex(); // Eat the comma.
3100 RegLoc = Parser.getTok().getLoc();
3101 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003102 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003103 Reg = tryParseRegister();
3104 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003105 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003106 // Allow Q regs and just interpret them as the two D sub-registers.
3107 bool isQReg = false;
3108 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3109 Reg = getDRegFromQReg(Reg);
3110 isQReg = true;
3111 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003112 // The register must be in the same register class as the first.
3113 if (!RC->contains(Reg))
3114 return Error(RegLoc, "invalid register in register list");
3115 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003116 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003117 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3118 Warning(RegLoc, "register list not in ascending order");
3119 else
3120 return Error(RegLoc, "register list not in ascending order");
3121 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003122 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003123 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3124 ") in register list");
3125 continue;
3126 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003127 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003128 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3129 Reg != OldReg + 1)
3130 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003131 EReg = MRI->getEncodingValue(Reg);
3132 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3133 if (isQReg) {
3134 EReg = MRI->getEncodingValue(++Reg);
3135 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3136 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003137 }
3138
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003139 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003140 return Error(Parser.getTok().getLoc(), "'}' expected");
3141 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003142 Parser.Lex(); // Eat '}' token.
3143
Jim Grosbach18bf3632011-12-13 21:48:29 +00003144 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003145 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003146
3147 // The ARM system instruction variants for LDM/STM have a '^' token here.
3148 if (Parser.getTok().is(AsmToken::Caret)) {
3149 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3150 Parser.Lex(); // Eat '^' token.
3151 }
3152
Bill Wendling2063b842010-11-18 23:43:05 +00003153 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003154}
3155
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156// Helper function to parse the lane index for vector lists.
3157ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003158parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003159 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003160 if (Parser.getTok().is(AsmToken::LBrac)) {
3161 Parser.Lex(); // Eat the '['.
3162 if (Parser.getTok().is(AsmToken::RBrac)) {
3163 // "Dn[]" is the 'all lanes' syntax.
3164 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003165 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003166 Parser.Lex(); // Eat the ']'.
3167 return MatchOperand_Success;
3168 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003169
3170 // There's an optional '#' token here. Normally there wouldn't be, but
3171 // inline assemble puts one in, and it's friendly to accept that.
3172 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003173 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003174
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003175 const MCExpr *LaneIndex;
3176 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003177 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003178 Error(Loc, "illegal expression");
3179 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003180 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003181 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3182 if (!CE) {
3183 Error(Loc, "lane index must be empty or an integer");
3184 return MatchOperand_ParseFail;
3185 }
3186 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3187 Error(Parser.getTok().getLoc(), "']' expected");
3188 return MatchOperand_ParseFail;
3189 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003190 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003191 Parser.Lex(); // Eat the ']'.
3192 int64_t Val = CE->getValue();
3193
3194 // FIXME: Make this range check context sensitive for .8, .16, .32.
3195 if (Val < 0 || Val > 7) {
3196 Error(Parser.getTok().getLoc(), "lane index out of range");
3197 return MatchOperand_ParseFail;
3198 }
3199 Index = Val;
3200 LaneKind = IndexedLane;
3201 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003202 }
3203 LaneKind = NoLanes;
3204 return MatchOperand_Success;
3205}
3206
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003207// parse a vector register list
3208ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3209parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003210 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003211 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003212 SMLoc S = Parser.getTok().getLoc();
3213 // As an extension (to match gas), support a plain D register or Q register
3214 // (without encosing curly braces) as a single or double entry list,
3215 // respectively.
3216 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003217 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003218 int Reg = tryParseRegister();
3219 if (Reg == -1)
3220 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003221 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003222 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003223 if (Res != MatchOperand_Success)
3224 return Res;
3225 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003227 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 break;
3229 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003230 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3231 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003232 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003233 case IndexedLane:
3234 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003235 LaneIndex,
3236 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003237 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003238 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003239 return MatchOperand_Success;
3240 }
3241 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3242 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003243 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003244 if (Res != MatchOperand_Success)
3245 return Res;
3246 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003247 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003248 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003249 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003250 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003251 break;
3252 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003253 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3254 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003255 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3256 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003257 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003258 case IndexedLane:
3259 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003260 LaneIndex,
3261 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003262 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003263 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003264 return MatchOperand_Success;
3265 }
3266 Error(S, "vector register expected");
3267 return MatchOperand_ParseFail;
3268 }
3269
3270 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003271 return MatchOperand_NoMatch;
3272
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003273 Parser.Lex(); // Eat '{' token.
3274 SMLoc RegLoc = Parser.getTok().getLoc();
3275
3276 int Reg = tryParseRegister();
3277 if (Reg == -1) {
3278 Error(RegLoc, "register expected");
3279 return MatchOperand_ParseFail;
3280 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003281 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003282 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003283 unsigned FirstReg = Reg;
3284 // The list is of D registers, but we also allow Q regs and just interpret
3285 // them as the two D sub-registers.
3286 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3287 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003288 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3289 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003290 ++Reg;
3291 ++Count;
3292 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003293
3294 SMLoc E;
3295 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003296 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003297
Jim Grosbache891fe82011-11-15 23:19:15 +00003298 while (Parser.getTok().is(AsmToken::Comma) ||
3299 Parser.getTok().is(AsmToken::Minus)) {
3300 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003301 if (!Spacing)
3302 Spacing = 1; // Register range implies a single spaced list.
3303 else if (Spacing == 2) {
3304 Error(Parser.getTok().getLoc(),
3305 "sequential registers in double spaced list");
3306 return MatchOperand_ParseFail;
3307 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003308 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003309 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003310 int EndReg = tryParseRegister();
3311 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003312 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003313 return MatchOperand_ParseFail;
3314 }
3315 // Allow Q regs and just interpret them as the two D sub-registers.
3316 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3317 EndReg = getDRegFromQReg(EndReg) + 1;
3318 // If the register is the same as the start reg, there's nothing
3319 // more to do.
3320 if (Reg == EndReg)
3321 continue;
3322 // The register must be in the same register class as the first.
3323 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003324 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003325 return MatchOperand_ParseFail;
3326 }
3327 // Ranges must go from low to high.
3328 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003329 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003330 return MatchOperand_ParseFail;
3331 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003332 // Parse the lane specifier if present.
3333 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003334 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003335 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3336 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003337 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003338 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003339 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003340 return MatchOperand_ParseFail;
3341 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003342
3343 // Add all the registers in the range to the register list.
3344 Count += EndReg - Reg;
3345 Reg = EndReg;
3346 continue;
3347 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003348 Parser.Lex(); // Eat the comma.
3349 RegLoc = Parser.getTok().getLoc();
3350 int OldReg = Reg;
3351 Reg = tryParseRegister();
3352 if (Reg == -1) {
3353 Error(RegLoc, "register expected");
3354 return MatchOperand_ParseFail;
3355 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003356 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003357 // It's OK to use the enumeration values directly here rather, as the
3358 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003359 //
3360 // The list is of D registers, but we also allow Q regs and just interpret
3361 // them as the two D sub-registers.
3362 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003363 if (!Spacing)
3364 Spacing = 1; // Register range implies a single spaced list.
3365 else if (Spacing == 2) {
3366 Error(RegLoc,
3367 "invalid register in double-spaced list (must be 'D' register')");
3368 return MatchOperand_ParseFail;
3369 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003370 Reg = getDRegFromQReg(Reg);
3371 if (Reg != OldReg + 1) {
3372 Error(RegLoc, "non-contiguous register range");
3373 return MatchOperand_ParseFail;
3374 }
3375 ++Reg;
3376 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003377 // Parse the lane specifier if present.
3378 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003379 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003380 SMLoc LaneLoc = Parser.getTok().getLoc();
3381 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3382 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003383 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003384 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003385 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003386 return MatchOperand_ParseFail;
3387 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003388 continue;
3389 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003390 // Normal D register.
3391 // Figure out the register spacing (single or double) of the list if
3392 // we don't know it already.
3393 if (!Spacing)
3394 Spacing = 1 + (Reg == OldReg + 2);
3395
3396 // Just check that it's contiguous and keep going.
3397 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003398 Error(RegLoc, "non-contiguous register range");
3399 return MatchOperand_ParseFail;
3400 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003401 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003402 // Parse the lane specifier if present.
3403 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003404 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003405 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003406 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003407 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003408 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003409 Error(EndLoc, "mismatched lane index in register list");
3410 return MatchOperand_ParseFail;
3411 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003412 }
3413
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003414 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003415 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003416 return MatchOperand_ParseFail;
3417 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003418 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003419 Parser.Lex(); // Eat '}' token.
3420
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003421 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003422 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003423 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003424 // composite register classes.
3425 if (Count == 2) {
3426 const MCRegisterClass *RC = (Spacing == 1) ?
3427 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3428 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3429 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3430 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003431
Jim Grosbach2f50e922011-12-15 21:44:33 +00003432 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3433 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003434 break;
3435 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003436 // Two-register operands have been converted to the
3437 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003438 if (Count == 2) {
3439 const MCRegisterClass *RC = (Spacing == 1) ?
3440 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3441 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003442 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3443 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003444 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003445 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003446 S, E));
3447 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003448 case IndexedLane:
3449 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003450 LaneIndex,
3451 (Spacing == 2),
3452 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003453 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003454 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003455 return MatchOperand_Success;
3456}
3457
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003458/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003459ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003460parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003461 SMLoc S = Parser.getTok().getLoc();
3462 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003463 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003464
Jiangning Liu288e1af2012-08-02 08:21:27 +00003465 if (Tok.is(AsmToken::Identifier)) {
3466 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003467
Jiangning Liu288e1af2012-08-02 08:21:27 +00003468 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3469 .Case("sy", ARM_MB::SY)
3470 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003471 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003472 .Case("sh", ARM_MB::ISH)
3473 .Case("ish", ARM_MB::ISH)
3474 .Case("shst", ARM_MB::ISHST)
3475 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003476 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003477 .Case("nsh", ARM_MB::NSH)
3478 .Case("un", ARM_MB::NSH)
3479 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003480 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003481 .Case("unst", ARM_MB::NSHST)
3482 .Case("osh", ARM_MB::OSH)
3483 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003484 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003485 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003486
Joey Gouly926d3f52013-09-05 15:35:24 +00003487 // ishld, oshld, nshld and ld are only available from ARMv8.
3488 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3489 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3490 Opt = ~0U;
3491
Jiangning Liu288e1af2012-08-02 08:21:27 +00003492 if (Opt == ~0U)
3493 return MatchOperand_NoMatch;
3494
3495 Parser.Lex(); // Eat identifier token.
3496 } else if (Tok.is(AsmToken::Hash) ||
3497 Tok.is(AsmToken::Dollar) ||
3498 Tok.is(AsmToken::Integer)) {
3499 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003500 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003501 SMLoc Loc = Parser.getTok().getLoc();
3502
3503 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003504 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003505 Error(Loc, "illegal expression");
3506 return MatchOperand_ParseFail;
3507 }
3508
3509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3510 if (!CE) {
3511 Error(Loc, "constant expression expected");
3512 return MatchOperand_ParseFail;
3513 }
3514
3515 int Val = CE->getValue();
3516 if (Val & ~0xf) {
3517 Error(Loc, "immediate value out of range");
3518 return MatchOperand_ParseFail;
3519 }
3520
3521 Opt = ARM_MB::RESERVED_0 + Val;
3522 } else
3523 return MatchOperand_ParseFail;
3524
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003525 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003526 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003527}
3528
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003529/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3530ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3531parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3532 SMLoc S = Parser.getTok().getLoc();
3533 const AsmToken &Tok = Parser.getTok();
3534 unsigned Opt;
3535
3536 if (Tok.is(AsmToken::Identifier)) {
3537 StringRef OptStr = Tok.getString();
3538
3539 if (OptStr.lower() == "sy")
3540 Opt = ARM_ISB::SY;
3541 else
3542 return MatchOperand_NoMatch;
3543
3544 Parser.Lex(); // Eat identifier token.
3545 } else if (Tok.is(AsmToken::Hash) ||
3546 Tok.is(AsmToken::Dollar) ||
3547 Tok.is(AsmToken::Integer)) {
3548 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003549 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003550 SMLoc Loc = Parser.getTok().getLoc();
3551
3552 const MCExpr *ISBarrierID;
3553 if (getParser().parseExpression(ISBarrierID)) {
3554 Error(Loc, "illegal expression");
3555 return MatchOperand_ParseFail;
3556 }
3557
3558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3559 if (!CE) {
3560 Error(Loc, "constant expression expected");
3561 return MatchOperand_ParseFail;
3562 }
3563
3564 int Val = CE->getValue();
3565 if (Val & ~0xf) {
3566 Error(Loc, "immediate value out of range");
3567 return MatchOperand_ParseFail;
3568 }
3569
3570 Opt = ARM_ISB::RESERVED_0 + Val;
3571 } else
3572 return MatchOperand_ParseFail;
3573
3574 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3575 (ARM_ISB::InstSyncBOpt)Opt, S));
3576 return MatchOperand_Success;
3577}
3578
3579
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003580/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003581ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003582parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003583 SMLoc S = Parser.getTok().getLoc();
3584 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003585 if (!Tok.is(AsmToken::Identifier))
3586 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003587 StringRef IFlagsStr = Tok.getString();
3588
Owen Anderson10c5b122011-10-05 17:16:40 +00003589 // An iflags string of "none" is interpreted to mean that none of the AIF
3590 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003591 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003592 if (IFlagsStr != "none") {
3593 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3594 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3595 .Case("a", ARM_PROC::A)
3596 .Case("i", ARM_PROC::I)
3597 .Case("f", ARM_PROC::F)
3598 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003599
Owen Anderson10c5b122011-10-05 17:16:40 +00003600 // If some specific iflag is already set, it means that some letter is
3601 // present more than once, this is not acceptable.
3602 if (Flag == ~0U || (IFlags & Flag))
3603 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003604
Owen Anderson10c5b122011-10-05 17:16:40 +00003605 IFlags |= Flag;
3606 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003607 }
3608
3609 Parser.Lex(); // Eat identifier token.
3610 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3611 return MatchOperand_Success;
3612}
3613
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003614/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003615ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003616parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003617 SMLoc S = Parser.getTok().getLoc();
3618 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003619 if (!Tok.is(AsmToken::Identifier))
3620 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003621 StringRef Mask = Tok.getString();
3622
James Molloy21efa7d2011-09-28 14:21:38 +00003623 if (isMClass()) {
3624 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003625 std::string Name = Mask.lower();
3626 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003627 // Note: in the documentation:
3628 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3629 // for MSR APSR_nzcvq.
3630 // but we do make it an alias here. This is so to get the "mask encoding"
3631 // bits correct on MSR APSR writes.
3632 //
3633 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3634 // should really only be allowed when writing a special register. Note
3635 // they get dropped in the MRS instruction reading a special register as
3636 // the SYSm field is only 8 bits.
3637 //
3638 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3639 // includes the DSP extension but that is not checked.
3640 .Case("apsr", 0x800)
3641 .Case("apsr_nzcvq", 0x800)
3642 .Case("apsr_g", 0x400)
3643 .Case("apsr_nzcvqg", 0xc00)
3644 .Case("iapsr", 0x801)
3645 .Case("iapsr_nzcvq", 0x801)
3646 .Case("iapsr_g", 0x401)
3647 .Case("iapsr_nzcvqg", 0xc01)
3648 .Case("eapsr", 0x802)
3649 .Case("eapsr_nzcvq", 0x802)
3650 .Case("eapsr_g", 0x402)
3651 .Case("eapsr_nzcvqg", 0xc02)
3652 .Case("xpsr", 0x803)
3653 .Case("xpsr_nzcvq", 0x803)
3654 .Case("xpsr_g", 0x403)
3655 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003656 .Case("ipsr", 0x805)
3657 .Case("epsr", 0x806)
3658 .Case("iepsr", 0x807)
3659 .Case("msp", 0x808)
3660 .Case("psp", 0x809)
3661 .Case("primask", 0x810)
3662 .Case("basepri", 0x811)
3663 .Case("basepri_max", 0x812)
3664 .Case("faultmask", 0x813)
3665 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003666 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003667
James Molloy21efa7d2011-09-28 14:21:38 +00003668 if (FlagsVal == ~0U)
3669 return MatchOperand_NoMatch;
3670
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003671 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003672 // basepri, basepri_max and faultmask only valid for V7m.
3673 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003674
James Molloy21efa7d2011-09-28 14:21:38 +00003675 Parser.Lex(); // Eat identifier token.
3676 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3677 return MatchOperand_Success;
3678 }
3679
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003680 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3681 size_t Start = 0, Next = Mask.find('_');
3682 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003683 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003684 if (Next != StringRef::npos)
3685 Flags = Mask.slice(Next+1, Mask.size());
3686
3687 // FlagsVal contains the complete mask:
3688 // 3-0: Mask
3689 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3690 unsigned FlagsVal = 0;
3691
3692 if (SpecReg == "apsr") {
3693 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003694 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003695 .Case("g", 0x4) // same as CPSR_s
3696 .Case("nzcvqg", 0xc) // same as CPSR_fs
3697 .Default(~0U);
3698
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003699 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003700 if (!Flags.empty())
3701 return MatchOperand_NoMatch;
3702 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003703 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003704 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003705 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003706 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3707 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003708 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003709 for (int i = 0, e = Flags.size(); i != e; ++i) {
3710 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3711 .Case("c", 1)
3712 .Case("x", 2)
3713 .Case("s", 4)
3714 .Case("f", 8)
3715 .Default(~0U);
3716
3717 // If some specific flag is already set, it means that some letter is
3718 // present more than once, this is not acceptable.
3719 if (FlagsVal == ~0U || (FlagsVal & Flag))
3720 return MatchOperand_NoMatch;
3721 FlagsVal |= Flag;
3722 }
3723 } else // No match for special register.
3724 return MatchOperand_NoMatch;
3725
Owen Anderson03a173e2011-10-21 18:43:28 +00003726 // Special register without flags is NOT equivalent to "fc" flags.
3727 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3728 // two lines would enable gas compatibility at the expense of breaking
3729 // round-tripping.
3730 //
3731 // if (!FlagsVal)
3732 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003733
3734 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3735 if (SpecReg == "spsr")
3736 FlagsVal |= 16;
3737
3738 Parser.Lex(); // Eat identifier token.
3739 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3740 return MatchOperand_Success;
3741}
3742
Jim Grosbach27c1e252011-07-21 17:23:04 +00003743ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3744parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3745 int Low, int High) {
3746 const AsmToken &Tok = Parser.getTok();
3747 if (Tok.isNot(AsmToken::Identifier)) {
3748 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3749 return MatchOperand_ParseFail;
3750 }
3751 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003752 std::string LowerOp = Op.lower();
3753 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003754 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3755 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3756 return MatchOperand_ParseFail;
3757 }
3758 Parser.Lex(); // Eat shift type token.
3759
3760 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003761 if (Parser.getTok().isNot(AsmToken::Hash) &&
3762 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003763 Error(Parser.getTok().getLoc(), "'#' expected");
3764 return MatchOperand_ParseFail;
3765 }
3766 Parser.Lex(); // Eat hash token.
3767
3768 const MCExpr *ShiftAmount;
3769 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003770 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003771 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003772 Error(Loc, "illegal expression");
3773 return MatchOperand_ParseFail;
3774 }
3775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3776 if (!CE) {
3777 Error(Loc, "constant expression expected");
3778 return MatchOperand_ParseFail;
3779 }
3780 int Val = CE->getValue();
3781 if (Val < Low || Val > High) {
3782 Error(Loc, "immediate value out of range");
3783 return MatchOperand_ParseFail;
3784 }
3785
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003786 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003787
3788 return MatchOperand_Success;
3789}
3790
Jim Grosbach0a547702011-07-22 17:44:50 +00003791ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3792parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3793 const AsmToken &Tok = Parser.getTok();
3794 SMLoc S = Tok.getLoc();
3795 if (Tok.isNot(AsmToken::Identifier)) {
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 }
Tim Northover4d141442013-05-31 15:58:45 +00003799 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003800 .Case("be", 1)
3801 .Case("le", 0)
3802 .Default(-1);
3803 Parser.Lex(); // Eat the token.
3804
3805 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003806 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003807 return MatchOperand_ParseFail;
3808 }
3809 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3810 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003811 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003812 return MatchOperand_Success;
3813}
3814
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003815/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3816/// instructions. Legal values are:
3817/// lsl #n 'n' in [0,31]
3818/// asr #n 'n' in [1,32]
3819/// n == 32 encoded as n == 0.
3820ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3821parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3822 const AsmToken &Tok = Parser.getTok();
3823 SMLoc S = Tok.getLoc();
3824 if (Tok.isNot(AsmToken::Identifier)) {
3825 Error(S, "shift operator 'asr' or 'lsl' expected");
3826 return MatchOperand_ParseFail;
3827 }
3828 StringRef ShiftName = Tok.getString();
3829 bool isASR;
3830 if (ShiftName == "lsl" || ShiftName == "LSL")
3831 isASR = false;
3832 else if (ShiftName == "asr" || ShiftName == "ASR")
3833 isASR = true;
3834 else {
3835 Error(S, "shift operator 'asr' or 'lsl' expected");
3836 return MatchOperand_ParseFail;
3837 }
3838 Parser.Lex(); // Eat the operator.
3839
3840 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003841 if (Parser.getTok().isNot(AsmToken::Hash) &&
3842 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003843 Error(Parser.getTok().getLoc(), "'#' expected");
3844 return MatchOperand_ParseFail;
3845 }
3846 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003847 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003848
3849 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003850 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003851 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003852 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003853 return MatchOperand_ParseFail;
3854 }
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3856 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003857 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003858 return MatchOperand_ParseFail;
3859 }
3860
3861 int64_t Val = CE->getValue();
3862 if (isASR) {
3863 // Shift amount must be in [1,32]
3864 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003865 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003866 return MatchOperand_ParseFail;
3867 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003868 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3869 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003870 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003871 return MatchOperand_ParseFail;
3872 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003873 if (Val == 32) Val = 0;
3874 } else {
3875 // Shift amount must be in [1,32]
3876 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003877 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003878 return MatchOperand_ParseFail;
3879 }
3880 }
3881
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003882 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003883
3884 return MatchOperand_Success;
3885}
3886
Jim Grosbach833b9d32011-07-27 20:15:40 +00003887/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3888/// of instructions. Legal values are:
3889/// ror #n 'n' in {0, 8, 16, 24}
3890ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3891parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3892 const AsmToken &Tok = Parser.getTok();
3893 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003894 if (Tok.isNot(AsmToken::Identifier))
3895 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003896 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003897 if (ShiftName != "ror" && ShiftName != "ROR")
3898 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003899 Parser.Lex(); // Eat the operator.
3900
3901 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003902 if (Parser.getTok().isNot(AsmToken::Hash) &&
3903 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003904 Error(Parser.getTok().getLoc(), "'#' expected");
3905 return MatchOperand_ParseFail;
3906 }
3907 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003908 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003909
3910 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003911 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003912 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003913 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003914 return MatchOperand_ParseFail;
3915 }
3916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3917 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003918 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003919 return MatchOperand_ParseFail;
3920 }
3921
3922 int64_t Val = CE->getValue();
3923 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3924 // normally, zero is represented in asm by omitting the rotate operand
3925 // entirely.
3926 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003927 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003928 return MatchOperand_ParseFail;
3929 }
3930
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003931 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003932
3933 return MatchOperand_Success;
3934}
3935
Jim Grosbach864b6092011-07-28 21:34:26 +00003936ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3937parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3938 SMLoc S = Parser.getTok().getLoc();
3939 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003940 if (Parser.getTok().isNot(AsmToken::Hash) &&
3941 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003942 Error(Parser.getTok().getLoc(), "'#' expected");
3943 return MatchOperand_ParseFail;
3944 }
3945 Parser.Lex(); // Eat hash token.
3946
3947 const MCExpr *LSBExpr;
3948 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003949 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003950 Error(E, "malformed immediate expression");
3951 return MatchOperand_ParseFail;
3952 }
3953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3954 if (!CE) {
3955 Error(E, "'lsb' operand must be an immediate");
3956 return MatchOperand_ParseFail;
3957 }
3958
3959 int64_t LSB = CE->getValue();
3960 // The LSB must be in the range [0,31]
3961 if (LSB < 0 || LSB > 31) {
3962 Error(E, "'lsb' operand must be in the range [0,31]");
3963 return MatchOperand_ParseFail;
3964 }
3965 E = Parser.getTok().getLoc();
3966
3967 // Expect another immediate operand.
3968 if (Parser.getTok().isNot(AsmToken::Comma)) {
3969 Error(Parser.getTok().getLoc(), "too few operands");
3970 return MatchOperand_ParseFail;
3971 }
3972 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003973 if (Parser.getTok().isNot(AsmToken::Hash) &&
3974 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003975 Error(Parser.getTok().getLoc(), "'#' expected");
3976 return MatchOperand_ParseFail;
3977 }
3978 Parser.Lex(); // Eat hash token.
3979
3980 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003981 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003982 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003983 Error(E, "malformed immediate expression");
3984 return MatchOperand_ParseFail;
3985 }
3986 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3987 if (!CE) {
3988 Error(E, "'width' operand must be an immediate");
3989 return MatchOperand_ParseFail;
3990 }
3991
3992 int64_t Width = CE->getValue();
3993 // The LSB must be in the range [1,32-lsb]
3994 if (Width < 1 || Width > 32 - LSB) {
3995 Error(E, "'width' operand must be in the range [1,32-lsb]");
3996 return MatchOperand_ParseFail;
3997 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003998
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003999 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004000
4001 return MatchOperand_Success;
4002}
4003
Jim Grosbachd3595712011-08-03 23:50:40 +00004004ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4005parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4006 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004007 // postidx_reg := '+' register {, shift}
4008 // | '-' register {, shift}
4009 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004010
4011 // This method must return MatchOperand_NoMatch without consuming any tokens
4012 // in the case where there is no match, as other alternatives take other
4013 // parse methods.
4014 AsmToken Tok = Parser.getTok();
4015 SMLoc S = Tok.getLoc();
4016 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004017 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004018 if (Tok.is(AsmToken::Plus)) {
4019 Parser.Lex(); // Eat the '+' token.
4020 haveEaten = true;
4021 } else if (Tok.is(AsmToken::Minus)) {
4022 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004023 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004024 haveEaten = true;
4025 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004026
4027 SMLoc E = Parser.getTok().getEndLoc();
4028 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004029 if (Reg == -1) {
4030 if (!haveEaten)
4031 return MatchOperand_NoMatch;
4032 Error(Parser.getTok().getLoc(), "register expected");
4033 return MatchOperand_ParseFail;
4034 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004035
Jim Grosbachc320c852011-08-05 21:28:30 +00004036 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4037 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004038 if (Parser.getTok().is(AsmToken::Comma)) {
4039 Parser.Lex(); // Eat the ','.
4040 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4041 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004042
4043 // FIXME: Only approximates end...may include intervening whitespace.
4044 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004045 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004046
4047 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4048 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004049
4050 return MatchOperand_Success;
4051}
4052
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004053ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4054parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4055 // Check for a post-index addressing register operand. Specifically:
4056 // am3offset := '+' register
4057 // | '-' register
4058 // | register
4059 // | # imm
4060 // | # + imm
4061 // | # - imm
4062
4063 // This method must return MatchOperand_NoMatch without consuming any tokens
4064 // in the case where there is no match, as other alternatives take other
4065 // parse methods.
4066 AsmToken Tok = Parser.getTok();
4067 SMLoc S = Tok.getLoc();
4068
4069 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004070 if (Parser.getTok().is(AsmToken::Hash) ||
4071 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004072 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004073 // Explicitly look for a '-', as we need to encode negative zero
4074 // differently.
4075 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4076 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004077 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004078 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004079 return MatchOperand_ParseFail;
4080 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4081 if (!CE) {
4082 Error(S, "constant expression expected");
4083 return MatchOperand_ParseFail;
4084 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004085 // Negative zero is encoded as the flag value INT32_MIN.
4086 int32_t Val = CE->getValue();
4087 if (isNegative && Val == 0)
4088 Val = INT32_MIN;
4089
4090 Operands.push_back(
4091 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4092
4093 return MatchOperand_Success;
4094 }
4095
4096
4097 bool haveEaten = false;
4098 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004099 if (Tok.is(AsmToken::Plus)) {
4100 Parser.Lex(); // Eat the '+' token.
4101 haveEaten = true;
4102 } else if (Tok.is(AsmToken::Minus)) {
4103 Parser.Lex(); // Eat the '-' token.
4104 isAdd = false;
4105 haveEaten = true;
4106 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004107
4108 Tok = Parser.getTok();
4109 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004110 if (Reg == -1) {
4111 if (!haveEaten)
4112 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004113 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004114 return MatchOperand_ParseFail;
4115 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004116
4117 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004118 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004119
4120 return MatchOperand_Success;
4121}
4122
Tim Northovereb5e4d52013-07-22 09:06:12 +00004123/// Convert parsed operands to MCInst. Needed here because this instruction
4124/// only has two register operands, but multiplication is commutative so
4125/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004126void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004127cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004128 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004129 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4130 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004131 // If we have a three-operand form, make sure to set Rn to be the operand
4132 // that isn't the same as Rd.
4133 unsigned RegOp = 4;
4134 if (Operands.size() == 6 &&
4135 ((ARMOperand*)Operands[4])->getReg() ==
4136 ((ARMOperand*)Operands[3])->getReg())
4137 RegOp = 5;
4138 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4139 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004140 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004141}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004142
Mihai Popaad18d3c2013-08-09 10:38:32 +00004143void ARMAsmParser::
4144cvtThumbBranches(MCInst &Inst,
4145 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 int CondOp = -1, ImmOp = -1;
4147 switch(Inst.getOpcode()) {
4148 case ARM::tB:
4149 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4150
4151 case ARM::t2B:
4152 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4153
4154 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4155 }
4156 // first decide whether or not the branch should be conditional
4157 // by looking at it's location relative to an IT block
4158 if(inITBlock()) {
4159 // inside an IT block we cannot have any conditional branches. any
4160 // such instructions needs to be converted to unconditional form
4161 switch(Inst.getOpcode()) {
4162 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4163 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4164 }
4165 } else {
4166 // outside IT blocks we can only have unconditional branches with AL
4167 // condition code or conditional branches with non-AL condition code
4168 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4169 switch(Inst.getOpcode()) {
4170 case ARM::tB:
4171 case ARM::tBcc:
4172 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4173 break;
4174 case ARM::t2B:
4175 case ARM::t2Bcc:
4176 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4177 break;
4178 }
4179 }
4180
4181 // now decide on encoding size based on branch target range
4182 switch(Inst.getOpcode()) {
4183 // classify tB as either t2B or t1B based on range of immediate operand
4184 case ARM::tB: {
4185 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4186 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4187 Inst.setOpcode(ARM::t2B);
4188 break;
4189 }
4190 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4191 case ARM::tBcc: {
4192 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4193 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4194 Inst.setOpcode(ARM::t2Bcc);
4195 break;
4196 }
4197 }
4198 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4199 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4200}
4201
Bill Wendlinge18980a2010-11-06 22:36:58 +00004202/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004203/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004204bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004205parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004206 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004207 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004208 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004209 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004210 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004211
Sean Callanan936b0d32010-01-19 21:44:56 +00004212 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004213 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004214 if (BaseRegNum == -1)
4215 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004216
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004217 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004218 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004219 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4220 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004221 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004222
Jim Grosbachd3595712011-08-03 23:50:40 +00004223 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004224 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004225 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004226
Jim Grosbachd3595712011-08-03 23:50:40 +00004227 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004228 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004229
Jim Grosbach40700e02011-09-19 18:42:21 +00004230 // If there's a pre-indexing writeback marker, '!', just add it as a token
4231 // operand. It's rather odd, but syntactically valid.
4232 if (Parser.getTok().is(AsmToken::Exclaim)) {
4233 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4234 Parser.Lex(); // Eat the '!'.
4235 }
4236
Jim Grosbachd3595712011-08-03 23:50:40 +00004237 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004238 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004239
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004240 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4241 "Lost colon or comma in memory operand?!");
4242 if (Tok.is(AsmToken::Comma)) {
4243 Parser.Lex(); // Eat the comma.
4244 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004245
Jim Grosbacha95ec992011-10-11 17:29:55 +00004246 // If we have a ':', it's an alignment specifier.
4247 if (Parser.getTok().is(AsmToken::Colon)) {
4248 Parser.Lex(); // Eat the ':'.
4249 E = Parser.getTok().getLoc();
4250
4251 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004252 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004253 return true;
4254
4255 // The expression has to be a constant. Memory references with relocations
4256 // don't come through here, as they use the <label> forms of the relevant
4257 // instructions.
4258 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4259 if (!CE)
4260 return Error (E, "constant expression expected");
4261
4262 unsigned Align = 0;
4263 switch (CE->getValue()) {
4264 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004265 return Error(E,
4266 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4267 case 16: Align = 2; break;
4268 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004269 case 64: Align = 8; break;
4270 case 128: Align = 16; break;
4271 case 256: Align = 32; break;
4272 }
4273
4274 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004275 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004276 return Error(Parser.getTok().getLoc(), "']' expected");
4277 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004278 Parser.Lex(); // Eat right bracket token.
4279
4280 // Don't worry about range checking the value here. That's handled by
4281 // the is*() predicates.
4282 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4283 ARM_AM::no_shift, 0, Align,
4284 false, S, E));
4285
4286 // If there's a pre-indexing writeback marker, '!', just add it as a token
4287 // operand.
4288 if (Parser.getTok().is(AsmToken::Exclaim)) {
4289 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4290 Parser.Lex(); // Eat the '!'.
4291 }
4292
4293 return false;
4294 }
4295
4296 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004297 // offset. Be friendly and also accept a plain integer (without a leading
4298 // hash) for gas compatibility.
4299 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004300 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004301 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004302 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004303 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004304 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004305
Owen Anderson967674d2011-08-29 19:36:44 +00004306 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004307 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004308 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004309 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004310
4311 // The expression has to be a constant. Memory references with relocations
4312 // don't come through here, as they use the <label> forms of the relevant
4313 // instructions.
4314 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4315 if (!CE)
4316 return Error (E, "constant expression expected");
4317
Owen Anderson967674d2011-08-29 19:36:44 +00004318 // If the constant was #-0, represent it as INT32_MIN.
4319 int32_t Val = CE->getValue();
4320 if (isNegative && Val == 0)
4321 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4322
Jim Grosbachd3595712011-08-03 23:50:40 +00004323 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004324 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004325 return Error(Parser.getTok().getLoc(), "']' expected");
4326 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004327 Parser.Lex(); // Eat right bracket token.
4328
4329 // Don't worry about range checking the value here. That's handled by
4330 // the is*() predicates.
4331 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004332 ARM_AM::no_shift, 0, 0,
4333 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004334
4335 // If there's a pre-indexing writeback marker, '!', just add it as a token
4336 // operand.
4337 if (Parser.getTok().is(AsmToken::Exclaim)) {
4338 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4339 Parser.Lex(); // Eat the '!'.
4340 }
4341
4342 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004343 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004344
4345 // The register offset is optionally preceded by a '+' or '-'
4346 bool isNegative = false;
4347 if (Parser.getTok().is(AsmToken::Minus)) {
4348 isNegative = true;
4349 Parser.Lex(); // Eat the '-'.
4350 } else if (Parser.getTok().is(AsmToken::Plus)) {
4351 // Nothing to do.
4352 Parser.Lex(); // Eat the '+'.
4353 }
4354
4355 E = Parser.getTok().getLoc();
4356 int OffsetRegNum = tryParseRegister();
4357 if (OffsetRegNum == -1)
4358 return Error(E, "register expected");
4359
4360 // If there's a shift operator, handle it.
4361 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004362 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004363 if (Parser.getTok().is(AsmToken::Comma)) {
4364 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004365 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004366 return true;
4367 }
4368
4369 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004370 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004371 return Error(Parser.getTok().getLoc(), "']' expected");
4372 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004373 Parser.Lex(); // Eat right bracket token.
4374
4375 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004376 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004377 S, E));
4378
Jim Grosbachc320c852011-08-05 21:28:30 +00004379 // If there's a pre-indexing writeback marker, '!', just add it as a token
4380 // operand.
4381 if (Parser.getTok().is(AsmToken::Exclaim)) {
4382 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4383 Parser.Lex(); // Eat the '!'.
4384 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004385
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004386 return false;
4387}
4388
Jim Grosbachd3595712011-08-03 23:50:40 +00004389/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004390/// ( lsl | lsr | asr | ror ) , # shift_amount
4391/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004392/// return true if it parses a shift otherwise it returns false.
4393bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4394 unsigned &Amount) {
4395 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004396 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004397 if (Tok.isNot(AsmToken::Identifier))
4398 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004399 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004400 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4401 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004402 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004403 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004404 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004406 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004407 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004408 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004410 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004411 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004412 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004413 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004414
Jim Grosbachd3595712011-08-03 23:50:40 +00004415 // rrx stands alone.
4416 Amount = 0;
4417 if (St != ARM_AM::rrx) {
4418 Loc = Parser.getTok().getLoc();
4419 // A '#' and a shift amount.
4420 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004421 if (HashTok.isNot(AsmToken::Hash) &&
4422 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004423 return Error(HashTok.getLoc(), "'#' expected");
4424 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004425
Jim Grosbachd3595712011-08-03 23:50:40 +00004426 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004427 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004428 return true;
4429 // Range check the immediate.
4430 // lsl, ror: 0 <= imm <= 31
4431 // lsr, asr: 0 <= imm <= 32
4432 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4433 if (!CE)
4434 return Error(Loc, "shift amount must be an immediate");
4435 int64_t Imm = CE->getValue();
4436 if (Imm < 0 ||
4437 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4438 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4439 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004440 // If <ShiftTy> #0, turn it into a no_shift.
4441 if (Imm == 0)
4442 St = ARM_AM::lsl;
4443 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4444 if (Imm == 32)
4445 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004446 Amount = Imm;
4447 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004448
4449 return false;
4450}
4451
Jim Grosbache7fbce72011-10-03 23:38:36 +00004452/// parseFPImm - A floating point immediate expression operand.
4453ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4454parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004455 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004456 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004457 // integer only.
4458 //
4459 // This routine still creates a generic Immediate operand, containing
4460 // a bitcast of the 64-bit floating point value. The various operands
4461 // that accept floats can check whether the value is valid for them
4462 // via the standard is*() predicates.
4463
Jim Grosbache7fbce72011-10-03 23:38:36 +00004464 SMLoc S = Parser.getTok().getLoc();
4465
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004466 if (Parser.getTok().isNot(AsmToken::Hash) &&
4467 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004468 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004469
4470 // Disambiguate the VMOV forms that can accept an FP immediate.
4471 // vmov.f32 <sreg>, #imm
4472 // vmov.f64 <dreg>, #imm
4473 // vmov.f32 <dreg>, #imm @ vector f32x2
4474 // vmov.f32 <qreg>, #imm @ vector f32x4
4475 //
4476 // There are also the NEON VMOV instructions which expect an
4477 // integer constant. Make sure we don't try to parse an FPImm
4478 // for these:
4479 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4480 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4481 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4482 TyOp->getToken() != ".f64"))
4483 return MatchOperand_NoMatch;
4484
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004485 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004486
4487 // Handle negation, as that still comes through as a separate token.
4488 bool isNegative = false;
4489 if (Parser.getTok().is(AsmToken::Minus)) {
4490 isNegative = true;
4491 Parser.Lex();
4492 }
4493 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004494 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004495 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004496 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004497 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4498 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004499 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004500 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004501 Operands.push_back(ARMOperand::CreateImm(
4502 MCConstantExpr::Create(IntVal, getContext()),
4503 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004504 return MatchOperand_Success;
4505 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004506 // Also handle plain integers. Instructions which allow floating point
4507 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004508 if (Tok.is(AsmToken::Integer)) {
4509 int64_t Val = Tok.getIntVal();
4510 Parser.Lex(); // Eat the token.
4511 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004512 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004513 return MatchOperand_ParseFail;
4514 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004515 double RealVal = ARM_AM::getFPImmFloat(Val);
4516 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4517 Operands.push_back(ARMOperand::CreateImm(
4518 MCConstantExpr::Create(Val, getContext()), S,
4519 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004520 return MatchOperand_Success;
4521 }
4522
Jim Grosbach235c8d22012-01-19 02:47:30 +00004523 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004524 return MatchOperand_ParseFail;
4525}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004526
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004527/// Parse a arm instruction operand. For now this parses the operand regardless
4528/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004529bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004530 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004531 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004532
4533 // Check if the current operand has a custom associated parser, if so, try to
4534 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004535 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4536 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004537 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004538 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4539 // there was a match, but an error occurred, in which case, just return that
4540 // the operand parsing failed.
4541 if (ResTy == MatchOperand_ParseFail)
4542 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004543
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004544 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004545 default:
4546 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004547 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004548 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004549 // If we've seen a branch mnemonic, the next operand must be a label. This
4550 // is true even if the label is a register name. So "br r1" means branch to
4551 // label "r1".
4552 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4553 if (!ExpectLabel) {
4554 if (!tryParseRegisterWithWriteBack(Operands))
4555 return false;
4556 int Res = tryParseShiftRegister(Operands);
4557 if (Res == 0) // success
4558 return false;
4559 else if (Res == -1) // irrecoverable error
4560 return true;
4561 // If this is VMRS, check for the apsr_nzcv operand.
4562 if (Mnemonic == "vmrs" &&
4563 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4564 S = Parser.getTok().getLoc();
4565 Parser.Lex();
4566 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4567 return false;
4568 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004569 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004570
4571 // Fall though for the Identifier case that is not a register or a
4572 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004573 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004574 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004575 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004576 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004577 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004578 // This was not a register so parse other operands that start with an
4579 // identifier (like labels) as expressions and create them as immediates.
4580 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004581 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004582 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004583 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004584 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004585 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4586 return false;
4587 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004588 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004589 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004590 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004591 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004592 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004593 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004594 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004595 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004596 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004597
4598 if (Parser.getTok().isNot(AsmToken::Colon)) {
4599 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4600 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004601 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004602 return true;
4603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4604 if (CE) {
4605 int32_t Val = CE->getValue();
4606 if (isNegative && Val == 0)
4607 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4608 }
4609 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4610 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004611
4612 // There can be a trailing '!' on operands that we want as a separate
4613 // '!' Token operand. Handle that here. For example, the compatibilty
4614 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4615 if (Parser.getTok().is(AsmToken::Exclaim)) {
4616 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4617 Parser.getTok().getLoc()));
4618 Parser.Lex(); // Eat exclaim token
4619 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004620 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004621 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004622 // w/ a ':' after the '#', it's just like a plain ':'.
4623 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004624 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004625 case AsmToken::Colon: {
4626 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004627 // FIXME: Check it's an expression prefix,
4628 // e.g. (FOO - :lower16:BAR) isn't legal.
4629 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004630 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004631 return true;
4632
Evan Cheng965b3c72011-01-13 07:58:56 +00004633 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004634 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004635 return true;
4636
Evan Cheng965b3c72011-01-13 07:58:56 +00004637 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004638 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004639 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004640 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004641 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004642 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004643 }
4644}
4645
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004646// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004647// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004648bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004649 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004650
4651 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004652 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004653 Parser.Lex(); // Eat ':'
4654
4655 if (getLexer().isNot(AsmToken::Identifier)) {
4656 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4657 return true;
4658 }
4659
4660 StringRef IDVal = Parser.getTok().getIdentifier();
4661 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004662 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004663 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004664 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004665 } else {
4666 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4667 return true;
4668 }
4669 Parser.Lex();
4670
4671 if (getLexer().isNot(AsmToken::Colon)) {
4672 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4673 return true;
4674 }
4675 Parser.Lex(); // Eat the last ':'
4676 return false;
4677}
4678
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004679/// \brief Given a mnemonic, split out possible predication code and carry
4680/// setting letters to form a canonical mnemonic and flags.
4681//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004682// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004683// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004684StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004685 unsigned &PredicationCode,
4686 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004687 unsigned &ProcessorIMod,
4688 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004689 PredicationCode = ARMCC::AL;
4690 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004691 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004692
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004693 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004694 //
4695 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004696 if ((Mnemonic == "movs" && isThumb()) ||
4697 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4698 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4699 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4700 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004701 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004702 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4703 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004704 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004705 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004706 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4707 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4708 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004709 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004710
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004711 // First, split out any predication code. Ignore mnemonics we know aren't
4712 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004713 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004714 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004715 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004716 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004717 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4718 .Case("eq", ARMCC::EQ)
4719 .Case("ne", ARMCC::NE)
4720 .Case("hs", ARMCC::HS)
4721 .Case("cs", ARMCC::HS)
4722 .Case("lo", ARMCC::LO)
4723 .Case("cc", ARMCC::LO)
4724 .Case("mi", ARMCC::MI)
4725 .Case("pl", ARMCC::PL)
4726 .Case("vs", ARMCC::VS)
4727 .Case("vc", ARMCC::VC)
4728 .Case("hi", ARMCC::HI)
4729 .Case("ls", ARMCC::LS)
4730 .Case("ge", ARMCC::GE)
4731 .Case("lt", ARMCC::LT)
4732 .Case("gt", ARMCC::GT)
4733 .Case("le", ARMCC::LE)
4734 .Case("al", ARMCC::AL)
4735 .Default(~0U);
4736 if (CC != ~0U) {
4737 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4738 PredicationCode = CC;
4739 }
Bill Wendling193961b2010-10-29 23:50:21 +00004740 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004741
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004742 // Next, determine if we have a carry setting bit. We explicitly ignore all
4743 // the instructions we know end in 's'.
4744 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004745 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004746 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4747 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4748 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004749 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004750 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004751 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004752 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004753 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004754 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004755 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4756 CarrySetting = true;
4757 }
4758
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004759 // The "cps" instruction can have a interrupt mode operand which is glued into
4760 // the mnemonic. Check if this is the case, split it and parse the imod op
4761 if (Mnemonic.startswith("cps")) {
4762 // Split out any imod code.
4763 unsigned IMod =
4764 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4765 .Case("ie", ARM_PROC::IE)
4766 .Case("id", ARM_PROC::ID)
4767 .Default(~0U);
4768 if (IMod != ~0U) {
4769 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4770 ProcessorIMod = IMod;
4771 }
4772 }
4773
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004774 // The "it" instruction has the condition mask on the end of the mnemonic.
4775 if (Mnemonic.startswith("it")) {
4776 ITMask = Mnemonic.slice(2, Mnemonic.size());
4777 Mnemonic = Mnemonic.slice(0, 2);
4778 }
4779
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004780 return Mnemonic;
4781}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004782
4783/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4784/// inclusion of carry set or predication code operands.
4785//
4786// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004787void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004788getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4789 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004790 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4791 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004792 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004793 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004794 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004795 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004796 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004797 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004798 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004799 Mnemonic == "mla" || Mnemonic == "smlal" ||
4800 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004801 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004802 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004803 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004804
Tim Northover2c45a382013-06-26 16:52:40 +00004805 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4806 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004807 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004808 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4809 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004810 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4811 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004812 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4813 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4814 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004815 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004816 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004817 } else if (!isThumb()) {
4818 // Some instructions are only predicable in Thumb mode
4819 CanAcceptPredicationCode
4820 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4821 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4822 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4823 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4824 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4825 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4826 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4827 } else if (isThumbOne()) {
4828 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004829 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004830 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004831}
4832
Jim Grosbach7283da92011-08-16 21:12:37 +00004833bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4834 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004835 // FIXME: This is all horribly hacky. We really need a better way to deal
4836 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004837
4838 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4839 // another does not. Specifically, the MOVW instruction does not. So we
4840 // special case it here and remove the defaulted (non-setting) cc_out
4841 // operand if that's the instruction we're trying to match.
4842 //
4843 // We do this as post-processing of the explicit operands rather than just
4844 // conditionally adding the cc_out in the first place because we need
4845 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004846 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004847 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4848 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4849 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4850 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004851
4852 // Register-register 'add' for thumb does not have a cc_out operand
4853 // when there are only two register operands.
4854 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4855 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4857 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4858 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004859 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004860 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4861 // have to check the immediate range here since Thumb2 has a variant
4862 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004863 if (((isThumb() && Mnemonic == "add") ||
4864 (isThumbTwo() && Mnemonic == "sub")) &&
4865 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004866 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4867 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4868 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004869 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004870 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004871 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004872 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004873 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4874 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004875 // selecting via the generic "add" mnemonic, so to know that we
4876 // should remove the cc_out operand, we have to explicitly check that
4877 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004878 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4879 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004880 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4881 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4882 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4883 // Nest conditions rather than one big 'if' statement for readability.
4884 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004885 // If both registers are low, we're in an IT block, and the immediate is
4886 // in range, we should use encoding T1 instead, which has a cc_out.
4887 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004888 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004889 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4890 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4891 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004892 // Check against T3. If the second register is the PC, this is an
4893 // alternate form of ADR, which uses encoding T4, so check for that too.
4894 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4895 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4896 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004897
4898 // Otherwise, we use encoding T4, which does not have a cc_out
4899 // operand.
4900 return true;
4901 }
4902
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004903 // The thumb2 multiply instruction doesn't have a CCOut register, so
4904 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4905 // use the 16-bit encoding or not.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4911 // If the registers aren't low regs, the destination reg isn't the
4912 // same as one of the source regs, or the cc_out operand is zero
4913 // outside of an IT block, we have to use the 32-bit encoding, so
4914 // remove the cc_out operand.
4915 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4916 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004917 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004918 !inITBlock() ||
4919 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4920 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4921 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4922 static_cast<ARMOperand*>(Operands[4])->getReg())))
4923 return true;
4924
Jim Grosbachefa7e952011-11-15 19:55:16 +00004925 // Also check the 'mul' syntax variant that doesn't specify an explicit
4926 // destination register.
4927 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4928 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4929 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4930 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4931 // If the registers aren't low regs or the cc_out operand is zero
4932 // outside of an IT block, we have to use the 32-bit encoding, so
4933 // remove the cc_out operand.
4934 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4935 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4936 !inITBlock()))
4937 return true;
4938
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004939
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004940
Jim Grosbach4b701af2011-08-24 21:42:27 +00004941 // Register-register 'add/sub' for thumb does not have a cc_out operand
4942 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4943 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4944 // right, this will result in better diagnostics (which operand is off)
4945 // anyway.
4946 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4947 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004948 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4949 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004950 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4951 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4952 (Operands.size() == 6 &&
4953 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004954 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004955
Jim Grosbach7283da92011-08-16 21:12:37 +00004956 return false;
4957}
4958
Joey Goulye8602552013-07-19 16:34:16 +00004959bool ARMAsmParser::shouldOmitPredicateOperand(
4960 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4961 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4962 unsigned RegIdx = 3;
4963 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4964 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4965 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4966 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4967 RegIdx = 4;
4968
4969 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4970 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4971 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4972 ARMMCRegisterClasses[ARM::QPRRegClassID]
4973 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4974 return true;
4975 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004976 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004977}
4978
Jim Grosbach12952fe2011-11-11 23:08:10 +00004979static bool isDataTypeToken(StringRef Tok) {
4980 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4981 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4982 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4983 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4984 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4985 Tok == ".f" || Tok == ".d";
4986}
4987
4988// FIXME: This bit should probably be handled via an explicit match class
4989// in the .td files that matches the suffix instead of having it be
4990// a literal string token the way it is now.
4991static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4992 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4993}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004994static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4995 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004996/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004997bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4998 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004999 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005000 // Apply mnemonic aliases before doing anything else, as the destination
5001 // mnemnonic may include suffices and we want to handle them normally.
5002 // The generic tblgen'erated code does this later, at the start of
5003 // MatchInstructionImpl(), but that's too late for aliases that include
5004 // any sort of suffix.
5005 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005006 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5007 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005008
Jim Grosbachab5830e2011-12-14 02:16:11 +00005009 // First check for the ARM-specific .req directive.
5010 if (Parser.getTok().is(AsmToken::Identifier) &&
5011 Parser.getTok().getIdentifier() == ".req") {
5012 parseDirectiveReq(Name, NameLoc);
5013 // We always return 'error' for this, as we're done with this
5014 // statement and don't need to match the 'instruction."
5015 return true;
5016 }
5017
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005018 // Create the leading tokens for the mnemonic, split by '.' characters.
5019 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005020 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005021
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005022 // Split out the predication code and carry setting flag from the mnemonic.
5023 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005024 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005025 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005026 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005027 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005028 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005029
Jim Grosbach1c171b12011-08-25 17:23:55 +00005030 // In Thumb1, only the branch (B) instruction can be predicated.
5031 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005032 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005033 return Error(NameLoc, "conditional execution not supported in Thumb1");
5034 }
5035
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005036 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5037
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005038 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5039 // is the mask as it will be for the IT encoding if the conditional
5040 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5041 // where the conditional bit0 is zero, the instruction post-processing
5042 // will adjust the mask accordingly.
5043 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005044 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5045 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005046 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005047 return Error(Loc, "too many conditions on IT instruction");
5048 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005049 unsigned Mask = 8;
5050 for (unsigned i = ITMask.size(); i != 0; --i) {
5051 char pos = ITMask[i - 1];
5052 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005053 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005054 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005055 }
5056 Mask >>= 1;
5057 if (ITMask[i - 1] == 't')
5058 Mask |= 8;
5059 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005060 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005061 }
5062
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005063 // FIXME: This is all a pretty gross hack. We should automatically handle
5064 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005065
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005066 // Next, add the CCOut and ConditionCode operands, if needed.
5067 //
5068 // For mnemonics which can ever incorporate a carry setting bit or predication
5069 // code, our matching model involves us always generating CCOut and
5070 // ConditionCode operands to match the mnemonic "as written" and then we let
5071 // the matcher deal with finding the right instruction or generating an
5072 // appropriate error.
5073 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005074 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005075
Jim Grosbach03a8a162011-07-14 22:04:21 +00005076 // If we had a carry-set on an instruction that can't do that, issue an
5077 // error.
5078 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005079 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005080 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005081 "' can not set flags, but 's' suffix specified");
5082 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005083 // If we had a predication code on an instruction that can't do that, issue an
5084 // error.
5085 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005086 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005087 return Error(NameLoc, "instruction '" + Mnemonic +
5088 "' is not predicable, but condition code specified");
5089 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005090
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005091 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005092 if (CanAcceptCarrySet) {
5093 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005094 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005095 Loc));
5096 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005097
5098 // Add the predication code operand, if necessary.
5099 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005100 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5101 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005102 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005103 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005104 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005105
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005106 // Add the processor imod operand, if necessary.
5107 if (ProcessorIMod) {
5108 Operands.push_back(ARMOperand::CreateImm(
5109 MCConstantExpr::Create(ProcessorIMod, getContext()),
5110 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005111 }
5112
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005113 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005114 while (Next != StringRef::npos) {
5115 Start = Next;
5116 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005117 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005118
Jim Grosbach12952fe2011-11-11 23:08:10 +00005119 // Some NEON instructions have an optional datatype suffix that is
5120 // completely ignored. Check for that.
5121 if (isDataTypeToken(ExtraToken) &&
5122 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5123 continue;
5124
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005125 // For for ARM mode generate an error if the .n qualifier is used.
5126 if (ExtraToken == ".n" && !isThumb()) {
5127 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5128 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5129 "arm mode");
5130 }
5131
5132 // The .n qualifier is always discarded as that is what the tables
5133 // and matcher expect. In ARM mode the .w qualifier has no effect,
5134 // so discard it to avoid errors that can be caused by the matcher.
5135 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005136 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5137 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5138 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005139 }
5140
5141 // Read the remaining operands.
5142 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005143 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005144 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005145 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005146 return true;
5147 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005148
5149 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005150 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005151
5152 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005153 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005154 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005155 return true;
5156 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005157 }
5158 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005159
Chris Lattnera2a9d162010-09-11 16:18:25 +00005160 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005161 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005162 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005163 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005164 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005165
Chris Lattner91689c12010-09-08 05:10:46 +00005166 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005167
Jim Grosbach7283da92011-08-16 21:12:37 +00005168 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5169 // do and don't have a cc_out optional-def operand. With some spot-checks
5170 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005171 // parse and adjust accordingly before actually matching. We shouldn't ever
5172 // try to remove a cc_out operand that was explicitly set on the the
5173 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5174 // table driven matcher doesn't fit well with the ARM instruction set.
5175 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005176 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5177 Operands.erase(Operands.begin() + 1);
5178 delete Op;
5179 }
5180
Joey Goulye8602552013-07-19 16:34:16 +00005181 // Some instructions have the same mnemonic, but don't always
5182 // have a predicate. Distinguish them here and delete the
5183 // predicate if needed.
5184 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5185 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5186 Operands.erase(Operands.begin() + 1);
5187 delete Op;
5188 }
5189
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005190 // ARM mode 'blx' need special handling, as the register operand version
5191 // is predicable, but the label operand version is not. So, we can't rely
5192 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005193 // a k_CondCode operand in the list. If we're trying to match the label
5194 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005195 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5196 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5197 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5198 Operands.erase(Operands.begin() + 1);
5199 delete Op;
5200 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005201
Weiming Zhao8f56f882012-11-16 21:55:34 +00005202 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5203 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5204 // a single GPRPair reg operand is used in the .td file to replace the two
5205 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5206 // expressed as a GPRPair, so we have to manually merge them.
5207 // FIXME: We would really like to be able to tablegen'erate this.
5208 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005209 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5210 Mnemonic == "stlexd")) {
5211 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005212 unsigned Idx = isLoad ? 2 : 3;
5213 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5214 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5215
5216 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5217 // Adjust only if Op1 and Op2 are GPRs.
5218 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5219 MRC.contains(Op2->getReg())) {
5220 unsigned Reg1 = Op1->getReg();
5221 unsigned Reg2 = Op2->getReg();
5222 unsigned Rt = MRI->getEncodingValue(Reg1);
5223 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5224
5225 // Rt2 must be Rt + 1 and Rt must be even.
5226 if (Rt + 1 != Rt2 || (Rt & 1)) {
5227 Error(Op2->getStartLoc(), isLoad ?
5228 "destination operands must be sequential" :
5229 "source operands must be sequential");
5230 return true;
5231 }
5232 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5233 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5234 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5235 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5236 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5237 delete Op1;
5238 delete Op2;
5239 }
5240 }
5241
Kevin Enderby78f95722013-07-31 21:05:30 +00005242 // FIXME: As said above, this is all a pretty gross hack. This instruction
5243 // does not fit with other "subs" and tblgen.
5244 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5245 // so the Mnemonic is the original name "subs" and delete the predicate
5246 // operand so it will match the table entry.
5247 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5248 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5249 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5250 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5251 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5252 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5253 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5254 Operands.erase(Operands.begin());
5255 delete Op0;
5256 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5257
5258 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5259 Operands.erase(Operands.begin() + 1);
5260 delete Op1;
5261 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005262 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005263}
5264
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005265// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005266
5267// return 'true' if register list contains non-low GPR registers,
5268// 'false' otherwise. If Reg is in the register list or is HiReg, set
5269// 'containsReg' to true.
5270static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5271 unsigned HiReg, bool &containsReg) {
5272 containsReg = false;
5273 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5274 unsigned OpReg = Inst.getOperand(i).getReg();
5275 if (OpReg == Reg)
5276 containsReg = true;
5277 // Anything other than a low register isn't legal here.
5278 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5279 return true;
5280 }
5281 return false;
5282}
5283
Jim Grosbacha31f2232011-09-07 18:05:34 +00005284// Check if the specified regisgter is in the register list of the inst,
5285// starting at the indicated operand number.
5286static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5287 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5288 unsigned OpReg = Inst.getOperand(i).getReg();
5289 if (OpReg == Reg)
5290 return true;
5291 }
5292 return false;
5293}
5294
Richard Barton8d519fe2013-09-05 14:14:19 +00005295// Return true if instruction has the interesting property of being
5296// allowed in IT blocks, but not being predicable.
5297static bool instIsBreakpoint(const MCInst &Inst) {
5298 return Inst.getOpcode() == ARM::tBKPT ||
5299 Inst.getOpcode() == ARM::BKPT ||
5300 Inst.getOpcode() == ARM::tHLT ||
5301 Inst.getOpcode() == ARM::HLT;
5302
5303}
5304
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005305// FIXME: We would really like to be able to tablegen'erate this.
5306bool ARMAsmParser::
5307validateInstruction(MCInst &Inst,
5308 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005309 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005310 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005311
Jim Grosbached16ec42011-08-29 22:24:09 +00005312 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005313 // NOTE: BKPT and HLT instructions have the interesting property of being
5314 // allowed in IT blocks, but not being predicable. They just always
5315 // execute.
5316 if (inITBlock() && !instIsBreakpoint(Inst)) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005317 unsigned bit = 1;
5318 if (ITState.FirstCond)
5319 ITState.FirstCond = false;
5320 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005321 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005322 // The instruction must be predicable.
5323 if (!MCID.isPredicable())
5324 return Error(Loc, "instructions in IT block must be predicable");
5325 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5326 unsigned ITCond = bit ? ITState.Cond :
5327 ARMCC::getOppositeCondition(ITState.Cond);
5328 if (Cond != ITCond) {
5329 // Find the condition code Operand to get its SMLoc information.
5330 SMLoc CondLoc;
5331 for (unsigned i = 1; i < Operands.size(); ++i)
5332 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5333 CondLoc = Operands[i]->getStartLoc();
5334 return Error(CondLoc, "incorrect condition in IT block; got '" +
5335 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5336 "', but expected '" +
5337 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5338 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005339 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005340 } else if (isThumbTwo() && MCID.isPredicable() &&
5341 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005342 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5343 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005344 return Error(Loc, "predicated instructions must be in IT block");
5345
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005346 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005347 case ARM::LDRD:
5348 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005349 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005350 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005351 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5352 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005353 if (Rt2 != Rt + 1)
5354 return Error(Operands[3]->getStartLoc(),
5355 "destination operands must be sequential");
5356 return false;
5357 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005358 case ARM::STRD: {
5359 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005360 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5361 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005362 if (Rt2 != Rt + 1)
5363 return Error(Operands[3]->getStartLoc(),
5364 "source operands must be sequential");
5365 return false;
5366 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005367 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005368 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005369 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005370 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5371 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005372 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005373 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005374 "source operands must be sequential");
5375 return false;
5376 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005377 case ARM::SBFX:
5378 case ARM::UBFX: {
5379 // width must be in range [1, 32-lsb]
5380 unsigned lsb = Inst.getOperand(2).getImm();
5381 unsigned widthm1 = Inst.getOperand(3).getImm();
5382 if (widthm1 >= 32 - lsb)
5383 return Error(Operands[5]->getStartLoc(),
5384 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005385 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005386 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005387 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005388 // If we're parsing Thumb2, the .w variant is available and handles
5389 // most cases that are normally illegal for a Thumb1 LDM
5390 // instruction. We'll make the transformation in processInstruction()
5391 // if necessary.
5392 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005393 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005394 // in the register list.
5395 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005396 bool hasWritebackToken =
5397 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5398 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005399 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005400 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005401 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5402 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005403 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005404 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005405 return Error(Operands[2]->getStartLoc(),
5406 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005407 // If we should not have writeback, there must not be a '!'. This is
5408 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005409 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005410 return Error(Operands[3]->getStartLoc(),
5411 "writeback operator '!' not allowed when base register "
5412 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005413
5414 break;
5415 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005416 case ARM::t2LDMIA_UPD: {
5417 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5418 return Error(Operands[4]->getStartLoc(),
5419 "writeback operator '!' not allowed when base register "
5420 "in register list");
5421 break;
5422 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005423 case ARM::tMUL: {
5424 // The second source operand must be the same register as the destination
5425 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005426 //
5427 // In this case, we must directly check the parsed operands because the
5428 // cvtThumbMultiply() function is written in such a way that it guarantees
5429 // this first statement is always true for the new Inst. Essentially, the
5430 // destination is unconditionally copied into the second source operand
5431 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005432 if (Operands.size() == 6 &&
5433 (((ARMOperand*)Operands[3])->getReg() !=
5434 ((ARMOperand*)Operands[5])->getReg()) &&
5435 (((ARMOperand*)Operands[3])->getReg() !=
5436 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005437 return Error(Operands[3]->getStartLoc(),
5438 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005439 }
5440 break;
5441 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005442 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5443 // so only issue a diagnostic for thumb1. The instructions will be
5444 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005445 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005446 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005447 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5448 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005449 return Error(Operands[2]->getStartLoc(),
5450 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005451 break;
5452 }
5453 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005454 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005455 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5456 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005457 return Error(Operands[2]->getStartLoc(),
5458 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005459 break;
5460 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005461 case ARM::tSTMIA_UPD: {
5462 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005463 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005464 return Error(Operands[4]->getStartLoc(),
5465 "registers must be in range r0-r7");
5466 break;
5467 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005468 case ARM::tADDrSP: {
5469 // If the non-SP source operand and the destination operand are not the
5470 // same, we need thumb2 (for the wide encoding), or we have an error.
5471 if (!isThumbTwo() &&
5472 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5473 return Error(Operands[4]->getStartLoc(),
5474 "source register must be the same as destination");
5475 }
5476 break;
5477 }
Mihai Popaad18d3c2013-08-09 10:38:32 +00005478 // final range checking for Thumb unconditional branch instructions
5479 case ARM::tB:
5480 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5481 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5482 break;
5483 case ARM::t2B: {
5484 int op = (Operands[2]->isImm()) ? 2 : 3;
5485 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5486 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5487 break;
5488 }
5489 // final range checking for Thumb conditional branch instructions
5490 case ARM::tBcc:
5491 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5492 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5493 break;
5494 case ARM::t2Bcc: {
5495 int op = (Operands[2]->isImm()) ? 2 : 3;
5496 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<20, 1>())
5497 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5498 break;
5499 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005500 }
5501
5502 return false;
5503}
5504
Jim Grosbach1a747242012-01-23 23:45:44 +00005505static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005506 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005507 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005508 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005509 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5510 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5511 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5512 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5513 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5514 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5515 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5516 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5517 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005518
5519 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005520 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5521 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5522 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5523 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5524 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005525
Jim Grosbach1e946a42012-01-24 00:43:12 +00005526 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5527 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5528 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5529 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5530 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005531
Jim Grosbach1e946a42012-01-24 00:43:12 +00005532 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5533 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5534 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5535 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5536 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005537
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005538 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005539 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5540 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5541 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5542 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5543 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5544 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5545 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5546 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5547 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5548 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5549 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5550 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5551 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5552 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5553 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005554
Jim Grosbach1a747242012-01-23 23:45:44 +00005555 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005556 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5557 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5558 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5559 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5560 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5561 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5562 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5563 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5564 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5565 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5566 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5567 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5568 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5569 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5570 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5571 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5572 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5573 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005574
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005575 // VST4LN
5576 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5577 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5578 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5579 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5580 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5581 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5582 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5583 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5584 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5585 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5586 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5587 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5588 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5589 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5590 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5591
Jim Grosbachda70eac2012-01-24 00:58:13 +00005592 // VST4
5593 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5594 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5595 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5596 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5597 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5598 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5599 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5600 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5601 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5602 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5603 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5604 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5605 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5606 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5607 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5608 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5609 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5610 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005611 }
5612}
5613
Jim Grosbach1a747242012-01-23 23:45:44 +00005614static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005615 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005616 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005617 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005618 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5619 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5620 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5621 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5622 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5623 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5624 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5625 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5626 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005627
5628 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005629 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5630 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5631 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5632 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5633 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5634 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5635 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5636 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5637 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5638 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5639 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5640 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5641 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5642 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5643 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005644
Jim Grosbachb78403c2012-01-24 23:47:04 +00005645 // VLD3DUP
5646 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5647 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5648 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5649 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5650 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5651 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5652 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5653 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5654 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5655 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5656 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5657 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5658 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5659 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5660 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5661 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5662 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5663 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5664
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005665 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005666 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5667 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5668 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5669 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5670 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5671 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5672 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5673 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5674 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5675 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5676 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5677 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5678 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5679 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5680 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005681
5682 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005683 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5684 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5685 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5686 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5687 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5688 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5689 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5690 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5691 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5692 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5693 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5694 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5695 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5696 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5697 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5698 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5699 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5700 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005701
Jim Grosbach14952a02012-01-24 18:37:25 +00005702 // VLD4LN
5703 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5704 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5705 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5706 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5707 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5708 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5709 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5710 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5711 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5712 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5713 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5714 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5715 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5716 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5717 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5718
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005719 // VLD4DUP
5720 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5721 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5722 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5723 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5724 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5725 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5726 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5727 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5728 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5729 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5730 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5731 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5732 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5733 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5734 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5735 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5736 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5737 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5738
Jim Grosbached561fc2012-01-24 00:43:17 +00005739 // VLD4
5740 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5741 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5742 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5743 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5744 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5745 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5746 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5747 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5748 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5749 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5750 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5751 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5752 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5753 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5754 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5755 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5756 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5757 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005758 }
5759}
5760
Jim Grosbachafad0532011-11-10 23:42:14 +00005761bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005762processInstruction(MCInst &Inst,
5763 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5764 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005765 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5766 case ARM::ADDri: {
5767 if (Inst.getOperand(1).getReg() != ARM::PC ||
5768 Inst.getOperand(5).getReg() != 0)
5769 return false;
5770 MCInst TmpInst;
5771 TmpInst.setOpcode(ARM::ADR);
5772 TmpInst.addOperand(Inst.getOperand(0));
5773 TmpInst.addOperand(Inst.getOperand(2));
5774 TmpInst.addOperand(Inst.getOperand(3));
5775 TmpInst.addOperand(Inst.getOperand(4));
5776 Inst = TmpInst;
5777 return true;
5778 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005779 // Aliases for alternate PC+imm syntax of LDR instructions.
5780 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005781 // Select the narrow version if the immediate will fit.
5782 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005783 Inst.getOperand(1).getImm() <= 0xff &&
5784 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5785 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005786 Inst.setOpcode(ARM::tLDRpci);
5787 else
5788 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005789 return true;
5790 case ARM::t2LDRBpcrel:
5791 Inst.setOpcode(ARM::t2LDRBpci);
5792 return true;
5793 case ARM::t2LDRHpcrel:
5794 Inst.setOpcode(ARM::t2LDRHpci);
5795 return true;
5796 case ARM::t2LDRSBpcrel:
5797 Inst.setOpcode(ARM::t2LDRSBpci);
5798 return true;
5799 case ARM::t2LDRSHpcrel:
5800 Inst.setOpcode(ARM::t2LDRSHpci);
5801 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005802 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005803 case ARM::VST1LNdWB_register_Asm_8:
5804 case ARM::VST1LNdWB_register_Asm_16:
5805 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005806 MCInst TmpInst;
5807 // Shuffle the operands around so the lane index operand is in the
5808 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005809 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005810 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005811 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5812 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5813 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5814 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5815 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5816 TmpInst.addOperand(Inst.getOperand(1)); // lane
5817 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5818 TmpInst.addOperand(Inst.getOperand(6));
5819 Inst = TmpInst;
5820 return true;
5821 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005822
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005823 case ARM::VST2LNdWB_register_Asm_8:
5824 case ARM::VST2LNdWB_register_Asm_16:
5825 case ARM::VST2LNdWB_register_Asm_32:
5826 case ARM::VST2LNqWB_register_Asm_16:
5827 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005828 MCInst TmpInst;
5829 // Shuffle the operands around so the lane index operand is in the
5830 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005831 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005832 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005833 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5834 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5835 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5836 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5837 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5839 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005840 TmpInst.addOperand(Inst.getOperand(1)); // lane
5841 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5842 TmpInst.addOperand(Inst.getOperand(6));
5843 Inst = TmpInst;
5844 return true;
5845 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005846
5847 case ARM::VST3LNdWB_register_Asm_8:
5848 case ARM::VST3LNdWB_register_Asm_16:
5849 case ARM::VST3LNdWB_register_Asm_32:
5850 case ARM::VST3LNqWB_register_Asm_16:
5851 case ARM::VST3LNqWB_register_Asm_32: {
5852 MCInst TmpInst;
5853 // Shuffle the operands around so the lane index operand is in the
5854 // right place.
5855 unsigned Spacing;
5856 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5857 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5858 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5859 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5860 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5861 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5863 Spacing));
5864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5865 Spacing * 2));
5866 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 }
5872
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005873 case ARM::VST4LNdWB_register_Asm_8:
5874 case ARM::VST4LNdWB_register_Asm_16:
5875 case ARM::VST4LNdWB_register_Asm_32:
5876 case ARM::VST4LNqWB_register_Asm_16:
5877 case ARM::VST4LNqWB_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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5893 Spacing * 3));
5894 TmpInst.addOperand(Inst.getOperand(1)); // lane
5895 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5896 TmpInst.addOperand(Inst.getOperand(6));
5897 Inst = TmpInst;
5898 return true;
5899 }
5900
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005901 case ARM::VST1LNdWB_fixed_Asm_8:
5902 case ARM::VST1LNdWB_fixed_Asm_16:
5903 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005904 MCInst TmpInst;
5905 // Shuffle the operands around so the lane index operand is in the
5906 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005907 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005908 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005909 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5910 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5911 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5912 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5913 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5914 TmpInst.addOperand(Inst.getOperand(1)); // lane
5915 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5916 TmpInst.addOperand(Inst.getOperand(5));
5917 Inst = TmpInst;
5918 return true;
5919 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005920
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005921 case ARM::VST2LNdWB_fixed_Asm_8:
5922 case ARM::VST2LNdWB_fixed_Asm_16:
5923 case ARM::VST2LNdWB_fixed_Asm_32:
5924 case ARM::VST2LNqWB_fixed_Asm_16:
5925 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005926 MCInst TmpInst;
5927 // Shuffle the operands around so the lane index operand is in the
5928 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005929 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005930 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005931 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5932 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5933 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5934 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5935 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005936 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5937 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005938 TmpInst.addOperand(Inst.getOperand(1)); // lane
5939 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5940 TmpInst.addOperand(Inst.getOperand(5));
5941 Inst = TmpInst;
5942 return true;
5943 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005944
5945 case ARM::VST3LNdWB_fixed_Asm_8:
5946 case ARM::VST3LNdWB_fixed_Asm_16:
5947 case ARM::VST3LNdWB_fixed_Asm_32:
5948 case ARM::VST3LNqWB_fixed_Asm_16:
5949 case ARM::VST3LNqWB_fixed_Asm_32: {
5950 MCInst TmpInst;
5951 // Shuffle the operands around so the lane index operand is in the
5952 // right place.
5953 unsigned Spacing;
5954 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5955 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5956 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5957 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5958 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5959 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5960 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5961 Spacing));
5962 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5963 Spacing * 2));
5964 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 }
5970
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005971 case ARM::VST4LNdWB_fixed_Asm_8:
5972 case ARM::VST4LNdWB_fixed_Asm_16:
5973 case ARM::VST4LNdWB_fixed_Asm_32:
5974 case ARM::VST4LNqWB_fixed_Asm_16:
5975 case ARM::VST4LNqWB_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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5991 Spacing * 3));
5992 TmpInst.addOperand(Inst.getOperand(1)); // lane
5993 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5994 TmpInst.addOperand(Inst.getOperand(5));
5995 Inst = TmpInst;
5996 return true;
5997 }
5998
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005999 case ARM::VST1LNdAsm_8:
6000 case ARM::VST1LNdAsm_16:
6001 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006002 MCInst TmpInst;
6003 // Shuffle the operands around so the lane index operand is in the
6004 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006005 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006006 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006007 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6008 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6009 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6010 TmpInst.addOperand(Inst.getOperand(1)); // lane
6011 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6012 TmpInst.addOperand(Inst.getOperand(5));
6013 Inst = TmpInst;
6014 return true;
6015 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006016
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006017 case ARM::VST2LNdAsm_8:
6018 case ARM::VST2LNdAsm_16:
6019 case ARM::VST2LNdAsm_32:
6020 case ARM::VST2LNqAsm_16:
6021 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006022 MCInst TmpInst;
6023 // Shuffle the operands around so the lane index operand is in the
6024 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006025 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006026 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006027 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6028 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6029 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006030 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6031 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006032 TmpInst.addOperand(Inst.getOperand(1)); // lane
6033 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6034 TmpInst.addOperand(Inst.getOperand(5));
6035 Inst = TmpInst;
6036 return true;
6037 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006038
6039 case ARM::VST3LNdAsm_8:
6040 case ARM::VST3LNdAsm_16:
6041 case ARM::VST3LNdAsm_32:
6042 case ARM::VST3LNqAsm_16:
6043 case ARM::VST3LNqAsm_32: {
6044 MCInst TmpInst;
6045 // Shuffle the operands around so the lane index operand is in the
6046 // right place.
6047 unsigned Spacing;
6048 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6049 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6050 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6051 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6052 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6053 Spacing));
6054 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6055 Spacing * 2));
6056 TmpInst.addOperand(Inst.getOperand(1)); // lane
6057 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6058 TmpInst.addOperand(Inst.getOperand(5));
6059 Inst = TmpInst;
6060 return true;
6061 }
6062
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006063 case ARM::VST4LNdAsm_8:
6064 case ARM::VST4LNdAsm_16:
6065 case ARM::VST4LNdAsm_32:
6066 case ARM::VST4LNqAsm_16:
6067 case ARM::VST4LNqAsm_32: {
6068 MCInst TmpInst;
6069 // Shuffle the operands around so the lane index operand is in the
6070 // right place.
6071 unsigned Spacing;
6072 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6073 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6074 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6075 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6076 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 Spacing));
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 Spacing * 2));
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing * 3));
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 Grosbacha8aa30b2011-12-14 23:25:46 +00006089 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006090 case ARM::VLD1LNdWB_register_Asm_8:
6091 case ARM::VLD1LNdWB_register_Asm_16:
6092 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006093 MCInst TmpInst;
6094 // Shuffle the operands around so the lane index operand is in the
6095 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006096 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006097 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006098 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6099 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6100 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6101 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6102 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6103 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6104 TmpInst.addOperand(Inst.getOperand(1)); // lane
6105 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6106 TmpInst.addOperand(Inst.getOperand(6));
6107 Inst = TmpInst;
6108 return true;
6109 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006110
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006111 case ARM::VLD2LNdWB_register_Asm_8:
6112 case ARM::VLD2LNdWB_register_Asm_16:
6113 case ARM::VLD2LNdWB_register_Asm_32:
6114 case ARM::VLD2LNqWB_register_Asm_16:
6115 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006116 MCInst TmpInst;
6117 // Shuffle the operands around so the lane index operand is in the
6118 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006119 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006120 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006121 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6123 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006124 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6125 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6126 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6127 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6128 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006129 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6130 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006131 TmpInst.addOperand(Inst.getOperand(1)); // lane
6132 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6133 TmpInst.addOperand(Inst.getOperand(6));
6134 Inst = TmpInst;
6135 return true;
6136 }
6137
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006138 case ARM::VLD3LNdWB_register_Asm_8:
6139 case ARM::VLD3LNdWB_register_Asm_16:
6140 case ARM::VLD3LNdWB_register_Asm_32:
6141 case ARM::VLD3LNqWB_register_Asm_16:
6142 case ARM::VLD3LNqWB_register_Asm_32: {
6143 MCInst TmpInst;
6144 // Shuffle the operands around so the lane index operand is in the
6145 // right place.
6146 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006147 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006148 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6150 Spacing));
6151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006152 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006153 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6154 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6155 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6156 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6157 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6159 Spacing));
6160 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006161 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006162 TmpInst.addOperand(Inst.getOperand(1)); // lane
6163 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6164 TmpInst.addOperand(Inst.getOperand(6));
6165 Inst = TmpInst;
6166 return true;
6167 }
6168
Jim Grosbach14952a02012-01-24 18:37:25 +00006169 case ARM::VLD4LNdWB_register_Asm_8:
6170 case ARM::VLD4LNdWB_register_Asm_16:
6171 case ARM::VLD4LNdWB_register_Asm_32:
6172 case ARM::VLD4LNqWB_register_Asm_16:
6173 case ARM::VLD4LNqWB_register_Asm_32: {
6174 MCInst TmpInst;
6175 // Shuffle the operands around so the lane index operand is in the
6176 // right place.
6177 unsigned Spacing;
6178 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6179 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6181 Spacing));
6182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 Spacing * 2));
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 Spacing * 3));
6186 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6187 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6188 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6189 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6190 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6192 Spacing));
6193 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6194 Spacing * 2));
6195 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6196 Spacing * 3));
6197 TmpInst.addOperand(Inst.getOperand(1)); // lane
6198 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6199 TmpInst.addOperand(Inst.getOperand(6));
6200 Inst = TmpInst;
6201 return true;
6202 }
6203
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006204 case ARM::VLD1LNdWB_fixed_Asm_8:
6205 case ARM::VLD1LNdWB_fixed_Asm_16:
6206 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006207 MCInst TmpInst;
6208 // Shuffle the operands around so the lane index operand is in the
6209 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006210 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006211 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006212 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6213 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6217 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6218 TmpInst.addOperand(Inst.getOperand(1)); // lane
6219 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6220 TmpInst.addOperand(Inst.getOperand(5));
6221 Inst = TmpInst;
6222 return true;
6223 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006224
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006225 case ARM::VLD2LNdWB_fixed_Asm_8:
6226 case ARM::VLD2LNdWB_fixed_Asm_16:
6227 case ARM::VLD2LNdWB_fixed_Asm_32:
6228 case ARM::VLD2LNqWB_fixed_Asm_16:
6229 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006230 MCInst TmpInst;
6231 // Shuffle the operands around so the lane index operand is in the
6232 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006233 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006234 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006235 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6237 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006238 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6239 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6240 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6241 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6242 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006243 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6244 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006245 TmpInst.addOperand(Inst.getOperand(1)); // lane
6246 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6247 TmpInst.addOperand(Inst.getOperand(5));
6248 Inst = TmpInst;
6249 return true;
6250 }
6251
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006252 case ARM::VLD3LNdWB_fixed_Asm_8:
6253 case ARM::VLD3LNdWB_fixed_Asm_16:
6254 case ARM::VLD3LNdWB_fixed_Asm_32:
6255 case ARM::VLD3LNqWB_fixed_Asm_16:
6256 case ARM::VLD3LNqWB_fixed_Asm_32: {
6257 MCInst TmpInst;
6258 // Shuffle the operands around so the lane index operand is in the
6259 // right place.
6260 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006261 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006262 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 Spacing));
6265 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006266 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006267 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6268 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6269 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6270 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6271 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6272 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 Spacing));
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006275 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006276 TmpInst.addOperand(Inst.getOperand(1)); // lane
6277 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6278 TmpInst.addOperand(Inst.getOperand(5));
6279 Inst = TmpInst;
6280 return true;
6281 }
6282
Jim Grosbach14952a02012-01-24 18:37:25 +00006283 case ARM::VLD4LNdWB_fixed_Asm_8:
6284 case ARM::VLD4LNdWB_fixed_Asm_16:
6285 case ARM::VLD4LNdWB_fixed_Asm_32:
6286 case ARM::VLD4LNqWB_fixed_Asm_16:
6287 case ARM::VLD4LNqWB_fixed_Asm_32: {
6288 MCInst TmpInst;
6289 // Shuffle the operands around so the lane index operand is in the
6290 // right place.
6291 unsigned Spacing;
6292 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6293 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 Spacing));
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing * 2));
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing * 3));
6300 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6301 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6302 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6303 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6304 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 Spacing));
6307 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6308 Spacing * 2));
6309 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6310 Spacing * 3));
6311 TmpInst.addOperand(Inst.getOperand(1)); // lane
6312 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6313 TmpInst.addOperand(Inst.getOperand(5));
6314 Inst = TmpInst;
6315 return true;
6316 }
6317
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006318 case ARM::VLD1LNdAsm_8:
6319 case ARM::VLD1LNdAsm_16:
6320 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006321 MCInst TmpInst;
6322 // Shuffle the operands around so the lane index operand is in the
6323 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006324 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006325 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006326 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6327 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6329 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6330 TmpInst.addOperand(Inst.getOperand(1)); // lane
6331 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6332 TmpInst.addOperand(Inst.getOperand(5));
6333 Inst = TmpInst;
6334 return true;
6335 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006336
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006337 case ARM::VLD2LNdAsm_8:
6338 case ARM::VLD2LNdAsm_16:
6339 case ARM::VLD2LNdAsm_32:
6340 case ARM::VLD2LNqAsm_16:
6341 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006342 MCInst TmpInst;
6343 // Shuffle the operands around so the lane index operand is in the
6344 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006345 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006346 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006347 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006348 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6349 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006350 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6351 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6352 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006353 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6354 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006355 TmpInst.addOperand(Inst.getOperand(1)); // lane
6356 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6357 TmpInst.addOperand(Inst.getOperand(5));
6358 Inst = TmpInst;
6359 return true;
6360 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006361
6362 case ARM::VLD3LNdAsm_8:
6363 case ARM::VLD3LNdAsm_16:
6364 case ARM::VLD3LNdAsm_32:
6365 case ARM::VLD3LNqAsm_16:
6366 case ARM::VLD3LNqAsm_32: {
6367 MCInst TmpInst;
6368 // Shuffle the operands around so the lane index operand is in the
6369 // right place.
6370 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006371 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006372 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 Spacing));
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006376 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006377 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6378 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6379 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6380 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6381 Spacing));
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006383 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006384 TmpInst.addOperand(Inst.getOperand(1)); // lane
6385 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6386 TmpInst.addOperand(Inst.getOperand(5));
6387 Inst = TmpInst;
6388 return true;
6389 }
6390
Jim Grosbach14952a02012-01-24 18:37:25 +00006391 case ARM::VLD4LNdAsm_8:
6392 case ARM::VLD4LNdAsm_16:
6393 case ARM::VLD4LNdAsm_32:
6394 case ARM::VLD4LNqAsm_16:
6395 case ARM::VLD4LNqAsm_32: {
6396 MCInst TmpInst;
6397 // Shuffle the operands around so the lane index operand is in the
6398 // right place.
6399 unsigned Spacing;
6400 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6401 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing));
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing * 2));
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 Spacing * 3));
6408 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6410 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 Spacing));
6413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6414 Spacing * 2));
6415 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6416 Spacing * 3));
6417 TmpInst.addOperand(Inst.getOperand(1)); // lane
6418 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6419 TmpInst.addOperand(Inst.getOperand(5));
6420 Inst = TmpInst;
6421 return true;
6422 }
6423
Jim Grosbachb78403c2012-01-24 23:47:04 +00006424 // VLD3DUP single 3-element structure to all lanes instructions.
6425 case ARM::VLD3DUPdAsm_8:
6426 case ARM::VLD3DUPdAsm_16:
6427 case ARM::VLD3DUPdAsm_32:
6428 case ARM::VLD3DUPqAsm_8:
6429 case ARM::VLD3DUPqAsm_16:
6430 case ARM::VLD3DUPqAsm_32: {
6431 MCInst TmpInst;
6432 unsigned Spacing;
6433 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6434 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6436 Spacing));
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing * 2));
6439 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6441 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6442 TmpInst.addOperand(Inst.getOperand(4));
6443 Inst = TmpInst;
6444 return true;
6445 }
6446
6447 case ARM::VLD3DUPdWB_fixed_Asm_8:
6448 case ARM::VLD3DUPdWB_fixed_Asm_16:
6449 case ARM::VLD3DUPdWB_fixed_Asm_32:
6450 case ARM::VLD3DUPqWB_fixed_Asm_8:
6451 case ARM::VLD3DUPqWB_fixed_Asm_16:
6452 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6453 MCInst TmpInst;
6454 unsigned Spacing;
6455 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6456 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 Spacing));
6459 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6460 Spacing * 2));
6461 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6462 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6463 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6464 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6465 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6466 TmpInst.addOperand(Inst.getOperand(4));
6467 Inst = TmpInst;
6468 return true;
6469 }
6470
6471 case ARM::VLD3DUPdWB_register_Asm_8:
6472 case ARM::VLD3DUPdWB_register_Asm_16:
6473 case ARM::VLD3DUPdWB_register_Asm_32:
6474 case ARM::VLD3DUPqWB_register_Asm_8:
6475 case ARM::VLD3DUPqWB_register_Asm_16:
6476 case ARM::VLD3DUPqWB_register_Asm_32: {
6477 MCInst TmpInst;
6478 unsigned Spacing;
6479 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6480 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 Spacing));
6483 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6484 Spacing * 2));
6485 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6486 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6487 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6488 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6489 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6490 TmpInst.addOperand(Inst.getOperand(5));
6491 Inst = TmpInst;
6492 return true;
6493 }
6494
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006495 // VLD3 multiple 3-element structure instructions.
6496 case ARM::VLD3dAsm_8:
6497 case ARM::VLD3dAsm_16:
6498 case ARM::VLD3dAsm_32:
6499 case ARM::VLD3qAsm_8:
6500 case ARM::VLD3qAsm_16:
6501 case ARM::VLD3qAsm_32: {
6502 MCInst TmpInst;
6503 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006504 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006505 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 Spacing));
6508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6509 Spacing * 2));
6510 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6511 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6512 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6513 TmpInst.addOperand(Inst.getOperand(4));
6514 Inst = TmpInst;
6515 return true;
6516 }
6517
6518 case ARM::VLD3dWB_fixed_Asm_8:
6519 case ARM::VLD3dWB_fixed_Asm_16:
6520 case ARM::VLD3dWB_fixed_Asm_32:
6521 case ARM::VLD3qWB_fixed_Asm_8:
6522 case ARM::VLD3qWB_fixed_Asm_16:
6523 case ARM::VLD3qWB_fixed_Asm_32: {
6524 MCInst TmpInst;
6525 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006526 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006527 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing));
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing * 2));
6532 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6534 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6535 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6536 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6537 TmpInst.addOperand(Inst.getOperand(4));
6538 Inst = TmpInst;
6539 return true;
6540 }
6541
6542 case ARM::VLD3dWB_register_Asm_8:
6543 case ARM::VLD3dWB_register_Asm_16:
6544 case ARM::VLD3dWB_register_Asm_32:
6545 case ARM::VLD3qWB_register_Asm_8:
6546 case ARM::VLD3qWB_register_Asm_16:
6547 case ARM::VLD3qWB_register_Asm_32: {
6548 MCInst TmpInst;
6549 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006550 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006551 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 Spacing));
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing * 2));
6556 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6557 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6558 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6559 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6560 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6561 TmpInst.addOperand(Inst.getOperand(5));
6562 Inst = TmpInst;
6563 return true;
6564 }
6565
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006566 // VLD4DUP single 3-element structure to all lanes instructions.
6567 case ARM::VLD4DUPdAsm_8:
6568 case ARM::VLD4DUPdAsm_16:
6569 case ARM::VLD4DUPdAsm_32:
6570 case ARM::VLD4DUPqAsm_8:
6571 case ARM::VLD4DUPqAsm_16:
6572 case ARM::VLD4DUPqAsm_32: {
6573 MCInst TmpInst;
6574 unsigned Spacing;
6575 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6576 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 Spacing));
6579 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6580 Spacing * 2));
6581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 Spacing * 3));
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6586 TmpInst.addOperand(Inst.getOperand(4));
6587 Inst = TmpInst;
6588 return true;
6589 }
6590
6591 case ARM::VLD4DUPdWB_fixed_Asm_8:
6592 case ARM::VLD4DUPdWB_fixed_Asm_16:
6593 case ARM::VLD4DUPdWB_fixed_Asm_32:
6594 case ARM::VLD4DUPqWB_fixed_Asm_8:
6595 case ARM::VLD4DUPqWB_fixed_Asm_16:
6596 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6597 MCInst TmpInst;
6598 unsigned Spacing;
6599 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6600 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6602 Spacing));
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 Spacing * 2));
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing * 3));
6607 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6608 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6609 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6610 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
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_register_Asm_8:
6618 case ARM::VLD4DUPdWB_register_Asm_16:
6619 case ARM::VLD4DUPdWB_register_Asm_32:
6620 case ARM::VLD4DUPqWB_register_Asm_8:
6621 case ARM::VLD4DUPqWB_register_Asm_16:
6622 case ARM::VLD4DUPqWB_register_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(Inst.getOperand(3)); // Rm
6637 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(5));
6639 Inst = TmpInst;
6640 return true;
6641 }
6642
6643 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006644 case ARM::VLD4dAsm_8:
6645 case ARM::VLD4dAsm_16:
6646 case ARM::VLD4dAsm_32:
6647 case ARM::VLD4qAsm_8:
6648 case ARM::VLD4qAsm_16:
6649 case ARM::VLD4qAsm_32: {
6650 MCInst TmpInst;
6651 unsigned Spacing;
6652 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6653 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6654 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6655 Spacing));
6656 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 Spacing * 2));
6658 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 Spacing * 3));
6660 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6661 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6662 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6663 TmpInst.addOperand(Inst.getOperand(4));
6664 Inst = TmpInst;
6665 return true;
6666 }
6667
6668 case ARM::VLD4dWB_fixed_Asm_8:
6669 case ARM::VLD4dWB_fixed_Asm_16:
6670 case ARM::VLD4dWB_fixed_Asm_32:
6671 case ARM::VLD4qWB_fixed_Asm_8:
6672 case ARM::VLD4qWB_fixed_Asm_16:
6673 case ARM::VLD4qWB_fixed_Asm_32: {
6674 MCInst TmpInst;
6675 unsigned Spacing;
6676 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6677 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 Spacing));
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 Spacing * 2));
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 Spacing * 3));
6684 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6685 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6686 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6687 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
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_register_Asm_8:
6695 case ARM::VLD4dWB_register_Asm_16:
6696 case ARM::VLD4dWB_register_Asm_32:
6697 case ARM::VLD4qWB_register_Asm_8:
6698 case ARM::VLD4qWB_register_Asm_16:
6699 case ARM::VLD4qWB_register_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(Inst.getOperand(3)); // Rm
6714 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6715 TmpInst.addOperand(Inst.getOperand(5));
6716 Inst = TmpInst;
6717 return true;
6718 }
6719
Jim Grosbach1a747242012-01-23 23:45:44 +00006720 // VST3 multiple 3-element structure instructions.
6721 case ARM::VST3dAsm_8:
6722 case ARM::VST3dAsm_16:
6723 case ARM::VST3dAsm_32:
6724 case ARM::VST3qAsm_8:
6725 case ARM::VST3qAsm_16:
6726 case ARM::VST3qAsm_32: {
6727 MCInst TmpInst;
6728 unsigned Spacing;
6729 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6730 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6731 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6732 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 Spacing));
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 Spacing * 2));
6737 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6738 TmpInst.addOperand(Inst.getOperand(4));
6739 Inst = TmpInst;
6740 return true;
6741 }
6742
6743 case ARM::VST3dWB_fixed_Asm_8:
6744 case ARM::VST3dWB_fixed_Asm_16:
6745 case ARM::VST3dWB_fixed_Asm_32:
6746 case ARM::VST3qWB_fixed_Asm_8:
6747 case ARM::VST3qWB_fixed_Asm_16:
6748 case ARM::VST3qWB_fixed_Asm_32: {
6749 MCInst TmpInst;
6750 unsigned Spacing;
6751 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6752 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6753 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6754 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6755 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6756 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6758 Spacing));
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6760 Spacing * 2));
6761 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6762 TmpInst.addOperand(Inst.getOperand(4));
6763 Inst = TmpInst;
6764 return true;
6765 }
6766
6767 case ARM::VST3dWB_register_Asm_8:
6768 case ARM::VST3dWB_register_Asm_16:
6769 case ARM::VST3dWB_register_Asm_32:
6770 case ARM::VST3qWB_register_Asm_8:
6771 case ARM::VST3qWB_register_Asm_16:
6772 case ARM::VST3qWB_register_Asm_32: {
6773 MCInst TmpInst;
6774 unsigned Spacing;
6775 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6776 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6777 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6778 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6779 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6780 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6782 Spacing));
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6784 Spacing * 2));
6785 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6786 TmpInst.addOperand(Inst.getOperand(5));
6787 Inst = TmpInst;
6788 return true;
6789 }
6790
Jim Grosbachda70eac2012-01-24 00:58:13 +00006791 // VST4 multiple 3-element structure instructions.
6792 case ARM::VST4dAsm_8:
6793 case ARM::VST4dAsm_16:
6794 case ARM::VST4dAsm_32:
6795 case ARM::VST4qAsm_8:
6796 case ARM::VST4qAsm_16:
6797 case ARM::VST4qAsm_32: {
6798 MCInst TmpInst;
6799 unsigned Spacing;
6800 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6801 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6802 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6803 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6804 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6805 Spacing));
6806 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6807 Spacing * 2));
6808 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6809 Spacing * 3));
6810 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6811 TmpInst.addOperand(Inst.getOperand(4));
6812 Inst = TmpInst;
6813 return true;
6814 }
6815
6816 case ARM::VST4dWB_fixed_Asm_8:
6817 case ARM::VST4dWB_fixed_Asm_16:
6818 case ARM::VST4dWB_fixed_Asm_32:
6819 case ARM::VST4qWB_fixed_Asm_8:
6820 case ARM::VST4qWB_fixed_Asm_16:
6821 case ARM::VST4qWB_fixed_Asm_32: {
6822 MCInst TmpInst;
6823 unsigned Spacing;
6824 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6825 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6826 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6827 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6828 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
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_register_Asm_8:
6843 case ARM::VST4dWB_register_Asm_16:
6844 case ARM::VST4dWB_register_Asm_32:
6845 case ARM::VST4qWB_register_Asm_8:
6846 case ARM::VST4qWB_register_Asm_16:
6847 case ARM::VST4qWB_register_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(Inst.getOperand(3)); // 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(4)); // CondCode
6863 TmpInst.addOperand(Inst.getOperand(5));
6864 Inst = TmpInst;
6865 return true;
6866 }
6867
Jim Grosbachad66de12012-04-11 00:15:16 +00006868 // Handle encoding choice for the shift-immediate instructions.
6869 case ARM::t2LSLri:
6870 case ARM::t2LSRri:
6871 case ARM::t2ASRri: {
6872 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6873 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6874 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6875 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6876 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6877 unsigned NewOpc;
6878 switch (Inst.getOpcode()) {
6879 default: llvm_unreachable("unexpected opcode");
6880 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6881 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6882 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6883 }
6884 // The Thumb1 operands aren't in the same order. Awesome, eh?
6885 MCInst TmpInst;
6886 TmpInst.setOpcode(NewOpc);
6887 TmpInst.addOperand(Inst.getOperand(0));
6888 TmpInst.addOperand(Inst.getOperand(5));
6889 TmpInst.addOperand(Inst.getOperand(1));
6890 TmpInst.addOperand(Inst.getOperand(2));
6891 TmpInst.addOperand(Inst.getOperand(3));
6892 TmpInst.addOperand(Inst.getOperand(4));
6893 Inst = TmpInst;
6894 return true;
6895 }
6896 return false;
6897 }
6898
Jim Grosbach485e5622011-12-13 22:45:11 +00006899 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006900 case ARM::t2MOVsr:
6901 case ARM::t2MOVSsr: {
6902 // Which instruction to expand to depends on the CCOut operand and
6903 // whether we're in an IT block if the register operands are low
6904 // registers.
6905 bool isNarrow = false;
6906 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6907 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6908 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6909 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6910 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6911 isNarrow = true;
6912 MCInst TmpInst;
6913 unsigned newOpc;
6914 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6915 default: llvm_unreachable("unexpected opcode!");
6916 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6917 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6918 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6919 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6920 }
6921 TmpInst.setOpcode(newOpc);
6922 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6923 if (isNarrow)
6924 TmpInst.addOperand(MCOperand::CreateReg(
6925 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6926 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6927 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6928 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6929 TmpInst.addOperand(Inst.getOperand(5));
6930 if (!isNarrow)
6931 TmpInst.addOperand(MCOperand::CreateReg(
6932 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6933 Inst = TmpInst;
6934 return true;
6935 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006936 case ARM::t2MOVsi:
6937 case ARM::t2MOVSsi: {
6938 // Which instruction to expand to depends on the CCOut operand and
6939 // whether we're in an IT block if the register operands are low
6940 // registers.
6941 bool isNarrow = false;
6942 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6943 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6944 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6945 isNarrow = true;
6946 MCInst TmpInst;
6947 unsigned newOpc;
6948 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6949 default: llvm_unreachable("unexpected opcode!");
6950 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6951 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6952 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6953 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006954 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006955 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006956 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6957 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006958 TmpInst.setOpcode(newOpc);
6959 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6960 if (isNarrow)
6961 TmpInst.addOperand(MCOperand::CreateReg(
6962 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6963 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006964 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006965 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006966 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6967 TmpInst.addOperand(Inst.getOperand(4));
6968 if (!isNarrow)
6969 TmpInst.addOperand(MCOperand::CreateReg(
6970 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6971 Inst = TmpInst;
6972 return true;
6973 }
6974 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006975 case ARM::ASRr:
6976 case ARM::LSRr:
6977 case ARM::LSLr:
6978 case ARM::RORr: {
6979 ARM_AM::ShiftOpc ShiftTy;
6980 switch(Inst.getOpcode()) {
6981 default: llvm_unreachable("unexpected opcode!");
6982 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6983 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6984 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6985 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6986 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006987 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6988 MCInst TmpInst;
6989 TmpInst.setOpcode(ARM::MOVsr);
6990 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6991 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6992 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6993 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6994 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6995 TmpInst.addOperand(Inst.getOperand(4));
6996 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6997 Inst = TmpInst;
6998 return true;
6999 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007000 case ARM::ASRi:
7001 case ARM::LSRi:
7002 case ARM::LSLi:
7003 case ARM::RORi: {
7004 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007005 switch(Inst.getOpcode()) {
7006 default: llvm_unreachable("unexpected opcode!");
7007 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7008 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7009 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7010 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7011 }
7012 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007013 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007014 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007015 // A shift by 32 should be encoded as 0 when permitted
7016 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7017 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007018 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007019 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007020 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007021 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7022 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007023 if (Opc == ARM::MOVsi)
7024 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007025 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7026 TmpInst.addOperand(Inst.getOperand(4));
7027 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7028 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007029 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007030 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007031 case ARM::RRXi: {
7032 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7033 MCInst TmpInst;
7034 TmpInst.setOpcode(ARM::MOVsi);
7035 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7036 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7037 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7038 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7039 TmpInst.addOperand(Inst.getOperand(3));
7040 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7041 Inst = TmpInst;
7042 return true;
7043 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007044 case ARM::t2LDMIA_UPD: {
7045 // If this is a load of a single register, then we should use
7046 // a post-indexed LDR instruction instead, per the ARM ARM.
7047 if (Inst.getNumOperands() != 5)
7048 return false;
7049 MCInst TmpInst;
7050 TmpInst.setOpcode(ARM::t2LDR_POST);
7051 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7052 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7053 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7054 TmpInst.addOperand(MCOperand::CreateImm(4));
7055 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7056 TmpInst.addOperand(Inst.getOperand(3));
7057 Inst = TmpInst;
7058 return true;
7059 }
7060 case ARM::t2STMDB_UPD: {
7061 // If this is a store of a single register, then we should use
7062 // a pre-indexed STR instruction instead, per the ARM ARM.
7063 if (Inst.getNumOperands() != 5)
7064 return false;
7065 MCInst TmpInst;
7066 TmpInst.setOpcode(ARM::t2STR_PRE);
7067 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7068 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7069 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7070 TmpInst.addOperand(MCOperand::CreateImm(-4));
7071 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7072 TmpInst.addOperand(Inst.getOperand(3));
7073 Inst = TmpInst;
7074 return true;
7075 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007076 case ARM::LDMIA_UPD:
7077 // If this is a load of a single register via a 'pop', then we should use
7078 // a post-indexed LDR instruction instead, per the ARM ARM.
7079 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7080 Inst.getNumOperands() == 5) {
7081 MCInst TmpInst;
7082 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7083 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7084 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7085 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7086 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7087 TmpInst.addOperand(MCOperand::CreateImm(4));
7088 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7089 TmpInst.addOperand(Inst.getOperand(3));
7090 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007091 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007092 }
7093 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007094 case ARM::STMDB_UPD:
7095 // If this is a store of a single register via a 'push', then we should use
7096 // a pre-indexed STR instruction instead, per the ARM ARM.
7097 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7098 Inst.getNumOperands() == 5) {
7099 MCInst TmpInst;
7100 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7101 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7102 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7103 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7104 TmpInst.addOperand(MCOperand::CreateImm(-4));
7105 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7106 TmpInst.addOperand(Inst.getOperand(3));
7107 Inst = TmpInst;
7108 }
7109 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007110 case ARM::t2ADDri12:
7111 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7112 // mnemonic was used (not "addw"), encoding T3 is preferred.
7113 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7114 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7115 break;
7116 Inst.setOpcode(ARM::t2ADDri);
7117 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7118 break;
7119 case ARM::t2SUBri12:
7120 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7121 // mnemonic was used (not "subw"), encoding T3 is preferred.
7122 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7123 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7124 break;
7125 Inst.setOpcode(ARM::t2SUBri);
7126 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7127 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007128 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007129 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007130 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7131 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7132 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007133 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007134 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007135 return true;
7136 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007137 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007138 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007139 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007140 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7141 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7142 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007143 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007144 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007145 return true;
7146 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007147 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007148 case ARM::t2ADDri:
7149 case ARM::t2SUBri: {
7150 // If the destination and first source operand are the same, and
7151 // the flags are compatible with the current IT status, use encoding T2
7152 // instead of T3. For compatibility with the system 'as'. Make sure the
7153 // wide encoding wasn't explicit.
7154 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007155 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007156 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7157 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7158 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7159 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7160 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7161 break;
7162 MCInst TmpInst;
7163 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7164 ARM::tADDi8 : ARM::tSUBi8);
7165 TmpInst.addOperand(Inst.getOperand(0));
7166 TmpInst.addOperand(Inst.getOperand(5));
7167 TmpInst.addOperand(Inst.getOperand(0));
7168 TmpInst.addOperand(Inst.getOperand(2));
7169 TmpInst.addOperand(Inst.getOperand(3));
7170 TmpInst.addOperand(Inst.getOperand(4));
7171 Inst = TmpInst;
7172 return true;
7173 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007174 case ARM::t2ADDrr: {
7175 // If the destination and first source operand are the same, and
7176 // there's no setting of the flags, use encoding T2 instead of T3.
7177 // Note that this is only for ADD, not SUB. This mirrors the system
7178 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7179 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7180 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007181 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7182 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007183 break;
7184 MCInst TmpInst;
7185 TmpInst.setOpcode(ARM::tADDhirr);
7186 TmpInst.addOperand(Inst.getOperand(0));
7187 TmpInst.addOperand(Inst.getOperand(0));
7188 TmpInst.addOperand(Inst.getOperand(2));
7189 TmpInst.addOperand(Inst.getOperand(3));
7190 TmpInst.addOperand(Inst.getOperand(4));
7191 Inst = TmpInst;
7192 return true;
7193 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007194 case ARM::tADDrSP: {
7195 // If the non-SP source operand and the destination operand are not the
7196 // same, we need to use the 32-bit encoding if it's available.
7197 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7198 Inst.setOpcode(ARM::t2ADDrr);
7199 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7200 return true;
7201 }
7202 break;
7203 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007204 case ARM::tB:
7205 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007206 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007207 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007208 return true;
7209 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007210 break;
7211 case ARM::t2B:
7212 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007213 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007214 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007215 return true;
7216 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007217 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007218 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007219 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007220 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007221 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007222 return true;
7223 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007224 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007225 case ARM::tBcc:
7226 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007227 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007228 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007229 return true;
7230 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007231 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007232 case ARM::tLDMIA: {
7233 // If the register list contains any high registers, or if the writeback
7234 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7235 // instead if we're in Thumb2. Otherwise, this should have generated
7236 // an error in validateInstruction().
7237 unsigned Rn = Inst.getOperand(0).getReg();
7238 bool hasWritebackToken =
7239 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7240 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7241 bool listContainsBase;
7242 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7243 (!listContainsBase && !hasWritebackToken) ||
7244 (listContainsBase && hasWritebackToken)) {
7245 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7246 assert (isThumbTwo());
7247 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7248 // If we're switching to the updating version, we need to insert
7249 // the writeback tied operand.
7250 if (hasWritebackToken)
7251 Inst.insert(Inst.begin(),
7252 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007253 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007254 }
7255 break;
7256 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007257 case ARM::tSTMIA_UPD: {
7258 // If the register list contains any high registers, we need to use
7259 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7260 // should have generated an error in validateInstruction().
7261 unsigned Rn = Inst.getOperand(0).getReg();
7262 bool listContainsBase;
7263 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7264 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7265 assert (isThumbTwo());
7266 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007267 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007268 }
7269 break;
7270 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007271 case ARM::tPOP: {
7272 bool listContainsBase;
7273 // If the register list contains any high registers, we need to use
7274 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7275 // should have generated an error in validateInstruction().
7276 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007277 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007278 assert (isThumbTwo());
7279 Inst.setOpcode(ARM::t2LDMIA_UPD);
7280 // Add the base register and writeback operands.
7281 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7282 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007283 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007284 }
7285 case ARM::tPUSH: {
7286 bool listContainsBase;
7287 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007288 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007289 assert (isThumbTwo());
7290 Inst.setOpcode(ARM::t2STMDB_UPD);
7291 // Add the base register and writeback operands.
7292 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7293 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007294 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007295 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007296 case ARM::t2MOVi: {
7297 // If we can use the 16-bit encoding and the user didn't explicitly
7298 // request the 32-bit variant, transform it here.
7299 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007300 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007301 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7302 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7303 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007304 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7305 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7306 // The operands aren't in the same order for tMOVi8...
7307 MCInst TmpInst;
7308 TmpInst.setOpcode(ARM::tMOVi8);
7309 TmpInst.addOperand(Inst.getOperand(0));
7310 TmpInst.addOperand(Inst.getOperand(4));
7311 TmpInst.addOperand(Inst.getOperand(1));
7312 TmpInst.addOperand(Inst.getOperand(2));
7313 TmpInst.addOperand(Inst.getOperand(3));
7314 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007315 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007316 }
7317 break;
7318 }
7319 case ARM::t2MOVr: {
7320 // If we can use the 16-bit encoding and the user didn't explicitly
7321 // request the 32-bit variant, transform it here.
7322 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7323 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7324 Inst.getOperand(2).getImm() == ARMCC::AL &&
7325 Inst.getOperand(4).getReg() == ARM::CPSR &&
7326 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7327 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7328 // The operands aren't the same for tMOV[S]r... (no cc_out)
7329 MCInst TmpInst;
7330 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7331 TmpInst.addOperand(Inst.getOperand(0));
7332 TmpInst.addOperand(Inst.getOperand(1));
7333 TmpInst.addOperand(Inst.getOperand(2));
7334 TmpInst.addOperand(Inst.getOperand(3));
7335 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007336 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007337 }
7338 break;
7339 }
Jim Grosbach82213192011-09-19 20:29:33 +00007340 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007341 case ARM::t2SXTB:
7342 case ARM::t2UXTH:
7343 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007344 // If we can use the 16-bit encoding and the user didn't explicitly
7345 // request the 32-bit variant, transform it here.
7346 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7347 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7348 Inst.getOperand(2).getImm() == 0 &&
7349 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7350 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007351 unsigned NewOpc;
7352 switch (Inst.getOpcode()) {
7353 default: llvm_unreachable("Illegal opcode!");
7354 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7355 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7356 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7357 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7358 }
Jim Grosbach82213192011-09-19 20:29:33 +00007359 // The operands aren't the same for thumb1 (no rotate operand).
7360 MCInst TmpInst;
7361 TmpInst.setOpcode(NewOpc);
7362 TmpInst.addOperand(Inst.getOperand(0));
7363 TmpInst.addOperand(Inst.getOperand(1));
7364 TmpInst.addOperand(Inst.getOperand(3));
7365 TmpInst.addOperand(Inst.getOperand(4));
7366 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007367 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007368 }
7369 break;
7370 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007371 case ARM::MOVsi: {
7372 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007373 // rrx shifts and asr/lsr of #32 is encoded as 0
7374 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7375 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007376 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7377 // Shifting by zero is accepted as a vanilla 'MOVr'
7378 MCInst TmpInst;
7379 TmpInst.setOpcode(ARM::MOVr);
7380 TmpInst.addOperand(Inst.getOperand(0));
7381 TmpInst.addOperand(Inst.getOperand(1));
7382 TmpInst.addOperand(Inst.getOperand(3));
7383 TmpInst.addOperand(Inst.getOperand(4));
7384 TmpInst.addOperand(Inst.getOperand(5));
7385 Inst = TmpInst;
7386 return true;
7387 }
7388 return false;
7389 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007390 case ARM::ANDrsi:
7391 case ARM::ORRrsi:
7392 case ARM::EORrsi:
7393 case ARM::BICrsi:
7394 case ARM::SUBrsi:
7395 case ARM::ADDrsi: {
7396 unsigned newOpc;
7397 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7398 if (SOpc == ARM_AM::rrx) return false;
7399 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007400 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007401 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7402 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7403 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7404 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7405 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7406 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7407 }
7408 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007409 // The exception is for right shifts, where 0 == 32
7410 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7411 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007412 MCInst TmpInst;
7413 TmpInst.setOpcode(newOpc);
7414 TmpInst.addOperand(Inst.getOperand(0));
7415 TmpInst.addOperand(Inst.getOperand(1));
7416 TmpInst.addOperand(Inst.getOperand(2));
7417 TmpInst.addOperand(Inst.getOperand(4));
7418 TmpInst.addOperand(Inst.getOperand(5));
7419 TmpInst.addOperand(Inst.getOperand(6));
7420 Inst = TmpInst;
7421 return true;
7422 }
7423 return false;
7424 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007425 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007426 case ARM::t2IT: {
7427 // The mask bits for all but the first condition are represented as
7428 // the low bit of the condition code value implies 't'. We currently
7429 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007430 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007431 MCOperand &MO = Inst.getOperand(1);
7432 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007433 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007434 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007435 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007436 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007437 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007438 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007439 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007440
7441 // Set up the IT block state according to the IT instruction we just
7442 // matched.
7443 assert(!inITBlock() && "nested IT blocks?!");
7444 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7445 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7446 ITState.CurPosition = 0;
7447 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007448 break;
7449 }
Richard Bartona39625e2012-07-09 16:12:24 +00007450 case ARM::t2LSLrr:
7451 case ARM::t2LSRrr:
7452 case ARM::t2ASRrr:
7453 case ARM::t2SBCrr:
7454 case ARM::t2RORrr:
7455 case ARM::t2BICrr:
7456 {
Richard Bartond5660372012-07-09 16:14:28 +00007457 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007458 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7459 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7460 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007461 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7462 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007463 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7464 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7465 unsigned NewOpc;
7466 switch (Inst.getOpcode()) {
7467 default: llvm_unreachable("unexpected opcode");
7468 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7469 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7470 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7471 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7472 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7473 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7474 }
7475 MCInst TmpInst;
7476 TmpInst.setOpcode(NewOpc);
7477 TmpInst.addOperand(Inst.getOperand(0));
7478 TmpInst.addOperand(Inst.getOperand(5));
7479 TmpInst.addOperand(Inst.getOperand(1));
7480 TmpInst.addOperand(Inst.getOperand(2));
7481 TmpInst.addOperand(Inst.getOperand(3));
7482 TmpInst.addOperand(Inst.getOperand(4));
7483 Inst = TmpInst;
7484 return true;
7485 }
7486 return false;
7487 }
7488 case ARM::t2ANDrr:
7489 case ARM::t2EORrr:
7490 case ARM::t2ADCrr:
7491 case ARM::t2ORRrr:
7492 {
Richard Bartond5660372012-07-09 16:14:28 +00007493 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007494 // These instructions are special in that they are commutable, so shorter encodings
7495 // are available more often.
7496 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7497 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7498 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7499 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007500 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7501 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007502 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7503 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7504 unsigned NewOpc;
7505 switch (Inst.getOpcode()) {
7506 default: llvm_unreachable("unexpected opcode");
7507 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7508 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7509 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7510 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7511 }
7512 MCInst TmpInst;
7513 TmpInst.setOpcode(NewOpc);
7514 TmpInst.addOperand(Inst.getOperand(0));
7515 TmpInst.addOperand(Inst.getOperand(5));
7516 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7517 TmpInst.addOperand(Inst.getOperand(1));
7518 TmpInst.addOperand(Inst.getOperand(2));
7519 } else {
7520 TmpInst.addOperand(Inst.getOperand(2));
7521 TmpInst.addOperand(Inst.getOperand(1));
7522 }
7523 TmpInst.addOperand(Inst.getOperand(3));
7524 TmpInst.addOperand(Inst.getOperand(4));
7525 Inst = TmpInst;
7526 return true;
7527 }
7528 return false;
7529 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007530 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007531 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007532}
7533
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007534unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7535 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7536 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007537 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007538 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007539 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7540 assert(MCID.hasOptionalDef() &&
7541 "optionally flag setting instruction missing optional def operand");
7542 assert(MCID.NumOperands == Inst.getNumOperands() &&
7543 "operand count mismatch!");
7544 // Find the optional-def operand (cc_out).
7545 unsigned OpNo;
7546 for (OpNo = 0;
7547 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7548 ++OpNo)
7549 ;
7550 // If we're parsing Thumb1, reject it completely.
7551 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7552 return Match_MnemonicFail;
7553 // If we're parsing Thumb2, which form is legal depends on whether we're
7554 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007555 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7556 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007557 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007558 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7559 inITBlock())
7560 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007561 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007562 // Some high-register supporting Thumb1 encodings only allow both registers
7563 // to be from r0-r7 when in Thumb2.
7564 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7565 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7566 isARMLowRegister(Inst.getOperand(2).getReg()))
7567 return Match_RequiresThumb2;
7568 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007569 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007570 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7571 isARMLowRegister(Inst.getOperand(1).getReg()))
7572 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007573 return Match_Success;
7574}
7575
Jim Grosbach5117ef72012-04-24 22:40:08 +00007576static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007577bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007578MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007579 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007580 MCStreamer &Out, unsigned &ErrorInfo,
7581 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007582 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007583 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007584
Chad Rosier2f480a82012-10-12 22:53:36 +00007585 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007586 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007587 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007588 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007589 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007590 // Context sensitive operand constraints aren't handled by the matcher,
7591 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007592 if (validateInstruction(Inst, Operands)) {
7593 // Still progress the IT block, otherwise one wrong condition causes
7594 // nasty cascading errors.
7595 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007596 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007597 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007598
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007599 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007600 // encoding is selected. Loop on it while changes happen so the
7601 // individual transformations can chain off each other. E.g.,
7602 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7603 while (processInstruction(Inst, Operands))
7604 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007605
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007606 // Only move forward at the very end so that everything in validate
7607 // and process gets a consistent answer about whether we're in an IT
7608 // block.
7609 forwardITPosition();
7610
Jim Grosbach82f76d12012-01-25 19:52:01 +00007611 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7612 // doesn't actually encode.
7613 if (Inst.getOpcode() == ARM::ITasm)
7614 return false;
7615
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007616 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007617 Out.EmitInstruction(Inst);
7618 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007619 case Match_MissingFeature: {
7620 assert(ErrorInfo && "Unknown missing feature!");
7621 // Special case the error message for the very common case where only
7622 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7623 std::string Msg = "instruction requires:";
7624 unsigned Mask = 1;
7625 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7626 if (ErrorInfo & Mask) {
7627 Msg += " ";
7628 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7629 }
7630 Mask <<= 1;
7631 }
7632 return Error(IDLoc, Msg);
7633 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007634 case Match_InvalidOperand: {
7635 SMLoc ErrorLoc = IDLoc;
7636 if (ErrorInfo != ~0U) {
7637 if (ErrorInfo >= Operands.size())
7638 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007639
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007640 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7641 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7642 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007643
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007644 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007645 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007646 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007647 return Error(IDLoc, "invalid instruction",
7648 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007649 case Match_RequiresNotITBlock:
7650 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007651 case Match_RequiresITBlock:
7652 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007653 case Match_RequiresV6:
7654 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7655 case Match_RequiresThumb2:
7656 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007657 case Match_ImmRange0_4: {
7658 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7659 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7660 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7661 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007662 case Match_ImmRange0_15: {
7663 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7664 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7665 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7666 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007667 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007668
Eric Christopher91d7b902010-10-29 09:26:59 +00007669 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007670}
7671
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007672/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007673bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7674 StringRef IDVal = DirectiveID.getIdentifier();
7675 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007676 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007677 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007678 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007679 else if (IDVal == ".arm")
7680 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007681 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007682 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007683 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007684 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007685 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007686 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007687 else if (IDVal == ".unreq")
7688 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007689 else if (IDVal == ".arch")
7690 return parseDirectiveArch(DirectiveID.getLoc());
7691 else if (IDVal == ".eabi_attribute")
7692 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007693 else if (IDVal == ".fnstart")
7694 return parseDirectiveFnStart(DirectiveID.getLoc());
7695 else if (IDVal == ".fnend")
7696 return parseDirectiveFnEnd(DirectiveID.getLoc());
7697 else if (IDVal == ".cantunwind")
7698 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7699 else if (IDVal == ".personality")
7700 return parseDirectivePersonality(DirectiveID.getLoc());
7701 else if (IDVal == ".handlerdata")
7702 return parseDirectiveHandlerData(DirectiveID.getLoc());
7703 else if (IDVal == ".setfp")
7704 return parseDirectiveSetFP(DirectiveID.getLoc());
7705 else if (IDVal == ".pad")
7706 return parseDirectivePad(DirectiveID.getLoc());
7707 else if (IDVal == ".save")
7708 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7709 else if (IDVal == ".vsave")
7710 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007711 return true;
7712}
7713
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007714/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007715/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007716bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007717 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7718 for (;;) {
7719 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007720 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007721 return true;
7722
Eric Christopherbf7bc492013-01-09 03:52:05 +00007723 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007724
7725 if (getLexer().is(AsmToken::EndOfStatement))
7726 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007727
Kevin Enderbyccab3172009-09-15 00:27:25 +00007728 // FIXME: Improve diagnostic.
7729 if (getLexer().isNot(AsmToken::Comma))
7730 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007731 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007732 }
7733 }
7734
Sean Callanana83fd7d2010-01-19 20:27:46 +00007735 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007736 return false;
7737}
7738
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007739/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007740/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007741bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007742 if (getLexer().isNot(AsmToken::EndOfStatement))
7743 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007744 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007745
Tim Northovera2292d02013-06-10 23:20:58 +00007746 if (!hasThumb())
7747 return Error(L, "target does not support Thumb mode");
7748
Jim Grosbach7f882392011-12-07 18:04:19 +00007749 if (!isThumb())
7750 SwitchMode();
7751 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7752 return false;
7753}
7754
7755/// parseDirectiveARM
7756/// ::= .arm
7757bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7758 if (getLexer().isNot(AsmToken::EndOfStatement))
7759 return Error(L, "unexpected token in directive");
7760 Parser.Lex();
7761
Tim Northovera2292d02013-06-10 23:20:58 +00007762 if (!hasARM())
7763 return Error(L, "target does not support ARM mode");
7764
Jim Grosbach7f882392011-12-07 18:04:19 +00007765 if (isThumb())
7766 SwitchMode();
7767 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007768 return false;
7769}
7770
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007771/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007772/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007773bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007774 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7775 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007776 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007777 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007778
Jim Grosbach1152cc02011-12-21 22:30:16 +00007779 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007780 // ELF doesn't
7781 if (isMachO) {
7782 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007783 if (Tok.isNot(AsmToken::EndOfStatement)) {
7784 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7785 return Error(L, "unexpected token in .thumb_func directive");
7786 Name = Tok.getIdentifier();
7787 Parser.Lex(); // Consume the identifier token.
7788 needFuncName = false;
7789 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007790 }
7791
Jim Grosbach1152cc02011-12-21 22:30:16 +00007792 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007793 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007794
7795 // Eat the end of statement and any blank lines that follow.
7796 while (getLexer().is(AsmToken::EndOfStatement))
7797 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007798
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007799 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007800 // We really should be checking the next symbol definition even if there's
7801 // stuff in between.
7802 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007803 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007804 }
7805
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007806 // Mark symbol as a thumb symbol.
7807 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7808 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007809 return false;
7810}
7811
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007812/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007813/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007814bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007815 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007816 if (Tok.isNot(AsmToken::Identifier))
7817 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007818 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007819 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007820 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007821 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007822 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007823 else
7824 return Error(L, "unrecognized syntax mode in .syntax directive");
7825
7826 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007827 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007828 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007829
7830 // TODO tell the MC streamer the mode
7831 // getParser().getStreamer().Emit???();
7832 return false;
7833}
7834
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007835/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007836/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007837bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007838 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007839 if (Tok.isNot(AsmToken::Integer))
7840 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007841 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007842 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007843 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007844 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007845 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007846 else
7847 return Error(L, "invalid operand to .code directive");
7848
7849 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007850 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007851 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007852
Evan Cheng284b4672011-07-08 22:36:29 +00007853 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007854 if (!hasThumb())
7855 return Error(L, "target does not support Thumb mode");
7856
Jim Grosbachf471ac32011-09-06 18:46:23 +00007857 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007858 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007859 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007860 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007861 if (!hasARM())
7862 return Error(L, "target does not support ARM mode");
7863
Jim Grosbachf471ac32011-09-06 18:46:23 +00007864 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007865 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007866 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007867 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007868
Kevin Enderby146dcf22009-10-15 20:48:48 +00007869 return false;
7870}
7871
Jim Grosbachab5830e2011-12-14 02:16:11 +00007872/// parseDirectiveReq
7873/// ::= name .req registername
7874bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7875 Parser.Lex(); // Eat the '.req' token.
7876 unsigned Reg;
7877 SMLoc SRegLoc, ERegLoc;
7878 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007879 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007880 return Error(SRegLoc, "register name expected");
7881 }
7882
7883 // Shouldn't be anything else.
7884 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007885 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007886 return Error(Parser.getTok().getLoc(),
7887 "unexpected input in .req directive.");
7888 }
7889
7890 Parser.Lex(); // Consume the EndOfStatement
7891
7892 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7893 return Error(SRegLoc, "redefinition of '" + Name +
7894 "' does not match original.");
7895
7896 return false;
7897}
7898
7899/// parseDirectiveUneq
7900/// ::= .unreq registername
7901bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7902 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007903 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007904 return Error(L, "unexpected input in .unreq directive.");
7905 }
7906 RegisterReqs.erase(Parser.getTok().getIdentifier());
7907 Parser.Lex(); // Eat the identifier.
7908 return false;
7909}
7910
Jason W Kim135d2442011-12-20 17:38:12 +00007911/// parseDirectiveArch
7912/// ::= .arch token
7913bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7914 return true;
7915}
7916
7917/// parseDirectiveEabiAttr
7918/// ::= .eabi_attribute int, int
7919bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7920 return true;
7921}
7922
Logan Chien4ea23b52013-05-10 16:17:24 +00007923/// parseDirectiveFnStart
7924/// ::= .fnstart
7925bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7926 if (FnStartLoc.isValid()) {
7927 Error(L, ".fnstart starts before the end of previous one");
7928 Error(FnStartLoc, "previous .fnstart starts here");
7929 return true;
7930 }
7931
7932 FnStartLoc = L;
7933 getParser().getStreamer().EmitFnStart();
7934 return false;
7935}
7936
7937/// parseDirectiveFnEnd
7938/// ::= .fnend
7939bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7940 // Check the ordering of unwind directives
7941 if (!FnStartLoc.isValid())
7942 return Error(L, ".fnstart must precede .fnend directive");
7943
7944 // Reset the unwind directives parser state
7945 resetUnwindDirectiveParserState();
7946
7947 getParser().getStreamer().EmitFnEnd();
7948 return false;
7949}
7950
7951/// parseDirectiveCantUnwind
7952/// ::= .cantunwind
7953bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7954 // Check the ordering of unwind directives
7955 CantUnwindLoc = L;
7956 if (!FnStartLoc.isValid())
7957 return Error(L, ".fnstart must precede .cantunwind directive");
7958 if (HandlerDataLoc.isValid()) {
7959 Error(L, ".cantunwind can't be used with .handlerdata directive");
7960 Error(HandlerDataLoc, ".handlerdata was specified here");
7961 return true;
7962 }
7963 if (PersonalityLoc.isValid()) {
7964 Error(L, ".cantunwind can't be used with .personality directive");
7965 Error(PersonalityLoc, ".personality was specified here");
7966 return true;
7967 }
7968
7969 getParser().getStreamer().EmitCantUnwind();
7970 return false;
7971}
7972
7973/// parseDirectivePersonality
7974/// ::= .personality name
7975bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7976 // Check the ordering of unwind directives
7977 PersonalityLoc = L;
7978 if (!FnStartLoc.isValid())
7979 return Error(L, ".fnstart must precede .personality directive");
7980 if (CantUnwindLoc.isValid()) {
7981 Error(L, ".personality can't be used with .cantunwind directive");
7982 Error(CantUnwindLoc, ".cantunwind was specified here");
7983 return true;
7984 }
7985 if (HandlerDataLoc.isValid()) {
7986 Error(L, ".personality must precede .handlerdata directive");
7987 Error(HandlerDataLoc, ".handlerdata was specified here");
7988 return true;
7989 }
7990
7991 // Parse the name of the personality routine
7992 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7993 Parser.eatToEndOfStatement();
7994 return Error(L, "unexpected input in .personality directive.");
7995 }
7996 StringRef Name(Parser.getTok().getIdentifier());
7997 Parser.Lex();
7998
7999 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8000 getParser().getStreamer().EmitPersonality(PR);
8001 return false;
8002}
8003
8004/// parseDirectiveHandlerData
8005/// ::= .handlerdata
8006bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8007 // Check the ordering of unwind directives
8008 HandlerDataLoc = L;
8009 if (!FnStartLoc.isValid())
8010 return Error(L, ".fnstart must precede .personality directive");
8011 if (CantUnwindLoc.isValid()) {
8012 Error(L, ".handlerdata can't be used with .cantunwind directive");
8013 Error(CantUnwindLoc, ".cantunwind was specified here");
8014 return true;
8015 }
8016
8017 getParser().getStreamer().EmitHandlerData();
8018 return false;
8019}
8020
8021/// parseDirectiveSetFP
8022/// ::= .setfp fpreg, spreg [, offset]
8023bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8024 // Check the ordering of unwind directives
8025 if (!FnStartLoc.isValid())
8026 return Error(L, ".fnstart must precede .setfp directive");
8027 if (HandlerDataLoc.isValid())
8028 return Error(L, ".setfp must precede .handlerdata directive");
8029
8030 // Parse fpreg
8031 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8032 int NewFPReg = tryParseRegister();
8033 if (NewFPReg == -1)
8034 return Error(NewFPRegLoc, "frame pointer register expected");
8035
8036 // Consume comma
8037 if (!Parser.getTok().is(AsmToken::Comma))
8038 return Error(Parser.getTok().getLoc(), "comma expected");
8039 Parser.Lex(); // skip comma
8040
8041 // Parse spreg
8042 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8043 int NewSPReg = tryParseRegister();
8044 if (NewSPReg == -1)
8045 return Error(NewSPRegLoc, "stack pointer register expected");
8046
8047 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8048 return Error(NewSPRegLoc,
8049 "register should be either $sp or the latest fp register");
8050
8051 // Update the frame pointer register
8052 FPReg = NewFPReg;
8053
8054 // Parse offset
8055 int64_t Offset = 0;
8056 if (Parser.getTok().is(AsmToken::Comma)) {
8057 Parser.Lex(); // skip comma
8058
8059 if (Parser.getTok().isNot(AsmToken::Hash) &&
8060 Parser.getTok().isNot(AsmToken::Dollar)) {
8061 return Error(Parser.getTok().getLoc(), "'#' expected");
8062 }
8063 Parser.Lex(); // skip hash token.
8064
8065 const MCExpr *OffsetExpr;
8066 SMLoc ExLoc = Parser.getTok().getLoc();
8067 SMLoc EndLoc;
8068 if (getParser().parseExpression(OffsetExpr, EndLoc))
8069 return Error(ExLoc, "malformed setfp offset");
8070 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8071 if (!CE)
8072 return Error(ExLoc, "setfp offset must be an immediate");
8073
8074 Offset = CE->getValue();
8075 }
8076
8077 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8078 static_cast<unsigned>(NewSPReg),
8079 Offset);
8080 return false;
8081}
8082
8083/// parseDirective
8084/// ::= .pad offset
8085bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8086 // Check the ordering of unwind directives
8087 if (!FnStartLoc.isValid())
8088 return Error(L, ".fnstart must precede .pad directive");
8089 if (HandlerDataLoc.isValid())
8090 return Error(L, ".pad must precede .handlerdata directive");
8091
8092 // Parse the offset
8093 if (Parser.getTok().isNot(AsmToken::Hash) &&
8094 Parser.getTok().isNot(AsmToken::Dollar)) {
8095 return Error(Parser.getTok().getLoc(), "'#' expected");
8096 }
8097 Parser.Lex(); // skip hash token.
8098
8099 const MCExpr *OffsetExpr;
8100 SMLoc ExLoc = Parser.getTok().getLoc();
8101 SMLoc EndLoc;
8102 if (getParser().parseExpression(OffsetExpr, EndLoc))
8103 return Error(ExLoc, "malformed pad offset");
8104 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8105 if (!CE)
8106 return Error(ExLoc, "pad offset must be an immediate");
8107
8108 getParser().getStreamer().EmitPad(CE->getValue());
8109 return false;
8110}
8111
8112/// parseDirectiveRegSave
8113/// ::= .save { registers }
8114/// ::= .vsave { registers }
8115bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8116 // Check the ordering of unwind directives
8117 if (!FnStartLoc.isValid())
8118 return Error(L, ".fnstart must precede .save or .vsave directives");
8119 if (HandlerDataLoc.isValid())
8120 return Error(L, ".save or .vsave must precede .handlerdata directive");
8121
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008122 // RAII object to make sure parsed operands are deleted.
8123 struct CleanupObject {
8124 SmallVector<MCParsedAsmOperand *, 1> Operands;
8125 ~CleanupObject() {
8126 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8127 delete Operands[I];
8128 }
8129 } CO;
8130
Logan Chien4ea23b52013-05-10 16:17:24 +00008131 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008132 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008133 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008134 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008135 if (!IsVector && !Op->isRegList())
8136 return Error(L, ".save expects GPR registers");
8137 if (IsVector && !Op->isDPRRegList())
8138 return Error(L, ".vsave expects DPR registers");
8139
8140 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8141 return false;
8142}
8143
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008144/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008145extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008146 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8147 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008148}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008149
Chris Lattner3e4582a2010-09-06 19:11:01 +00008150#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008151#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008152#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008153#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008154
8155// Define this matcher function after the auto-generated include so we
8156// have the match class enum definitions.
8157unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8158 unsigned Kind) {
8159 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8160 // If the kind is a token for a literal immediate, check if our asm
8161 // operand matches. This is for InstAliases which have a fixed-value
8162 // immediate in the syntax.
8163 if (Kind == MCK__35_0 && Op->isImm()) {
8164 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8165 if (!CE)
8166 return Match_InvalidOperand;
8167 if (CE->getValue() == 0)
8168 return Match_Success;
8169 }
8170 return Match_InvalidOperand;
8171}