blob: 032e74438a84cd10abb2c4abac0d027bc2187894 [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);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000144 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000145 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000146
Evan Cheng4d1ca962011-07-08 01:53:10 +0000147 bool isThumb() const {
148 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000149 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000150 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000152 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000153 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000154 bool isThumbTwo() const {
155 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
156 }
Tim Northovera2292d02013-06-10 23:20:58 +0000157 bool hasThumb() const {
158 return STI.getFeatureBits() & ARM::HasV4TOps;
159 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000160 bool hasV6Ops() const {
161 return STI.getFeatureBits() & ARM::HasV6Ops;
162 }
James Molloy21efa7d2011-09-28 14:21:38 +0000163 bool hasV7Ops() const {
164 return STI.getFeatureBits() & ARM::HasV7Ops;
165 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000166 bool hasV8Ops() const {
167 return STI.getFeatureBits() & ARM::HasV8Ops;
168 }
Tim Northovera2292d02013-06-10 23:20:58 +0000169 bool hasARM() const {
170 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
171 }
172
Evan Cheng284b4672011-07-08 22:36:29 +0000173 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000174 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
175 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000176 }
James Molloy21efa7d2011-09-28 14:21:38 +0000177 bool isMClass() const {
178 return STI.getFeatureBits() & ARM::FeatureMClass;
179 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000180
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000181 /// @name Auto-generated Match Functions
182 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000183
Chris Lattner3e4582a2010-09-06 19:11:01 +0000184#define GET_ASSEMBLER_HEADER
185#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000186
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000187 /// }
188
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000189 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000192 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000194 OperandMatchResultTy parseCoprocOptionOperand(
195 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000196 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000197 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000198 OperandMatchResultTy parseInstSyncBarrierOptOperand(
199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000202 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000203 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000204 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
205 StringRef Op, int Low, int High);
206 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
207 return parsePKHImm(O, "lsl", 0, 31);
208 }
209 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
210 return parsePKHImm(O, "asr", 1, 32);
211 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000212 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000213 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000214 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000215 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000216 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000217 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000218 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000219 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000220 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
221 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000222
223 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000224 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000226 void cvtThumbBranches(MCInst &Inst,
227 const SmallVectorImpl<MCParsedAsmOperand*> &);
228
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000229 bool validateInstruction(MCInst &Inst,
230 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000231 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000232 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000233 bool shouldOmitCCOutOperand(StringRef Mnemonic,
234 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000235 bool shouldOmitPredicateOperand(StringRef Mnemonic,
236 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000237public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000238 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000239 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000240 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000241 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000242 Match_RequiresThumb2,
243#define GET_OPERAND_DIAGNOSTIC_TYPES
244#include "ARMGenAsmMatcher.inc"
245
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000246 };
247
Joey Gouly0e76fa72013-09-12 10:28:05 +0000248 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
249 const MCInstrInfo &MII)
250 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000251 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000252
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000253 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000254 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000255
Evan Cheng4d1ca962011-07-08 01:53:10 +0000256 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000257 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000258
259 // Not in an ITBlock to start with.
260 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000261
262 // Set ELF header flags.
263 // FIXME: This should eventually end up somewhere else where more
264 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000265 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
266 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
267 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000268 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000269
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000270 // Implementation of the MCTargetAsmParser interface:
271 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000272 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
273 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000274 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000275 bool ParseDirective(AsmToken DirectiveID);
276
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000277 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000278 unsigned checkTargetMatchPredicate(MCInst &Inst);
279
Chad Rosier49963552012-10-13 00:26:04 +0000280 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000281 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000282 MCStreamer &Out, unsigned &ErrorInfo,
283 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000284};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000285} // end anonymous namespace
286
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000287namespace {
288
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000289/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000290/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000291class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000292 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000293 k_CondCode,
294 k_CCOut,
295 k_ITCondMask,
296 k_CoprocNum,
297 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000298 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000299 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000300 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000301 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000302 k_Memory,
303 k_PostIndexRegister,
304 k_MSRMask,
305 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000306 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000307 k_Register,
308 k_RegisterList,
309 k_DPRRegisterList,
310 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000311 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000312 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000313 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000314 k_ShiftedRegister,
315 k_ShiftedImmediate,
316 k_ShifterImmediate,
317 k_RotateImmediate,
318 k_BitfieldDescriptor,
319 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000320 } Kind;
321
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000322 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000323 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000324
Eric Christopher8996c5d2013-03-15 00:42:55 +0000325 struct CCOp {
326 ARMCC::CondCodes Val;
327 };
328
329 struct CopOp {
330 unsigned Val;
331 };
332
333 struct CoprocOptionOp {
334 unsigned Val;
335 };
336
337 struct ITMaskOp {
338 unsigned Mask:4;
339 };
340
341 struct MBOptOp {
342 ARM_MB::MemBOpt Val;
343 };
344
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000345 struct ISBOptOp {
346 ARM_ISB::InstSyncBOpt Val;
347 };
348
Eric Christopher8996c5d2013-03-15 00:42:55 +0000349 struct IFlagsOp {
350 ARM_PROC::IFlags Val;
351 };
352
353 struct MMaskOp {
354 unsigned Val;
355 };
356
357 struct TokOp {
358 const char *Data;
359 unsigned Length;
360 };
361
362 struct RegOp {
363 unsigned RegNum;
364 };
365
366 // A vector register list is a sequential list of 1 to 4 registers.
367 struct VectorListOp {
368 unsigned RegNum;
369 unsigned Count;
370 unsigned LaneIndex;
371 bool isDoubleSpaced;
372 };
373
374 struct VectorIndexOp {
375 unsigned Val;
376 };
377
378 struct ImmOp {
379 const MCExpr *Val;
380 };
381
382 /// Combined record for all forms of ARM address expressions.
383 struct MemoryOp {
384 unsigned BaseRegNum;
385 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
386 // was specified.
387 const MCConstantExpr *OffsetImm; // Offset immediate value
388 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
389 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
390 unsigned ShiftImm; // shift for OffsetReg.
391 unsigned Alignment; // 0 = no alignment specified
392 // n = alignment in bytes (2, 4, 8, 16, or 32)
393 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
394 };
395
396 struct PostIdxRegOp {
397 unsigned RegNum;
398 bool isAdd;
399 ARM_AM::ShiftOpc ShiftTy;
400 unsigned ShiftImm;
401 };
402
403 struct ShifterImmOp {
404 bool isASR;
405 unsigned Imm;
406 };
407
408 struct RegShiftedRegOp {
409 ARM_AM::ShiftOpc ShiftTy;
410 unsigned SrcReg;
411 unsigned ShiftReg;
412 unsigned ShiftImm;
413 };
414
415 struct RegShiftedImmOp {
416 ARM_AM::ShiftOpc ShiftTy;
417 unsigned SrcReg;
418 unsigned ShiftImm;
419 };
420
421 struct RotImmOp {
422 unsigned Imm;
423 };
424
425 struct BitfieldOp {
426 unsigned LSB;
427 unsigned Width;
428 };
429
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000430 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000431 struct CCOp CC;
432 struct CopOp Cop;
433 struct CoprocOptionOp CoprocOption;
434 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000435 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000436 struct ITMaskOp ITMask;
437 struct IFlagsOp IFlags;
438 struct MMaskOp MMask;
439 struct TokOp Tok;
440 struct RegOp Reg;
441 struct VectorListOp VectorList;
442 struct VectorIndexOp VectorIndex;
443 struct ImmOp Imm;
444 struct MemoryOp Memory;
445 struct PostIdxRegOp PostIdxReg;
446 struct ShifterImmOp ShifterImm;
447 struct RegShiftedRegOp RegShiftedReg;
448 struct RegShiftedImmOp RegShiftedImm;
449 struct RotImmOp RotImm;
450 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000451 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000452
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000453 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
454public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000455 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
456 Kind = o.Kind;
457 StartLoc = o.StartLoc;
458 EndLoc = o.EndLoc;
459 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000460 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000461 CC = o.CC;
462 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000463 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000464 ITMask = o.ITMask;
465 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000466 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000467 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000469 case k_CCOut:
470 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000471 Reg = o.Reg;
472 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000473 case k_RegisterList:
474 case k_DPRRegisterList:
475 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000476 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000477 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000478 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000479 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000480 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000481 VectorList = o.VectorList;
482 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000483 case k_CoprocNum:
484 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000485 Cop = o.Cop;
486 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000487 case k_CoprocOption:
488 CoprocOption = o.CoprocOption;
489 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000490 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000491 Imm = o.Imm;
492 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000493 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000494 MBOpt = o.MBOpt;
495 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000496 case k_InstSyncBarrierOpt:
497 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000498 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000499 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000500 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000501 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000502 PostIdxReg = o.PostIdxReg;
503 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000504 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000505 MMask = o.MMask;
506 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000507 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000508 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000509 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000510 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000511 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000512 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000513 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000514 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000515 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000516 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000517 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000519 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000520 RotImm = o.RotImm;
521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000522 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000523 Bitfield = o.Bitfield;
524 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000525 case k_VectorIndex:
526 VectorIndex = o.VectorIndex;
527 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000528 }
529 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000530
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000531 /// getStartLoc - Get the location of the first token of this operand.
532 SMLoc getStartLoc() const { return StartLoc; }
533 /// getEndLoc - Get the location of the last token of this operand.
534 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000535 /// getLocRange - Get the range between the first and last token of this
536 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000537 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
538
Daniel Dunbard8042b72010-08-11 06:36:53 +0000539 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000540 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000541 return CC.Val;
542 }
543
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000544 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000546 return Cop.Val;
547 }
548
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000549 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000550 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000551 return StringRef(Tok.Data, Tok.Length);
552 }
553
554 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000555 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000556 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000557 }
558
Bill Wendlingbed94652010-11-09 23:28:44 +0000559 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000560 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
561 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000562 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000563 }
564
Kevin Enderbyf5079942009-10-13 22:19:02 +0000565 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000566 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000567 return Imm.Val;
568 }
569
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000570 unsigned getVectorIndex() const {
571 assert(Kind == k_VectorIndex && "Invalid access!");
572 return VectorIndex.Val;
573 }
574
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000575 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000576 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000577 return MBOpt.Val;
578 }
579
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000580 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
581 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
582 return ISBOpt.Val;
583 }
584
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000585 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000586 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000587 return IFlags.Val;
588 }
589
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000590 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000592 return MMask.Val;
593 }
594
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000595 bool isCoprocNum() const { return Kind == k_CoprocNum; }
596 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000597 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000598 bool isCondCode() const { return Kind == k_CondCode; }
599 bool isCCOut() const { return Kind == k_CCOut; }
600 bool isITMask() const { return Kind == k_ITCondMask; }
601 bool isITCondCode() const { return Kind == k_CondCode; }
602 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000603 // checks whether this operand is an unsigned offset which fits is a field
604 // of specified width and scaled by a specific number of bits
605 template<unsigned width, unsigned scale>
606 bool isUnsignedOffset() const {
607 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000608 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000609 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
610 int64_t Val = CE->getValue();
611 int64_t Align = 1LL << scale;
612 int64_t Max = Align * ((1LL << width) - 1);
613 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
614 }
615 return false;
616 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000617 // checks whether this operand is an signed offset which fits is a field
618 // of specified width and scaled by a specific number of bits
619 template<unsigned width, unsigned scale>
620 bool isSignedOffset() const {
621 if (!isImm()) return false;
622 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
623 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
624 int64_t Val = CE->getValue();
625 int64_t Align = 1LL << scale;
626 int64_t Max = Align * ((1LL << (width-1)) - 1);
627 int64_t Min = -Align * (1LL << (width-1));
628 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
629 }
630 return false;
631 }
632
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000633 // checks whether this operand is a memory operand computed as an offset
634 // applied to PC. the offset may have 8 bits of magnitude and is represented
635 // with two bits of shift. textually it may be either [pc, #imm], #imm or
636 // relocable expression...
637 bool isThumbMemPC() const {
638 int64_t Val = 0;
639 if (isImm()) {
640 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
642 if (!CE) return false;
643 Val = CE->getValue();
644 }
645 else if (isMem()) {
646 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
647 if(Memory.BaseRegNum != ARM::PC) return false;
648 Val = Memory.OffsetImm->getValue();
649 }
650 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000651 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000652 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000653 bool isFPImm() const {
654 if (!isImm()) return false;
655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
658 return Val != -1;
659 }
Jim Grosbachea231912011-12-22 22:19:05 +0000660 bool isFBits16() const {
661 if (!isImm()) return false;
662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value >= 0 && Value <= 16;
666 }
667 bool isFBits32() const {
668 if (!isImm()) return false;
669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
672 return Value >= 1 && Value <= 32;
673 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000674 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000675 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
680 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000681 bool isImm0_4() const {
682 if (!isImm()) return false;
683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = CE->getValue();
686 return Value >= 0 && Value < 5;
687 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000688 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000689 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
691 if (!CE) return false;
692 int64_t Value = CE->getValue();
693 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
694 }
695 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000696 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
698 if (!CE) return false;
699 int64_t Value = CE->getValue();
700 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
701 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000702 bool isImm0_508s4Neg() const {
703 if (!isImm()) return false;
704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
705 if (!CE) return false;
706 int64_t Value = -CE->getValue();
707 // explicitly exclude zero. we want that to use the normal 0_508 version.
708 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
709 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000710 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000711 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value >= 0 && Value < 256;
716 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000717 bool isImm0_4095() const {
718 if (!isImm()) return false;
719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = CE->getValue();
722 return Value >= 0 && Value < 4096;
723 }
724 bool isImm0_4095Neg() const {
725 if (!isImm()) return false;
726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = -CE->getValue();
729 return Value > 0 && Value < 4096;
730 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000731 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000732 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 2;
737 }
738 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value >= 0 && Value < 4;
744 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000745 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 8;
751 }
752 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value >= 0 && Value < 16;
758 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000759 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 if (!CE) return false;
763 int64_t Value = CE->getValue();
764 return Value >= 0 && Value < 32;
765 }
Jim Grosbach00326402011-12-08 01:30:04 +0000766 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000767 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return Value >= 0 && Value < 64;
772 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000773 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value == 8;
779 }
780 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value == 16;
786 }
787 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000788 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value == 32;
793 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000794 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000795 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value > 0 && Value <= 8;
800 }
801 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value > 0 && Value <= 16;
807 }
808 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value > 0 && Value <= 32;
814 }
815 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000816 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return Value > 0 && Value <= 64;
821 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000822 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000823 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value > 0 && Value < 8;
828 }
829 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000830 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value > 0 && Value < 16;
835 }
836 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value > 0 && Value < 32;
842 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000843 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value > 0 && Value < 17;
849 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000850 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value > 0 && Value < 33;
856 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000857 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 33;
863 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000864 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000865 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 if (!CE) return false;
868 int64_t Value = CE->getValue();
869 return Value >= 0 && Value < 65536;
870 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000871 bool isImm256_65535Expr() const {
872 if (!isImm()) return false;
873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 // If it's not a constant expression, it'll generate a fixup and be
875 // handled later.
876 if (!CE) return true;
877 int64_t Value = CE->getValue();
878 return Value >= 256 && Value < 65536;
879 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000880 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 // If it's not a constant expression, it'll generate a fixup and be
884 // handled later.
885 if (!CE) return true;
886 int64_t Value = CE->getValue();
887 return Value >= 0 && Value < 65536;
888 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000889 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000890 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
892 if (!CE) return false;
893 int64_t Value = CE->getValue();
894 return Value >= 0 && Value <= 0xffffff;
895 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000896 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000897 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 if (!CE) return false;
900 int64_t Value = CE->getValue();
901 return Value > 0 && Value < 33;
902 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000903 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000904 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000905 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
906 if (!CE) return false;
907 int64_t Value = CE->getValue();
908 return Value >= 0 && Value < 32;
909 }
910 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000911 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000912 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
913 if (!CE) return false;
914 int64_t Value = CE->getValue();
915 return Value > 0 && Value <= 32;
916 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000917 bool isAdrLabel() const {
918 // If we have an immediate that's not a constant, treat it as a label
919 // reference needing a fixup. If it is a constant, but it can't fit
920 // into shift immediate encoding, we reject it.
921 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
922 else return (isARMSOImm() || isARMSOImmNeg());
923 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000924 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000925 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
927 if (!CE) return false;
928 int64_t Value = CE->getValue();
929 return ARM_AM::getSOImmVal(Value) != -1;
930 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000931 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000932 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
936 return ARM_AM::getSOImmVal(~Value) != -1;
937 }
Jim Grosbach30506252011-12-08 00:31:07 +0000938 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000939 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000943 // Only use this when not representable as a plain so_imm.
944 return ARM_AM::getSOImmVal(Value) == -1 &&
945 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000946 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000947 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000948 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
950 if (!CE) return false;
951 int64_t Value = CE->getValue();
952 return ARM_AM::getT2SOImmVal(Value) != -1;
953 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000954 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000955 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000959 return ARM_AM::getT2SOImmVal(Value) == -1 &&
960 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000961 }
Jim Grosbach30506252011-12-08 00:31:07 +0000962 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000963 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 if (!CE) return false;
966 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000967 // Only use this when not representable as a plain so_imm.
968 return ARM_AM::getT2SOImmVal(Value) == -1 &&
969 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000970 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000971 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000972 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
974 if (!CE) return false;
975 int64_t Value = CE->getValue();
976 return Value == 1 || Value == 0;
977 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000978 bool isReg() const { return Kind == k_Register; }
979 bool isRegList() const { return Kind == k_RegisterList; }
980 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
981 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
982 bool isToken() const { return Kind == k_Token; }
983 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000984 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000985 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000986 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
987 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
988 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
989 bool isRotImm() const { return Kind == k_RotateImmediate; }
990 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
991 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000992 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000993 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000994 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000995 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000996 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000997 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000998 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000999 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1000 (alignOK || Memory.Alignment == 0);
1001 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001002 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001003 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001004 return false;
1005 // Base register must be PC.
1006 if (Memory.BaseRegNum != ARM::PC)
1007 return false;
1008 // Immediate offset in range [-4095, 4095].
1009 if (!Memory.OffsetImm) return true;
1010 int64_t Val = Memory.OffsetImm->getValue();
1011 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1012 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001013 bool isAlignedMemory() const {
1014 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001015 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001016 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001017 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001018 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001019 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001020 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001021 if (!Memory.OffsetImm) return true;
1022 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001023 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001024 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001025 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001026 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001027 // Immediate offset in range [-4095, 4095].
1028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1029 if (!CE) return false;
1030 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001031 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001032 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001033 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001034 // If we have an immediate that's not a constant, treat it as a label
1035 // reference needing a fixup. If it is a constant, it's something else
1036 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001037 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001038 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001039 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001040 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001041 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001042 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001043 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001044 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001045 if (!Memory.OffsetImm) return true;
1046 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001047 // The #-0 offset is encoded as INT32_MIN, and we have to check
1048 // for this too.
1049 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001050 }
1051 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001052 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001053 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001054 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001055 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1056 // Immediate offset in range [-255, 255].
1057 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1058 if (!CE) return false;
1059 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001060 // Special case, #-0 is INT32_MIN.
1061 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001062 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001063 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001064 // If we have an immediate that's not a constant, treat it as a label
1065 // reference needing a fixup. If it is a constant, it's something else
1066 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001067 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001068 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001069 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001070 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001071 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001072 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001073 if (!Memory.OffsetImm) return true;
1074 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001075 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001076 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001077 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001078 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001079 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001080 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001081 return false;
1082 return true;
1083 }
1084 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001085 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001086 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1087 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001088 return false;
1089 return true;
1090 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001091 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001092 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001093 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001094 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001095 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001096 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001097 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001098 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001099 return false;
1100 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001101 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001102 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001103 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001104 return false;
1105 return true;
1106 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001107 bool isMemThumbRR() const {
1108 // Thumb reg+reg addressing is simple. Just two registers, a base and
1109 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001110 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001111 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001112 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001113 return isARMLowRegister(Memory.BaseRegNum) &&
1114 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001115 }
1116 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001117 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001118 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001119 return false;
1120 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001121 if (!Memory.OffsetImm) return true;
1122 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001123 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1124 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001125 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001126 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001127 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001128 return false;
1129 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001130 if (!Memory.OffsetImm) return true;
1131 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001132 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1133 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001134 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001135 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001136 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001137 return false;
1138 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001139 if (!Memory.OffsetImm) return true;
1140 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001141 return Val >= 0 && Val <= 31;
1142 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001143 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001144 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001145 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001146 return false;
1147 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001148 if (!Memory.OffsetImm) return true;
1149 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001150 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001151 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001152 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001153 // If we have an immediate that's not a constant, treat it as a label
1154 // reference needing a fixup. If it is a constant, it's something else
1155 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001156 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001157 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001158 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001159 return false;
1160 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001161 if (!Memory.OffsetImm) return true;
1162 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001163 // Special case, #-0 is INT32_MIN.
1164 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001165 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001166 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001167 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001168 return false;
1169 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001170 if (!Memory.OffsetImm) return true;
1171 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001172 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1173 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001174 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001175 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001176 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001177 // Base reg of PC isn't allowed for these encodings.
1178 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001179 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001180 if (!Memory.OffsetImm) return true;
1181 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001182 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001183 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001184 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001185 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001186 return false;
1187 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001188 if (!Memory.OffsetImm) return true;
1189 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001190 return Val >= 0 && Val < 256;
1191 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001192 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001193 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001194 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001195 // Base reg of PC isn't allowed for these encodings.
1196 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001197 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001198 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001199 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001200 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001201 }
1202 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001203 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001204 return false;
1205 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001206 if (!Memory.OffsetImm) return true;
1207 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001208 return (Val >= 0 && Val < 4096);
1209 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001210 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001211 // If we have an immediate that's not a constant, treat it as a label
1212 // reference needing a fixup. If it is a constant, it's something else
1213 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001214 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001215 return true;
1216
Chad Rosier41099832012-09-11 23:02:35 +00001217 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001218 return false;
1219 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001220 if (!Memory.OffsetImm) return true;
1221 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001222 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001223 }
1224 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001225 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001226 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1227 if (!CE) return false;
1228 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001229 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001230 }
Jim Grosbach93981412011-10-11 21:55:36 +00001231 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001232 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001233 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1234 if (!CE) return false;
1235 int64_t Val = CE->getValue();
1236 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1237 (Val == INT32_MIN);
1238 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001239
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001240 bool isMSRMask() const { return Kind == k_MSRMask; }
1241 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001242
Jim Grosbach741cd732011-10-17 22:26:03 +00001243 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001244 bool isSingleSpacedVectorList() const {
1245 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1246 }
1247 bool isDoubleSpacedVectorList() const {
1248 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1249 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001250 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001251 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001252 return VectorList.Count == 1;
1253 }
1254
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001255 bool isVecListDPair() const {
1256 if (!isSingleSpacedVectorList()) return false;
1257 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1258 .contains(VectorList.RegNum));
1259 }
1260
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001261 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001262 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001263 return VectorList.Count == 3;
1264 }
1265
Jim Grosbach846bcff2011-10-21 20:35:01 +00001266 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001267 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001268 return VectorList.Count == 4;
1269 }
1270
Jim Grosbache5307f92012-03-05 21:43:40 +00001271 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001272 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001273 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1274 .contains(VectorList.RegNum));
1275 }
1276
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001277 bool isVecListThreeQ() const {
1278 if (!isDoubleSpacedVectorList()) return false;
1279 return VectorList.Count == 3;
1280 }
1281
Jim Grosbach1e946a42012-01-24 00:43:12 +00001282 bool isVecListFourQ() const {
1283 if (!isDoubleSpacedVectorList()) return false;
1284 return VectorList.Count == 4;
1285 }
1286
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001287 bool isSingleSpacedVectorAllLanes() const {
1288 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1289 }
1290 bool isDoubleSpacedVectorAllLanes() const {
1291 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1292 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001293 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001294 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001295 return VectorList.Count == 1;
1296 }
1297
Jim Grosbach13a292c2012-03-06 22:01:44 +00001298 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001299 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001300 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1301 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001302 }
1303
Jim Grosbached428bc2012-03-06 23:10:38 +00001304 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001305 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001306 return VectorList.Count == 2;
1307 }
1308
Jim Grosbachb78403c2012-01-24 23:47:04 +00001309 bool isVecListThreeDAllLanes() const {
1310 if (!isSingleSpacedVectorAllLanes()) return false;
1311 return VectorList.Count == 3;
1312 }
1313
1314 bool isVecListThreeQAllLanes() const {
1315 if (!isDoubleSpacedVectorAllLanes()) return false;
1316 return VectorList.Count == 3;
1317 }
1318
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001319 bool isVecListFourDAllLanes() const {
1320 if (!isSingleSpacedVectorAllLanes()) return false;
1321 return VectorList.Count == 4;
1322 }
1323
1324 bool isVecListFourQAllLanes() const {
1325 if (!isDoubleSpacedVectorAllLanes()) return false;
1326 return VectorList.Count == 4;
1327 }
1328
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001329 bool isSingleSpacedVectorIndexed() const {
1330 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1331 }
1332 bool isDoubleSpacedVectorIndexed() const {
1333 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1334 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001335 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001336 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001337 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1338 }
1339
Jim Grosbachda511042011-12-14 23:35:06 +00001340 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001341 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001342 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1343 }
1344
1345 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001346 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001347 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1348 }
1349
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001350 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001351 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001352 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1353 }
1354
Jim Grosbachda511042011-12-14 23:35:06 +00001355 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001356 if (!isSingleSpacedVectorIndexed()) return false;
1357 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1358 }
1359
1360 bool isVecListTwoQWordIndexed() const {
1361 if (!isDoubleSpacedVectorIndexed()) return false;
1362 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1363 }
1364
1365 bool isVecListTwoQHWordIndexed() const {
1366 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001367 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1368 }
1369
1370 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001371 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001372 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1373 }
1374
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001375 bool isVecListThreeDByteIndexed() const {
1376 if (!isSingleSpacedVectorIndexed()) return false;
1377 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1378 }
1379
1380 bool isVecListThreeDHWordIndexed() const {
1381 if (!isSingleSpacedVectorIndexed()) return false;
1382 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1383 }
1384
1385 bool isVecListThreeQWordIndexed() const {
1386 if (!isDoubleSpacedVectorIndexed()) return false;
1387 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1388 }
1389
1390 bool isVecListThreeQHWordIndexed() const {
1391 if (!isDoubleSpacedVectorIndexed()) return false;
1392 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1393 }
1394
1395 bool isVecListThreeDWordIndexed() const {
1396 if (!isSingleSpacedVectorIndexed()) return false;
1397 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1398 }
1399
Jim Grosbach14952a02012-01-24 18:37:25 +00001400 bool isVecListFourDByteIndexed() const {
1401 if (!isSingleSpacedVectorIndexed()) return false;
1402 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1403 }
1404
1405 bool isVecListFourDHWordIndexed() const {
1406 if (!isSingleSpacedVectorIndexed()) return false;
1407 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1408 }
1409
1410 bool isVecListFourQWordIndexed() const {
1411 if (!isDoubleSpacedVectorIndexed()) return false;
1412 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1413 }
1414
1415 bool isVecListFourQHWordIndexed() const {
1416 if (!isDoubleSpacedVectorIndexed()) return false;
1417 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1418 }
1419
1420 bool isVecListFourDWordIndexed() const {
1421 if (!isSingleSpacedVectorIndexed()) return false;
1422 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1423 }
1424
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001425 bool isVectorIndex8() const {
1426 if (Kind != k_VectorIndex) return false;
1427 return VectorIndex.Val < 8;
1428 }
1429 bool isVectorIndex16() const {
1430 if (Kind != k_VectorIndex) return false;
1431 return VectorIndex.Val < 4;
1432 }
1433 bool isVectorIndex32() const {
1434 if (Kind != k_VectorIndex) return false;
1435 return VectorIndex.Val < 2;
1436 }
1437
Jim Grosbach741cd732011-10-17 22:26:03 +00001438 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001439 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001440 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1441 // Must be a constant.
1442 if (!CE) return false;
1443 int64_t Value = CE->getValue();
1444 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1445 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001446 return Value >= 0 && Value < 256;
1447 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001448
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001449 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001450 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001451 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1452 // Must be a constant.
1453 if (!CE) return false;
1454 int64_t Value = CE->getValue();
1455 // i16 value in the range [0,255] or [0x0100, 0xff00]
1456 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1457 }
1458
Jim Grosbach8211c052011-10-18 00:22:00 +00001459 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001460 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001461 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1462 // Must be a constant.
1463 if (!CE) return false;
1464 int64_t Value = CE->getValue();
1465 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1466 return (Value >= 0 && Value < 256) ||
1467 (Value >= 0x0100 && Value <= 0xff00) ||
1468 (Value >= 0x010000 && Value <= 0xff0000) ||
1469 (Value >= 0x01000000 && Value <= 0xff000000);
1470 }
1471
1472 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001473 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001474 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1475 // Must be a constant.
1476 if (!CE) return false;
1477 int64_t Value = CE->getValue();
1478 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1479 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1480 return (Value >= 0 && Value < 256) ||
1481 (Value >= 0x0100 && Value <= 0xff00) ||
1482 (Value >= 0x010000 && Value <= 0xff0000) ||
1483 (Value >= 0x01000000 && Value <= 0xff000000) ||
1484 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1485 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1486 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001487 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001488 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001489 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1490 // Must be a constant.
1491 if (!CE) return false;
1492 int64_t Value = ~CE->getValue();
1493 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1494 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1495 return (Value >= 0 && Value < 256) ||
1496 (Value >= 0x0100 && Value <= 0xff00) ||
1497 (Value >= 0x010000 && Value <= 0xff0000) ||
1498 (Value >= 0x01000000 && Value <= 0xff000000) ||
1499 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1500 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1501 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001502
Jim Grosbache4454e02011-10-18 16:18:11 +00001503 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001504 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001505 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1506 // Must be a constant.
1507 if (!CE) return false;
1508 uint64_t Value = CE->getValue();
1509 // i64 value with each byte being either 0 or 0xff.
1510 for (unsigned i = 0; i < 8; ++i)
1511 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1512 return true;
1513 }
1514
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001515 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001516 // Add as immediates when possible. Null MCExpr = 0.
1517 if (Expr == 0)
1518 Inst.addOperand(MCOperand::CreateImm(0));
1519 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001520 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1521 else
1522 Inst.addOperand(MCOperand::CreateExpr(Expr));
1523 }
1524
Daniel Dunbard8042b72010-08-11 06:36:53 +00001525 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001526 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001527 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001528 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1529 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001530 }
1531
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001532 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1533 assert(N == 1 && "Invalid number of operands!");
1534 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1535 }
1536
Jim Grosbach48399582011-10-12 17:34:41 +00001537 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1538 assert(N == 1 && "Invalid number of operands!");
1539 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1540 }
1541
1542 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1543 assert(N == 1 && "Invalid number of operands!");
1544 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1545 }
1546
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001547 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1548 assert(N == 1 && "Invalid number of operands!");
1549 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1550 }
1551
1552 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1553 assert(N == 1 && "Invalid number of operands!");
1554 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1555 }
1556
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001557 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1558 assert(N == 1 && "Invalid number of operands!");
1559 Inst.addOperand(MCOperand::CreateReg(getReg()));
1560 }
1561
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001562 void addRegOperands(MCInst &Inst, unsigned N) const {
1563 assert(N == 1 && "Invalid number of operands!");
1564 Inst.addOperand(MCOperand::CreateReg(getReg()));
1565 }
1566
Jim Grosbachac798e12011-07-25 20:49:51 +00001567 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001568 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001569 assert(isRegShiftedReg() &&
1570 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001571 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1572 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001573 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001574 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001575 }
1576
Jim Grosbachac798e12011-07-25 20:49:51 +00001577 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001578 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001579 assert(isRegShiftedImm() &&
1580 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001581 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001582 // Shift of #32 is encoded as 0 where permitted
1583 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001584 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001585 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001586 }
1587
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001588 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001589 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001590 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1591 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001592 }
1593
Bill Wendling8d2aa032010-11-08 23:49:57 +00001594 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001595 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001596 const SmallVectorImpl<unsigned> &RegList = getRegList();
1597 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001598 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1599 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001600 }
1601
Bill Wendling9898ac92010-11-17 04:32:08 +00001602 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1603 addRegListOperands(Inst, N);
1604 }
1605
1606 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1607 addRegListOperands(Inst, N);
1608 }
1609
Jim Grosbach833b9d32011-07-27 20:15:40 +00001610 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1613 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1614 }
1615
Jim Grosbach864b6092011-07-28 21:34:26 +00001616 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 // Munge the lsb/width into a bitfield mask.
1619 unsigned lsb = Bitfield.LSB;
1620 unsigned width = Bitfield.Width;
1621 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1622 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1623 (32 - (lsb + width)));
1624 Inst.addOperand(MCOperand::CreateImm(Mask));
1625 }
1626
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001627 void addImmOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 addExpr(Inst, getImm());
1630 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001631
Jim Grosbachea231912011-12-22 22:19:05 +00001632 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1635 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1636 }
1637
1638 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1639 assert(N == 1 && "Invalid number of operands!");
1640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1641 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1642 }
1643
Jim Grosbache7fbce72011-10-03 23:38:36 +00001644 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1645 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1648 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001649 }
1650
Jim Grosbach7db8d692011-09-08 22:07:06 +00001651 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1652 assert(N == 1 && "Invalid number of operands!");
1653 // FIXME: We really want to scale the value here, but the LDRD/STRD
1654 // instruction don't encode operands that way yet.
1655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1656 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1657 }
1658
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001659 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1660 assert(N == 1 && "Invalid number of operands!");
1661 // The immediate is scaled by four in the encoding and is stored
1662 // in the MCInst as such. Lop off the low two bits here.
1663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1664 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1665 }
1666
Jim Grosbach930f2f62012-04-05 20:57:13 +00001667 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1668 assert(N == 1 && "Invalid number of operands!");
1669 // The immediate is scaled by four in the encoding and is stored
1670 // in the MCInst as such. Lop off the low two bits here.
1671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1672 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1673 }
1674
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001675 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1676 assert(N == 1 && "Invalid number of operands!");
1677 // The immediate is scaled by four in the encoding and is stored
1678 // in the MCInst as such. Lop off the low two bits here.
1679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1680 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1681 }
1682
Jim Grosbach475c6db2011-07-25 23:09:14 +00001683 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1684 assert(N == 1 && "Invalid number of operands!");
1685 // The constant encodes as the immediate-1, and we store in the instruction
1686 // the bits as encoded, so subtract off one here.
1687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1688 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1689 }
1690
Jim Grosbach801e0a32011-07-22 23:16:18 +00001691 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // The constant encodes as the immediate-1, and we store in the instruction
1694 // the bits as encoded, so subtract off one here.
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1697 }
1698
Jim Grosbach46dd4132011-08-17 21:51:27 +00001699 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1700 assert(N == 1 && "Invalid number of operands!");
1701 // The constant encodes as the immediate, except for 32, which encodes as
1702 // zero.
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 unsigned Imm = CE->getValue();
1705 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1706 }
1707
Jim Grosbach27c1e252011-07-21 17:23:04 +00001708 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1711 // the instruction as well.
1712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1713 int Val = CE->getValue();
1714 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1715 }
1716
Jim Grosbachb009a872011-10-28 22:36:30 +00001717 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1718 assert(N == 1 && "Invalid number of operands!");
1719 // The operand is actually a t2_so_imm, but we have its bitwise
1720 // negation in the assembly source, so twiddle it here.
1721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1722 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1723 }
1724
Jim Grosbach30506252011-12-08 00:31:07 +00001725 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1726 assert(N == 1 && "Invalid number of operands!");
1727 // The operand is actually a t2_so_imm, but we have its
1728 // negation in the assembly source, so twiddle it here.
1729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1730 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1731 }
1732
Jim Grosbach930f2f62012-04-05 20:57:13 +00001733 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1734 assert(N == 1 && "Invalid number of operands!");
1735 // The operand is actually an imm0_4095, but we have its
1736 // negation in the assembly source, so twiddle it here.
1737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1738 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1739 }
1740
Mihai Popad36cbaa2013-07-03 09:21:44 +00001741 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1742 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1743 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1744 return;
1745 }
1746
1747 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1748 assert(SR && "Unknown value type!");
1749 Inst.addOperand(MCOperand::CreateExpr(SR));
1750 }
1751
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001752 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1753 assert(N == 1 && "Invalid number of operands!");
1754 if (isImm()) {
1755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1756 if (CE) {
1757 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1758 return;
1759 }
1760
1761 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1762 assert(SR && "Unknown value type!");
1763 Inst.addOperand(MCOperand::CreateExpr(SR));
1764 return;
1765 }
1766
1767 assert(isMem() && "Unknown value type!");
1768 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1769 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1770 }
1771
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001772 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1773 assert(N == 1 && "Invalid number of operands!");
1774 // The operand is actually a so_imm, but we have its bitwise
1775 // negation in the assembly source, so twiddle it here.
1776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1777 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1778 }
1779
Jim Grosbach30506252011-12-08 00:31:07 +00001780 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1781 assert(N == 1 && "Invalid number of operands!");
1782 // The operand is actually a so_imm, but we have its
1783 // negation in the assembly source, so twiddle it here.
1784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1785 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1786 }
1787
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001788 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 1 && "Invalid number of operands!");
1790 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1791 }
1792
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001793 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1794 assert(N == 1 && "Invalid number of operands!");
1795 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1796 }
1797
Jim Grosbachd3595712011-08-03 23:50:40 +00001798 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1799 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001800 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001801 }
1802
Jim Grosbach94298a92012-01-18 22:46:46 +00001803 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1804 assert(N == 1 && "Invalid number of operands!");
1805 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001806 Inst.addOperand(MCOperand::CreateImm(Imm));
1807 }
1808
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001809 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1810 assert(N == 1 && "Invalid number of operands!");
1811 assert(isImm() && "Not an immediate!");
1812
1813 // If we have an immediate that's not a constant, treat it as a label
1814 // reference needing a fixup.
1815 if (!isa<MCConstantExpr>(getImm())) {
1816 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1817 return;
1818 }
1819
1820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1821 int Val = CE->getValue();
1822 Inst.addOperand(MCOperand::CreateImm(Val));
1823 }
1824
Jim Grosbacha95ec992011-10-11 17:29:55 +00001825 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
1827 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1828 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1829 }
1830
Jim Grosbachd3595712011-08-03 23:50:40 +00001831 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1832 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001833 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1834 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001835 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1836 // Special case for #-0
1837 if (Val == INT32_MIN) Val = 0;
1838 if (Val < 0) Val = -Val;
1839 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1840 } else {
1841 // For register offset, we encode the shift type and negation flag
1842 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001843 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1844 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001845 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001846 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1847 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001848 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001849 }
1850
Jim Grosbachcd17c122011-08-04 23:01:30 +00001851 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1852 assert(N == 2 && "Invalid number of operands!");
1853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1854 assert(CE && "non-constant AM2OffsetImm operand!");
1855 int32_t Val = CE->getValue();
1856 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1857 // Special case for #-0
1858 if (Val == INT32_MIN) Val = 0;
1859 if (Val < 0) Val = -Val;
1860 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1861 Inst.addOperand(MCOperand::CreateReg(0));
1862 Inst.addOperand(MCOperand::CreateImm(Val));
1863 }
1864
Jim Grosbach5b96b802011-08-10 20:29:19 +00001865 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1866 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001867 // If we have an immediate that's not a constant, treat it as a label
1868 // reference needing a fixup. If it is a constant, it's something else
1869 // and we reject it.
1870 if (isImm()) {
1871 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1872 Inst.addOperand(MCOperand::CreateReg(0));
1873 Inst.addOperand(MCOperand::CreateImm(0));
1874 return;
1875 }
1876
Jim Grosbach871dff72011-10-11 15:59:20 +00001877 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1878 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001879 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1880 // Special case for #-0
1881 if (Val == INT32_MIN) Val = 0;
1882 if (Val < 0) Val = -Val;
1883 Val = ARM_AM::getAM3Opc(AddSub, Val);
1884 } else {
1885 // For register offset, we encode the shift type and negation flag
1886 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001887 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001888 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001889 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1890 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001891 Inst.addOperand(MCOperand::CreateImm(Val));
1892 }
1893
1894 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001896 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001897 int32_t Val =
1898 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1899 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1900 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001901 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001902 }
1903
1904 // Constant offset.
1905 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1906 int32_t Val = CE->getValue();
1907 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1908 // Special case for #-0
1909 if (Val == INT32_MIN) Val = 0;
1910 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001911 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001912 Inst.addOperand(MCOperand::CreateReg(0));
1913 Inst.addOperand(MCOperand::CreateImm(Val));
1914 }
1915
Jim Grosbachd3595712011-08-03 23:50:40 +00001916 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1917 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001918 // If we have an immediate that's not a constant, treat it as a label
1919 // reference needing a fixup. If it is a constant, it's something else
1920 // and we reject it.
1921 if (isImm()) {
1922 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1923 Inst.addOperand(MCOperand::CreateImm(0));
1924 return;
1925 }
1926
Jim Grosbachd3595712011-08-03 23:50:40 +00001927 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001928 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001929 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1930 // Special case for #-0
1931 if (Val == INT32_MIN) Val = 0;
1932 if (Val < 0) Val = -Val;
1933 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001934 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001935 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001936 }
1937
Jim Grosbach7db8d692011-09-08 22:07:06 +00001938 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001940 // If we have an immediate that's not a constant, treat it as a label
1941 // reference needing a fixup. If it is a constant, it's something else
1942 // and we reject it.
1943 if (isImm()) {
1944 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1945 Inst.addOperand(MCOperand::CreateImm(0));
1946 return;
1947 }
1948
Jim Grosbach871dff72011-10-11 15:59:20 +00001949 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1950 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001951 Inst.addOperand(MCOperand::CreateImm(Val));
1952 }
1953
Jim Grosbacha05627e2011-09-09 18:37:27 +00001954 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1955 assert(N == 2 && "Invalid number of operands!");
1956 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001957 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1958 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001959 Inst.addOperand(MCOperand::CreateImm(Val));
1960 }
1961
Jim Grosbachd3595712011-08-03 23:50:40 +00001962 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1963 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001964 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1965 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001966 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001967 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001968
Jim Grosbach2392c532011-09-07 23:39:14 +00001969 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1970 addMemImm8OffsetOperands(Inst, N);
1971 }
1972
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001973 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001974 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001975 }
1976
1977 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1978 assert(N == 2 && "Invalid number of operands!");
1979 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001980 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001981 addExpr(Inst, getImm());
1982 Inst.addOperand(MCOperand::CreateImm(0));
1983 return;
1984 }
1985
1986 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001987 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1988 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001989 Inst.addOperand(MCOperand::CreateImm(Val));
1990 }
1991
Jim Grosbachd3595712011-08-03 23:50:40 +00001992 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1993 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001994 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001995 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001996 addExpr(Inst, getImm());
1997 Inst.addOperand(MCOperand::CreateImm(0));
1998 return;
1999 }
2000
2001 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002002 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2003 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002004 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002005 }
Bill Wendling811c9362010-11-30 07:44:32 +00002006
Jim Grosbach05541f42011-09-19 22:21:13 +00002007 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2008 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002009 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2010 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002011 }
2012
2013 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2014 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002015 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2016 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002017 }
2018
Jim Grosbachd3595712011-08-03 23:50:40 +00002019 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2020 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002021 unsigned Val =
2022 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2023 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2025 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002026 Inst.addOperand(MCOperand::CreateImm(Val));
2027 }
2028
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002029 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2032 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2033 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002034 }
2035
Jim Grosbachd3595712011-08-03 23:50:40 +00002036 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002038 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2039 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002040 }
2041
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002042 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2043 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002044 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2045 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002046 Inst.addOperand(MCOperand::CreateImm(Val));
2047 }
2048
Jim Grosbach26d35872011-08-19 18:55:51 +00002049 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2050 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002051 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2052 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002053 Inst.addOperand(MCOperand::CreateImm(Val));
2054 }
2055
Jim Grosbacha32c7532011-08-19 18:49:59 +00002056 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2057 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002058 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2059 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002060 Inst.addOperand(MCOperand::CreateImm(Val));
2061 }
2062
Jim Grosbach23983d62011-08-19 18:13:48 +00002063 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2064 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002065 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2066 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002067 Inst.addOperand(MCOperand::CreateImm(Val));
2068 }
2069
Jim Grosbachd3595712011-08-03 23:50:40 +00002070 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2071 assert(N == 1 && "Invalid number of operands!");
2072 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2073 assert(CE && "non-constant post-idx-imm8 operand!");
2074 int Imm = CE->getValue();
2075 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002076 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002077 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2078 Inst.addOperand(MCOperand::CreateImm(Imm));
2079 }
2080
Jim Grosbach93981412011-10-11 21:55:36 +00002081 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2082 assert(N == 1 && "Invalid number of operands!");
2083 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2084 assert(CE && "non-constant post-idx-imm8s4 operand!");
2085 int Imm = CE->getValue();
2086 bool isAdd = Imm >= 0;
2087 if (Imm == INT32_MIN) Imm = 0;
2088 // Immediate is scaled by 4.
2089 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2090 Inst.addOperand(MCOperand::CreateImm(Imm));
2091 }
2092
Jim Grosbachd3595712011-08-03 23:50:40 +00002093 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2094 assert(N == 2 && "Invalid number of operands!");
2095 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002096 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2097 }
2098
2099 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2100 assert(N == 2 && "Invalid number of operands!");
2101 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2102 // The sign, shift type, and shift amount are encoded in a single operand
2103 // using the AM2 encoding helpers.
2104 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2105 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2106 PostIdxReg.ShiftTy);
2107 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002108 }
2109
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002110 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2111 assert(N == 1 && "Invalid number of operands!");
2112 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2113 }
2114
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002115 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2116 assert(N == 1 && "Invalid number of operands!");
2117 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2118 }
2119
Jim Grosbach182b6a02011-11-29 23:51:09 +00002120 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002121 assert(N == 1 && "Invalid number of operands!");
2122 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2123 }
2124
Jim Grosbach04945c42011-12-02 00:35:16 +00002125 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2126 assert(N == 2 && "Invalid number of operands!");
2127 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2128 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2129 }
2130
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002131 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2132 assert(N == 1 && "Invalid number of operands!");
2133 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2134 }
2135
2136 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2137 assert(N == 1 && "Invalid number of operands!");
2138 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2139 }
2140
2141 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2142 assert(N == 1 && "Invalid number of operands!");
2143 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2144 }
2145
Jim Grosbach741cd732011-10-17 22:26:03 +00002146 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2147 assert(N == 1 && "Invalid number of operands!");
2148 // The immediate encodes the type of constant as well as the value.
2149 // Mask in that this is an i8 splat.
2150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2151 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2152 }
2153
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002154 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2155 assert(N == 1 && "Invalid number of operands!");
2156 // The immediate encodes the type of constant as well as the value.
2157 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2158 unsigned Value = CE->getValue();
2159 if (Value >= 256)
2160 Value = (Value >> 8) | 0xa00;
2161 else
2162 Value |= 0x800;
2163 Inst.addOperand(MCOperand::CreateImm(Value));
2164 }
2165
Jim Grosbach8211c052011-10-18 00:22:00 +00002166 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2167 assert(N == 1 && "Invalid number of operands!");
2168 // The immediate encodes the type of constant as well as the value.
2169 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2170 unsigned Value = CE->getValue();
2171 if (Value >= 256 && Value <= 0xff00)
2172 Value = (Value >> 8) | 0x200;
2173 else if (Value > 0xffff && Value <= 0xff0000)
2174 Value = (Value >> 16) | 0x400;
2175 else if (Value > 0xffffff)
2176 Value = (Value >> 24) | 0x600;
2177 Inst.addOperand(MCOperand::CreateImm(Value));
2178 }
2179
2180 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2181 assert(N == 1 && "Invalid number of operands!");
2182 // The immediate encodes the type of constant as well as the value.
2183 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2184 unsigned Value = CE->getValue();
2185 if (Value >= 256 && Value <= 0xffff)
2186 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2187 else if (Value > 0xffff && Value <= 0xffffff)
2188 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2189 else if (Value > 0xffffff)
2190 Value = (Value >> 24) | 0x600;
2191 Inst.addOperand(MCOperand::CreateImm(Value));
2192 }
2193
Jim Grosbach045b6c72011-12-19 23:51:07 +00002194 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2195 assert(N == 1 && "Invalid number of operands!");
2196 // The immediate encodes the type of constant as well as the value.
2197 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2198 unsigned Value = ~CE->getValue();
2199 if (Value >= 256 && Value <= 0xffff)
2200 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2201 else if (Value > 0xffff && Value <= 0xffffff)
2202 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2203 else if (Value > 0xffffff)
2204 Value = (Value >> 24) | 0x600;
2205 Inst.addOperand(MCOperand::CreateImm(Value));
2206 }
2207
Jim Grosbache4454e02011-10-18 16:18:11 +00002208 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2209 assert(N == 1 && "Invalid number of operands!");
2210 // The immediate encodes the type of constant as well as the value.
2211 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2212 uint64_t Value = CE->getValue();
2213 unsigned Imm = 0;
2214 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2215 Imm |= (Value & 1) << i;
2216 }
2217 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2218 }
2219
Jim Grosbach602aa902011-07-13 15:34:57 +00002220 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002221
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002222 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002223 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002224 Op->ITMask.Mask = Mask;
2225 Op->StartLoc = S;
2226 Op->EndLoc = S;
2227 return Op;
2228 }
2229
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002230 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002231 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002232 Op->CC.Val = CC;
2233 Op->StartLoc = S;
2234 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002235 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002236 }
2237
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002238 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002239 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002240 Op->Cop.Val = CopVal;
2241 Op->StartLoc = S;
2242 Op->EndLoc = S;
2243 return Op;
2244 }
2245
2246 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002247 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002248 Op->Cop.Val = CopVal;
2249 Op->StartLoc = S;
2250 Op->EndLoc = S;
2251 return Op;
2252 }
2253
Jim Grosbach48399582011-10-12 17:34:41 +00002254 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2255 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2256 Op->Cop.Val = Val;
2257 Op->StartLoc = S;
2258 Op->EndLoc = E;
2259 return Op;
2260 }
2261
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002262 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002263 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002264 Op->Reg.RegNum = RegNum;
2265 Op->StartLoc = S;
2266 Op->EndLoc = S;
2267 return Op;
2268 }
2269
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002270 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002272 Op->Tok.Data = Str.data();
2273 Op->Tok.Length = Str.size();
2274 Op->StartLoc = S;
2275 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002276 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002277 }
2278
Bill Wendling2063b842010-11-18 23:43:05 +00002279 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002280 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002281 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002282 Op->StartLoc = S;
2283 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002284 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002285 }
2286
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002287 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2288 unsigned SrcReg,
2289 unsigned ShiftReg,
2290 unsigned ShiftImm,
2291 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002292 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002293 Op->RegShiftedReg.ShiftTy = ShTy;
2294 Op->RegShiftedReg.SrcReg = SrcReg;
2295 Op->RegShiftedReg.ShiftReg = ShiftReg;
2296 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002297 Op->StartLoc = S;
2298 Op->EndLoc = E;
2299 return Op;
2300 }
2301
Owen Andersonb595ed02011-07-21 18:54:16 +00002302 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2303 unsigned SrcReg,
2304 unsigned ShiftImm,
2305 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002306 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002307 Op->RegShiftedImm.ShiftTy = ShTy;
2308 Op->RegShiftedImm.SrcReg = SrcReg;
2309 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002310 Op->StartLoc = S;
2311 Op->EndLoc = E;
2312 return Op;
2313 }
2314
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002315 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002316 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002317 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002318 Op->ShifterImm.isASR = isASR;
2319 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002320 Op->StartLoc = S;
2321 Op->EndLoc = E;
2322 return Op;
2323 }
2324
Jim Grosbach833b9d32011-07-27 20:15:40 +00002325 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002326 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002327 Op->RotImm.Imm = Imm;
2328 Op->StartLoc = S;
2329 Op->EndLoc = E;
2330 return Op;
2331 }
2332
Jim Grosbach864b6092011-07-28 21:34:26 +00002333 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2334 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002335 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002336 Op->Bitfield.LSB = LSB;
2337 Op->Bitfield.Width = Width;
2338 Op->StartLoc = S;
2339 Op->EndLoc = E;
2340 return Op;
2341 }
2342
Bill Wendling2cae3272010-11-09 22:44:22 +00002343 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002344 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002345 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002346 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002347 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002348
Chad Rosierfa705ee2013-07-01 20:49:23 +00002349 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002350 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002351 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002352 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002353 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002354
Chad Rosierfa705ee2013-07-01 20:49:23 +00002355 // Sort based on the register encoding values.
2356 array_pod_sort(Regs.begin(), Regs.end());
2357
Bill Wendling9898ac92010-11-17 04:32:08 +00002358 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002359 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002360 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002361 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002362 Op->StartLoc = StartLoc;
2363 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002364 return Op;
2365 }
2366
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002367 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002368 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002369 ARMOperand *Op = new ARMOperand(k_VectorList);
2370 Op->VectorList.RegNum = RegNum;
2371 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002372 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002373 Op->StartLoc = S;
2374 Op->EndLoc = E;
2375 return Op;
2376 }
2377
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002378 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002379 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002380 SMLoc S, SMLoc E) {
2381 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2382 Op->VectorList.RegNum = RegNum;
2383 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002384 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002385 Op->StartLoc = S;
2386 Op->EndLoc = E;
2387 return Op;
2388 }
2389
Jim Grosbach04945c42011-12-02 00:35:16 +00002390 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002391 unsigned Index,
2392 bool isDoubleSpaced,
2393 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002394 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2395 Op->VectorList.RegNum = RegNum;
2396 Op->VectorList.Count = Count;
2397 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002398 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002399 Op->StartLoc = S;
2400 Op->EndLoc = E;
2401 return Op;
2402 }
2403
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002404 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2405 MCContext &Ctx) {
2406 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2407 Op->VectorIndex.Val = Idx;
2408 Op->StartLoc = S;
2409 Op->EndLoc = E;
2410 return Op;
2411 }
2412
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002413 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002414 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002415 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002416 Op->StartLoc = S;
2417 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002418 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002419 }
2420
Jim Grosbachd3595712011-08-03 23:50:40 +00002421 static ARMOperand *CreateMem(unsigned BaseRegNum,
2422 const MCConstantExpr *OffsetImm,
2423 unsigned OffsetRegNum,
2424 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002425 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002426 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002427 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002428 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002429 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002430 Op->Memory.BaseRegNum = BaseRegNum;
2431 Op->Memory.OffsetImm = OffsetImm;
2432 Op->Memory.OffsetRegNum = OffsetRegNum;
2433 Op->Memory.ShiftType = ShiftType;
2434 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002435 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002436 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002437 Op->StartLoc = S;
2438 Op->EndLoc = E;
2439 return Op;
2440 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002441
Jim Grosbachc320c852011-08-05 21:28:30 +00002442 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2443 ARM_AM::ShiftOpc ShiftTy,
2444 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002445 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002447 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002448 Op->PostIdxReg.isAdd = isAdd;
2449 Op->PostIdxReg.ShiftTy = ShiftTy;
2450 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002451 Op->StartLoc = S;
2452 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002453 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002454 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002455
2456 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002457 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002458 Op->MBOpt.Val = Opt;
2459 Op->StartLoc = S;
2460 Op->EndLoc = S;
2461 return Op;
2462 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002463
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002464 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2465 SMLoc S) {
2466 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2467 Op->ISBOpt.Val = Opt;
2468 Op->StartLoc = S;
2469 Op->EndLoc = S;
2470 return Op;
2471 }
2472
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002473 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002474 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002475 Op->IFlags.Val = IFlags;
2476 Op->StartLoc = S;
2477 Op->EndLoc = S;
2478 return Op;
2479 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002480
2481 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002482 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002483 Op->MMask.Val = MMask;
2484 Op->StartLoc = S;
2485 Op->EndLoc = S;
2486 return Op;
2487 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002488};
2489
2490} // end anonymous namespace.
2491
Jim Grosbach602aa902011-07-13 15:34:57 +00002492void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002493 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002494 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002495 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002496 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002497 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002498 OS << "<ccout " << getReg() << ">";
2499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002500 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002501 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002502 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2503 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2504 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002505 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2506 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2507 break;
2508 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002509 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002510 OS << "<coprocessor number: " << getCoproc() << ">";
2511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002512 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002513 OS << "<coprocessor register: " << getCoproc() << ">";
2514 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002515 case k_CoprocOption:
2516 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2517 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002518 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002519 OS << "<mask: " << getMSRMask() << ">";
2520 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002521 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002522 getImm()->print(OS);
2523 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002525 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002526 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002527 case k_InstSyncBarrierOpt:
2528 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002530 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002531 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002532 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002533 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002534 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002535 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002536 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2537 << PostIdxReg.RegNum;
2538 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2539 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2540 << PostIdxReg.ShiftImm;
2541 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002542 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002544 OS << "<ARM_PROC::";
2545 unsigned IFlags = getProcIFlags();
2546 for (int i=2; i >= 0; --i)
2547 if (IFlags & (1 << i))
2548 OS << ARM_PROC::IFlagsToString(1 << i);
2549 OS << ">";
2550 break;
2551 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002552 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002553 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002554 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002555 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002556 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2557 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002558 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002559 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002560 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002561 << RegShiftedReg.SrcReg << " "
2562 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2563 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002564 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002565 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002566 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002567 << RegShiftedImm.SrcReg << " "
2568 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2569 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002570 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002571 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002572 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002574 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002575 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2576 << ", width: " << Bitfield.Width << ">";
2577 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002578 case k_RegisterList:
2579 case k_DPRRegisterList:
2580 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002581 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002582
Bill Wendlingbed94652010-11-09 23:28:44 +00002583 const SmallVectorImpl<unsigned> &RegList = getRegList();
2584 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002585 I = RegList.begin(), E = RegList.end(); I != E; ) {
2586 OS << *I;
2587 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002588 }
2589
2590 OS << ">";
2591 break;
2592 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002593 case k_VectorList:
2594 OS << "<vector_list " << VectorList.Count << " * "
2595 << VectorList.RegNum << ">";
2596 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002597 case k_VectorListAllLanes:
2598 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2599 << VectorList.RegNum << ">";
2600 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002601 case k_VectorListIndexed:
2602 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2603 << VectorList.Count << " * " << VectorList.RegNum << ">";
2604 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002605 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002606 OS << "'" << getToken() << "'";
2607 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002608 case k_VectorIndex:
2609 OS << "<vectorindex " << getVectorIndex() << ">";
2610 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002611 }
2612}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002613
2614/// @name Auto-generated Match Functions
2615/// {
2616
2617static unsigned MatchRegisterName(StringRef Name);
2618
2619/// }
2620
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002621bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2622 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002623 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002624 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002625 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002626
2627 return (RegNo == (unsigned)-1);
2628}
2629
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002630/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002631/// and if it is a register name the token is eaten and the register number is
2632/// returned. Otherwise return -1.
2633///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002634int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002635 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002636 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002637
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002638 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002639 unsigned RegNum = MatchRegisterName(lowerCase);
2640 if (!RegNum) {
2641 RegNum = StringSwitch<unsigned>(lowerCase)
2642 .Case("r13", ARM::SP)
2643 .Case("r14", ARM::LR)
2644 .Case("r15", ARM::PC)
2645 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002646 // Additional register name aliases for 'gas' compatibility.
2647 .Case("a1", ARM::R0)
2648 .Case("a2", ARM::R1)
2649 .Case("a3", ARM::R2)
2650 .Case("a4", ARM::R3)
2651 .Case("v1", ARM::R4)
2652 .Case("v2", ARM::R5)
2653 .Case("v3", ARM::R6)
2654 .Case("v4", ARM::R7)
2655 .Case("v5", ARM::R8)
2656 .Case("v6", ARM::R9)
2657 .Case("v7", ARM::R10)
2658 .Case("v8", ARM::R11)
2659 .Case("sb", ARM::R9)
2660 .Case("sl", ARM::R10)
2661 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002662 .Default(0);
2663 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002664 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002665 // Check for aliases registered via .req. Canonicalize to lower case.
2666 // That's more consistent since register names are case insensitive, and
2667 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2668 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002669 // If no match, return failure.
2670 if (Entry == RegisterReqs.end())
2671 return -1;
2672 Parser.Lex(); // Eat identifier token.
2673 return Entry->getValue();
2674 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002675
Chris Lattner44e5981c2010-10-30 04:09:10 +00002676 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002677
Chris Lattner44e5981c2010-10-30 04:09:10 +00002678 return RegNum;
2679}
Jim Grosbach99710a82010-11-01 16:44:21 +00002680
Jim Grosbachbb24c592011-07-13 18:49:30 +00002681// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2682// If a recoverable error occurs, return 1. If an irrecoverable error
2683// occurs, return -1. An irrecoverable error is one where tokens have been
2684// consumed in the process of trying to parse the shifter (i.e., when it is
2685// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002686int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002687 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2688 SMLoc S = Parser.getTok().getLoc();
2689 const AsmToken &Tok = Parser.getTok();
2690 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2691
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002692 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002693 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002694 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002695 .Case("lsl", ARM_AM::lsl)
2696 .Case("lsr", ARM_AM::lsr)
2697 .Case("asr", ARM_AM::asr)
2698 .Case("ror", ARM_AM::ror)
2699 .Case("rrx", ARM_AM::rrx)
2700 .Default(ARM_AM::no_shift);
2701
2702 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002703 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002704
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002705 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002706
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002707 // The source register for the shift has already been added to the
2708 // operand list, so we need to pop it off and combine it into the shifted
2709 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002710 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002711 if (!PrevOp->isReg())
2712 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2713 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002714
2715 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002716 int64_t Imm = 0;
2717 int ShiftReg = 0;
2718 if (ShiftTy == ARM_AM::rrx) {
2719 // RRX Doesn't have an explicit shift amount. The encoder expects
2720 // the shift register to be the same as the source register. Seems odd,
2721 // but OK.
2722 ShiftReg = SrcReg;
2723 } else {
2724 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002725 if (Parser.getTok().is(AsmToken::Hash) ||
2726 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002727 Parser.Lex(); // Eat hash.
2728 SMLoc ImmLoc = Parser.getTok().getLoc();
2729 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002730 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002731 Error(ImmLoc, "invalid immediate shift value");
2732 return -1;
2733 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002734 // The expression must be evaluatable as an immediate.
2735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002736 if (!CE) {
2737 Error(ImmLoc, "invalid immediate shift value");
2738 return -1;
2739 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002740 // Range check the immediate.
2741 // lsl, ror: 0 <= imm <= 31
2742 // lsr, asr: 0 <= imm <= 32
2743 Imm = CE->getValue();
2744 if (Imm < 0 ||
2745 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2746 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002747 Error(ImmLoc, "immediate shift value out of range");
2748 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002749 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002750 // shift by zero is a nop. Always send it through as lsl.
2751 // ('as' compatibility)
2752 if (Imm == 0)
2753 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002754 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002755 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002756 EndLoc = Parser.getTok().getEndLoc();
2757 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002758 if (ShiftReg == -1) {
2759 Error (L, "expected immediate or register in shift operand");
2760 return -1;
2761 }
2762 } else {
2763 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002764 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002765 return -1;
2766 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002767 }
2768
Owen Andersonb595ed02011-07-21 18:54:16 +00002769 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2770 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002771 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002772 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002773 else
2774 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002775 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002776
Jim Grosbachbb24c592011-07-13 18:49:30 +00002777 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002778}
2779
2780
Bill Wendling2063b842010-11-18 23:43:05 +00002781/// Try to parse a register name. The token must be an Identifier when called.
2782/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2783/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002784///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002785/// TODO this is likely to change to allow different register types and or to
2786/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002787bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002788tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002789 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002790 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002791 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002792 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002793
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002794 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2795 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002796
Chris Lattner44e5981c2010-10-30 04:09:10 +00002797 const AsmToken &ExclaimTok = Parser.getTok();
2798 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002799 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2800 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002801 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002802 return false;
2803 }
2804
2805 // Also check for an index operand. This is only legal for vector registers,
2806 // but that'll get caught OK in operand matching, so we don't need to
2807 // explicitly filter everything else out here.
2808 if (Parser.getTok().is(AsmToken::LBrac)) {
2809 SMLoc SIdx = Parser.getTok().getLoc();
2810 Parser.Lex(); // Eat left bracket token.
2811
2812 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002813 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002814 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002815 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002816 if (!MCE)
2817 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002818
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002819 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002820 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002821
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002822 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002823 Parser.Lex(); // Eat right bracket token.
2824
2825 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2826 SIdx, E,
2827 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002828 }
2829
Bill Wendling2063b842010-11-18 23:43:05 +00002830 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002831}
2832
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002833/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2834/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2835/// "c5", ...
2836static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002837 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2838 // but efficient.
2839 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002840 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002841 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002842 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002843 return -1;
2844 switch (Name[1]) {
2845 default: return -1;
2846 case '0': return 0;
2847 case '1': return 1;
2848 case '2': return 2;
2849 case '3': return 3;
2850 case '4': return 4;
2851 case '5': return 5;
2852 case '6': return 6;
2853 case '7': return 7;
2854 case '8': return 8;
2855 case '9': return 9;
2856 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002857 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002858 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002859 return -1;
2860 switch (Name[2]) {
2861 default: return -1;
2862 case '0': return 10;
2863 case '1': return 11;
2864 case '2': return 12;
2865 case '3': return 13;
2866 case '4': return 14;
2867 case '5': return 15;
2868 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002869 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002870}
2871
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002872/// parseITCondCode - Try to parse a condition code for an IT instruction.
2873ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2874parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2875 SMLoc S = Parser.getTok().getLoc();
2876 const AsmToken &Tok = Parser.getTok();
2877 if (!Tok.is(AsmToken::Identifier))
2878 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002879 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002880 .Case("eq", ARMCC::EQ)
2881 .Case("ne", ARMCC::NE)
2882 .Case("hs", ARMCC::HS)
2883 .Case("cs", ARMCC::HS)
2884 .Case("lo", ARMCC::LO)
2885 .Case("cc", ARMCC::LO)
2886 .Case("mi", ARMCC::MI)
2887 .Case("pl", ARMCC::PL)
2888 .Case("vs", ARMCC::VS)
2889 .Case("vc", ARMCC::VC)
2890 .Case("hi", ARMCC::HI)
2891 .Case("ls", ARMCC::LS)
2892 .Case("ge", ARMCC::GE)
2893 .Case("lt", ARMCC::LT)
2894 .Case("gt", ARMCC::GT)
2895 .Case("le", ARMCC::LE)
2896 .Case("al", ARMCC::AL)
2897 .Default(~0U);
2898 if (CC == ~0U)
2899 return MatchOperand_NoMatch;
2900 Parser.Lex(); // Eat the token.
2901
2902 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2903
2904 return MatchOperand_Success;
2905}
2906
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002907/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002908/// token must be an Identifier when called, and if it is a coprocessor
2909/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002910ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002911parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002912 SMLoc S = Parser.getTok().getLoc();
2913 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002914 if (Tok.isNot(AsmToken::Identifier))
2915 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002916
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002917 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002918 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002919 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002920
2921 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002922 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002923 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002924}
2925
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002926/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002927/// token must be an Identifier when called, and if it is a coprocessor
2928/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002929ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002930parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002931 SMLoc S = Parser.getTok().getLoc();
2932 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002933 if (Tok.isNot(AsmToken::Identifier))
2934 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002935
2936 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2937 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002938 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002939
2940 Parser.Lex(); // Eat identifier token.
2941 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002942 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002943}
2944
Jim Grosbach48399582011-10-12 17:34:41 +00002945/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2946/// coproc_option : '{' imm0_255 '}'
2947ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2948parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2949 SMLoc S = Parser.getTok().getLoc();
2950
2951 // If this isn't a '{', this isn't a coprocessor immediate operand.
2952 if (Parser.getTok().isNot(AsmToken::LCurly))
2953 return MatchOperand_NoMatch;
2954 Parser.Lex(); // Eat the '{'
2955
2956 const MCExpr *Expr;
2957 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002958 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002959 Error(Loc, "illegal expression");
2960 return MatchOperand_ParseFail;
2961 }
2962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2963 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2964 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2965 return MatchOperand_ParseFail;
2966 }
2967 int Val = CE->getValue();
2968
2969 // Check for and consume the closing '}'
2970 if (Parser.getTok().isNot(AsmToken::RCurly))
2971 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002972 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002973 Parser.Lex(); // Eat the '}'
2974
2975 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2976 return MatchOperand_Success;
2977}
2978
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002979// For register list parsing, we need to map from raw GPR register numbering
2980// to the enumeration values. The enumeration values aren't sorted by
2981// register number due to our using "sp", "lr" and "pc" as canonical names.
2982static unsigned getNextRegister(unsigned Reg) {
2983 // If this is a GPR, we need to do it manually, otherwise we can rely
2984 // on the sort ordering of the enumeration since the other reg-classes
2985 // are sane.
2986 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2987 return Reg + 1;
2988 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002989 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002990 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2991 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2992 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2993 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2994 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2995 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2996 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2997 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2998 }
2999}
3000
Jim Grosbach85a23432011-11-11 21:27:40 +00003001// Return the low-subreg of a given Q register.
3002static unsigned getDRegFromQReg(unsigned QReg) {
3003 switch (QReg) {
3004 default: llvm_unreachable("expected a Q register!");
3005 case ARM::Q0: return ARM::D0;
3006 case ARM::Q1: return ARM::D2;
3007 case ARM::Q2: return ARM::D4;
3008 case ARM::Q3: return ARM::D6;
3009 case ARM::Q4: return ARM::D8;
3010 case ARM::Q5: return ARM::D10;
3011 case ARM::Q6: return ARM::D12;
3012 case ARM::Q7: return ARM::D14;
3013 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003014 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003015 case ARM::Q10: return ARM::D20;
3016 case ARM::Q11: return ARM::D22;
3017 case ARM::Q12: return ARM::D24;
3018 case ARM::Q13: return ARM::D26;
3019 case ARM::Q14: return ARM::D28;
3020 case ARM::Q15: return ARM::D30;
3021 }
3022}
3023
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003024/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003025bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003026parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003027 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003028 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003029 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003030 Parser.Lex(); // Eat '{' token.
3031 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003032
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003033 // Check the first register in the list to see what register class
3034 // this is a list of.
3035 int Reg = tryParseRegister();
3036 if (Reg == -1)
3037 return Error(RegLoc, "register expected");
3038
Jim Grosbach85a23432011-11-11 21:27:40 +00003039 // The reglist instructions have at most 16 registers, so reserve
3040 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003041 int EReg = 0;
3042 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003043
3044 // Allow Q regs and just interpret them as the two D sub-registers.
3045 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3046 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003047 EReg = MRI->getEncodingValue(Reg);
3048 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003049 ++Reg;
3050 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003051 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003052 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3053 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3054 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3055 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3056 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3057 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3058 else
3059 return Error(RegLoc, "invalid register in register list");
3060
Jim Grosbach85a23432011-11-11 21:27:40 +00003061 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003062 EReg = MRI->getEncodingValue(Reg);
3063 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003064
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003065 // This starts immediately after the first register token in the list,
3066 // so we can see either a comma or a minus (range separator) as a legal
3067 // next token.
3068 while (Parser.getTok().is(AsmToken::Comma) ||
3069 Parser.getTok().is(AsmToken::Minus)) {
3070 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003071 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003072 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003073 int EndReg = tryParseRegister();
3074 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003075 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003076 // Allow Q regs and just interpret them as the two D sub-registers.
3077 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3078 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003079 // If the register is the same as the start reg, there's nothing
3080 // more to do.
3081 if (Reg == EndReg)
3082 continue;
3083 // The register must be in the same register class as the first.
3084 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003085 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003086 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003087 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003088 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003089
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003090 // Add all the registers in the range to the register list.
3091 while (Reg != EndReg) {
3092 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003093 EReg = MRI->getEncodingValue(Reg);
3094 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003095 }
3096 continue;
3097 }
3098 Parser.Lex(); // Eat the comma.
3099 RegLoc = Parser.getTok().getLoc();
3100 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003101 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003102 Reg = tryParseRegister();
3103 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003104 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003105 // Allow Q regs and just interpret them as the two D sub-registers.
3106 bool isQReg = false;
3107 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3108 Reg = getDRegFromQReg(Reg);
3109 isQReg = true;
3110 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003111 // The register must be in the same register class as the first.
3112 if (!RC->contains(Reg))
3113 return Error(RegLoc, "invalid register in register list");
3114 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003115 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003116 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3117 Warning(RegLoc, "register list not in ascending order");
3118 else
3119 return Error(RegLoc, "register list not in ascending order");
3120 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003121 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003122 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3123 ") in register list");
3124 continue;
3125 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003126 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003127 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3128 Reg != OldReg + 1)
3129 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003130 EReg = MRI->getEncodingValue(Reg);
3131 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3132 if (isQReg) {
3133 EReg = MRI->getEncodingValue(++Reg);
3134 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3135 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003136 }
3137
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003138 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003139 return Error(Parser.getTok().getLoc(), "'}' expected");
3140 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003141 Parser.Lex(); // Eat '}' token.
3142
Jim Grosbach18bf3632011-12-13 21:48:29 +00003143 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003144 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003145
3146 // The ARM system instruction variants for LDM/STM have a '^' token here.
3147 if (Parser.getTok().is(AsmToken::Caret)) {
3148 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3149 Parser.Lex(); // Eat '^' token.
3150 }
3151
Bill Wendling2063b842010-11-18 23:43:05 +00003152 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003153}
3154
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003155// Helper function to parse the lane index for vector lists.
3156ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003157parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003158 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003159 if (Parser.getTok().is(AsmToken::LBrac)) {
3160 Parser.Lex(); // Eat the '['.
3161 if (Parser.getTok().is(AsmToken::RBrac)) {
3162 // "Dn[]" is the 'all lanes' syntax.
3163 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003164 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003165 Parser.Lex(); // Eat the ']'.
3166 return MatchOperand_Success;
3167 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003168
3169 // There's an optional '#' token here. Normally there wouldn't be, but
3170 // inline assemble puts one in, and it's friendly to accept that.
3171 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003172 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003173
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003174 const MCExpr *LaneIndex;
3175 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003176 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003177 Error(Loc, "illegal expression");
3178 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003179 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003180 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3181 if (!CE) {
3182 Error(Loc, "lane index must be empty or an integer");
3183 return MatchOperand_ParseFail;
3184 }
3185 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3186 Error(Parser.getTok().getLoc(), "']' expected");
3187 return MatchOperand_ParseFail;
3188 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003189 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003190 Parser.Lex(); // Eat the ']'.
3191 int64_t Val = CE->getValue();
3192
3193 // FIXME: Make this range check context sensitive for .8, .16, .32.
3194 if (Val < 0 || Val > 7) {
3195 Error(Parser.getTok().getLoc(), "lane index out of range");
3196 return MatchOperand_ParseFail;
3197 }
3198 Index = Val;
3199 LaneKind = IndexedLane;
3200 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003201 }
3202 LaneKind = NoLanes;
3203 return MatchOperand_Success;
3204}
3205
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003206// parse a vector register list
3207ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3208parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003209 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003210 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003211 SMLoc S = Parser.getTok().getLoc();
3212 // As an extension (to match gas), support a plain D register or Q register
3213 // (without encosing curly braces) as a single or double entry list,
3214 // respectively.
3215 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003216 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003217 int Reg = tryParseRegister();
3218 if (Reg == -1)
3219 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003220 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003221 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003222 if (Res != MatchOperand_Success)
3223 return Res;
3224 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003225 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003226 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003227 break;
3228 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003229 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3230 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003231 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003232 case IndexedLane:
3233 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003234 LaneIndex,
3235 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003236 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003237 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003238 return MatchOperand_Success;
3239 }
3240 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3241 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003242 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003243 if (Res != MatchOperand_Success)
3244 return Res;
3245 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003246 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003247 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003248 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003249 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003250 break;
3251 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003252 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3253 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003254 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3255 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003256 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003257 case IndexedLane:
3258 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003259 LaneIndex,
3260 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003261 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003262 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003263 return MatchOperand_Success;
3264 }
3265 Error(S, "vector register expected");
3266 return MatchOperand_ParseFail;
3267 }
3268
3269 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003270 return MatchOperand_NoMatch;
3271
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003272 Parser.Lex(); // Eat '{' token.
3273 SMLoc RegLoc = Parser.getTok().getLoc();
3274
3275 int Reg = tryParseRegister();
3276 if (Reg == -1) {
3277 Error(RegLoc, "register expected");
3278 return MatchOperand_ParseFail;
3279 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003280 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003281 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003282 unsigned FirstReg = Reg;
3283 // The list is of D registers, but we also allow Q regs and just interpret
3284 // them as the two D sub-registers.
3285 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3286 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003287 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3288 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003289 ++Reg;
3290 ++Count;
3291 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003292
3293 SMLoc E;
3294 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003295 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003296
Jim Grosbache891fe82011-11-15 23:19:15 +00003297 while (Parser.getTok().is(AsmToken::Comma) ||
3298 Parser.getTok().is(AsmToken::Minus)) {
3299 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003300 if (!Spacing)
3301 Spacing = 1; // Register range implies a single spaced list.
3302 else if (Spacing == 2) {
3303 Error(Parser.getTok().getLoc(),
3304 "sequential registers in double spaced list");
3305 return MatchOperand_ParseFail;
3306 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003307 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003308 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003309 int EndReg = tryParseRegister();
3310 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003311 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003312 return MatchOperand_ParseFail;
3313 }
3314 // Allow Q regs and just interpret them as the two D sub-registers.
3315 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3316 EndReg = getDRegFromQReg(EndReg) + 1;
3317 // If the register is the same as the start reg, there's nothing
3318 // more to do.
3319 if (Reg == EndReg)
3320 continue;
3321 // The register must be in the same register class as the first.
3322 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003323 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003324 return MatchOperand_ParseFail;
3325 }
3326 // Ranges must go from low to high.
3327 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003328 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003329 return MatchOperand_ParseFail;
3330 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003331 // Parse the lane specifier if present.
3332 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003333 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003334 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3335 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003336 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003337 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003338 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003339 return MatchOperand_ParseFail;
3340 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003341
3342 // Add all the registers in the range to the register list.
3343 Count += EndReg - Reg;
3344 Reg = EndReg;
3345 continue;
3346 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003347 Parser.Lex(); // Eat the comma.
3348 RegLoc = Parser.getTok().getLoc();
3349 int OldReg = Reg;
3350 Reg = tryParseRegister();
3351 if (Reg == -1) {
3352 Error(RegLoc, "register expected");
3353 return MatchOperand_ParseFail;
3354 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003355 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003356 // It's OK to use the enumeration values directly here rather, as the
3357 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003358 //
3359 // The list is of D registers, but we also allow Q regs and just interpret
3360 // them as the two D sub-registers.
3361 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003362 if (!Spacing)
3363 Spacing = 1; // Register range implies a single spaced list.
3364 else if (Spacing == 2) {
3365 Error(RegLoc,
3366 "invalid register in double-spaced list (must be 'D' register')");
3367 return MatchOperand_ParseFail;
3368 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003369 Reg = getDRegFromQReg(Reg);
3370 if (Reg != OldReg + 1) {
3371 Error(RegLoc, "non-contiguous register range");
3372 return MatchOperand_ParseFail;
3373 }
3374 ++Reg;
3375 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 // Parse the lane specifier if present.
3377 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003378 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003379 SMLoc LaneLoc = Parser.getTok().getLoc();
3380 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3381 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003382 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003383 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003384 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003385 return MatchOperand_ParseFail;
3386 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003387 continue;
3388 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003389 // Normal D register.
3390 // Figure out the register spacing (single or double) of the list if
3391 // we don't know it already.
3392 if (!Spacing)
3393 Spacing = 1 + (Reg == OldReg + 2);
3394
3395 // Just check that it's contiguous and keep going.
3396 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003397 Error(RegLoc, "non-contiguous register range");
3398 return MatchOperand_ParseFail;
3399 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003400 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003401 // Parse the lane specifier if present.
3402 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003403 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003404 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003405 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003406 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003407 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003408 Error(EndLoc, "mismatched lane index in register list");
3409 return MatchOperand_ParseFail;
3410 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003411 }
3412
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003413 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003414 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003415 return MatchOperand_ParseFail;
3416 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003417 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003418 Parser.Lex(); // Eat '}' token.
3419
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003420 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003421 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003422 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003423 // composite register classes.
3424 if (Count == 2) {
3425 const MCRegisterClass *RC = (Spacing == 1) ?
3426 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3427 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3428 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3429 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003430
Jim Grosbach2f50e922011-12-15 21:44:33 +00003431 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3432 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003433 break;
3434 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003435 // Two-register operands have been converted to the
3436 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003437 if (Count == 2) {
3438 const MCRegisterClass *RC = (Spacing == 1) ?
3439 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3440 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003441 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3442 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003443 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003444 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003445 S, E));
3446 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003447 case IndexedLane:
3448 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003449 LaneIndex,
3450 (Spacing == 2),
3451 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003452 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003453 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003454 return MatchOperand_Success;
3455}
3456
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003457/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003458ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003459parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003460 SMLoc S = Parser.getTok().getLoc();
3461 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003462 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003463
Jiangning Liu288e1af2012-08-02 08:21:27 +00003464 if (Tok.is(AsmToken::Identifier)) {
3465 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003466
Jiangning Liu288e1af2012-08-02 08:21:27 +00003467 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3468 .Case("sy", ARM_MB::SY)
3469 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003470 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003471 .Case("sh", ARM_MB::ISH)
3472 .Case("ish", ARM_MB::ISH)
3473 .Case("shst", ARM_MB::ISHST)
3474 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003475 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003476 .Case("nsh", ARM_MB::NSH)
3477 .Case("un", ARM_MB::NSH)
3478 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003479 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003480 .Case("unst", ARM_MB::NSHST)
3481 .Case("osh", ARM_MB::OSH)
3482 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003483 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003484 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003485
Joey Gouly926d3f52013-09-05 15:35:24 +00003486 // ishld, oshld, nshld and ld are only available from ARMv8.
3487 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3488 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3489 Opt = ~0U;
3490
Jiangning Liu288e1af2012-08-02 08:21:27 +00003491 if (Opt == ~0U)
3492 return MatchOperand_NoMatch;
3493
3494 Parser.Lex(); // Eat identifier token.
3495 } else if (Tok.is(AsmToken::Hash) ||
3496 Tok.is(AsmToken::Dollar) ||
3497 Tok.is(AsmToken::Integer)) {
3498 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003499 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003500 SMLoc Loc = Parser.getTok().getLoc();
3501
3502 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003503 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003504 Error(Loc, "illegal expression");
3505 return MatchOperand_ParseFail;
3506 }
3507
3508 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3509 if (!CE) {
3510 Error(Loc, "constant expression expected");
3511 return MatchOperand_ParseFail;
3512 }
3513
3514 int Val = CE->getValue();
3515 if (Val & ~0xf) {
3516 Error(Loc, "immediate value out of range");
3517 return MatchOperand_ParseFail;
3518 }
3519
3520 Opt = ARM_MB::RESERVED_0 + Val;
3521 } else
3522 return MatchOperand_ParseFail;
3523
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003524 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003525 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003526}
3527
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003528/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3529ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3530parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3531 SMLoc S = Parser.getTok().getLoc();
3532 const AsmToken &Tok = Parser.getTok();
3533 unsigned Opt;
3534
3535 if (Tok.is(AsmToken::Identifier)) {
3536 StringRef OptStr = Tok.getString();
3537
3538 if (OptStr.lower() == "sy")
3539 Opt = ARM_ISB::SY;
3540 else
3541 return MatchOperand_NoMatch;
3542
3543 Parser.Lex(); // Eat identifier token.
3544 } else if (Tok.is(AsmToken::Hash) ||
3545 Tok.is(AsmToken::Dollar) ||
3546 Tok.is(AsmToken::Integer)) {
3547 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003548 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003549 SMLoc Loc = Parser.getTok().getLoc();
3550
3551 const MCExpr *ISBarrierID;
3552 if (getParser().parseExpression(ISBarrierID)) {
3553 Error(Loc, "illegal expression");
3554 return MatchOperand_ParseFail;
3555 }
3556
3557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3558 if (!CE) {
3559 Error(Loc, "constant expression expected");
3560 return MatchOperand_ParseFail;
3561 }
3562
3563 int Val = CE->getValue();
3564 if (Val & ~0xf) {
3565 Error(Loc, "immediate value out of range");
3566 return MatchOperand_ParseFail;
3567 }
3568
3569 Opt = ARM_ISB::RESERVED_0 + Val;
3570 } else
3571 return MatchOperand_ParseFail;
3572
3573 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3574 (ARM_ISB::InstSyncBOpt)Opt, S));
3575 return MatchOperand_Success;
3576}
3577
3578
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003579/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003580ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003581parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003582 SMLoc S = Parser.getTok().getLoc();
3583 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003584 if (!Tok.is(AsmToken::Identifier))
3585 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003586 StringRef IFlagsStr = Tok.getString();
3587
Owen Anderson10c5b122011-10-05 17:16:40 +00003588 // An iflags string of "none" is interpreted to mean that none of the AIF
3589 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003590 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003591 if (IFlagsStr != "none") {
3592 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3593 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3594 .Case("a", ARM_PROC::A)
3595 .Case("i", ARM_PROC::I)
3596 .Case("f", ARM_PROC::F)
3597 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003598
Owen Anderson10c5b122011-10-05 17:16:40 +00003599 // If some specific iflag is already set, it means that some letter is
3600 // present more than once, this is not acceptable.
3601 if (Flag == ~0U || (IFlags & Flag))
3602 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003603
Owen Anderson10c5b122011-10-05 17:16:40 +00003604 IFlags |= Flag;
3605 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003606 }
3607
3608 Parser.Lex(); // Eat identifier token.
3609 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3610 return MatchOperand_Success;
3611}
3612
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003613/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003614ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003615parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003616 SMLoc S = Parser.getTok().getLoc();
3617 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003618 if (!Tok.is(AsmToken::Identifier))
3619 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003620 StringRef Mask = Tok.getString();
3621
James Molloy21efa7d2011-09-28 14:21:38 +00003622 if (isMClass()) {
3623 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003624 std::string Name = Mask.lower();
3625 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003626 // Note: in the documentation:
3627 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3628 // for MSR APSR_nzcvq.
3629 // but we do make it an alias here. This is so to get the "mask encoding"
3630 // bits correct on MSR APSR writes.
3631 //
3632 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3633 // should really only be allowed when writing a special register. Note
3634 // they get dropped in the MRS instruction reading a special register as
3635 // the SYSm field is only 8 bits.
3636 //
3637 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3638 // includes the DSP extension but that is not checked.
3639 .Case("apsr", 0x800)
3640 .Case("apsr_nzcvq", 0x800)
3641 .Case("apsr_g", 0x400)
3642 .Case("apsr_nzcvqg", 0xc00)
3643 .Case("iapsr", 0x801)
3644 .Case("iapsr_nzcvq", 0x801)
3645 .Case("iapsr_g", 0x401)
3646 .Case("iapsr_nzcvqg", 0xc01)
3647 .Case("eapsr", 0x802)
3648 .Case("eapsr_nzcvq", 0x802)
3649 .Case("eapsr_g", 0x402)
3650 .Case("eapsr_nzcvqg", 0xc02)
3651 .Case("xpsr", 0x803)
3652 .Case("xpsr_nzcvq", 0x803)
3653 .Case("xpsr_g", 0x403)
3654 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003655 .Case("ipsr", 0x805)
3656 .Case("epsr", 0x806)
3657 .Case("iepsr", 0x807)
3658 .Case("msp", 0x808)
3659 .Case("psp", 0x809)
3660 .Case("primask", 0x810)
3661 .Case("basepri", 0x811)
3662 .Case("basepri_max", 0x812)
3663 .Case("faultmask", 0x813)
3664 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003665 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003666
James Molloy21efa7d2011-09-28 14:21:38 +00003667 if (FlagsVal == ~0U)
3668 return MatchOperand_NoMatch;
3669
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003670 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003671 // basepri, basepri_max and faultmask only valid for V7m.
3672 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003673
James Molloy21efa7d2011-09-28 14:21:38 +00003674 Parser.Lex(); // Eat identifier token.
3675 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3676 return MatchOperand_Success;
3677 }
3678
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003679 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3680 size_t Start = 0, Next = Mask.find('_');
3681 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003682 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003683 if (Next != StringRef::npos)
3684 Flags = Mask.slice(Next+1, Mask.size());
3685
3686 // FlagsVal contains the complete mask:
3687 // 3-0: Mask
3688 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3689 unsigned FlagsVal = 0;
3690
3691 if (SpecReg == "apsr") {
3692 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003693 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003694 .Case("g", 0x4) // same as CPSR_s
3695 .Case("nzcvqg", 0xc) // same as CPSR_fs
3696 .Default(~0U);
3697
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003698 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003699 if (!Flags.empty())
3700 return MatchOperand_NoMatch;
3701 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003702 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003703 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003704 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003705 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3706 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003707 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003708 for (int i = 0, e = Flags.size(); i != e; ++i) {
3709 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3710 .Case("c", 1)
3711 .Case("x", 2)
3712 .Case("s", 4)
3713 .Case("f", 8)
3714 .Default(~0U);
3715
3716 // If some specific flag is already set, it means that some letter is
3717 // present more than once, this is not acceptable.
3718 if (FlagsVal == ~0U || (FlagsVal & Flag))
3719 return MatchOperand_NoMatch;
3720 FlagsVal |= Flag;
3721 }
3722 } else // No match for special register.
3723 return MatchOperand_NoMatch;
3724
Owen Anderson03a173e2011-10-21 18:43:28 +00003725 // Special register without flags is NOT equivalent to "fc" flags.
3726 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3727 // two lines would enable gas compatibility at the expense of breaking
3728 // round-tripping.
3729 //
3730 // if (!FlagsVal)
3731 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003732
3733 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3734 if (SpecReg == "spsr")
3735 FlagsVal |= 16;
3736
3737 Parser.Lex(); // Eat identifier token.
3738 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3739 return MatchOperand_Success;
3740}
3741
Jim Grosbach27c1e252011-07-21 17:23:04 +00003742ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3743parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3744 int Low, int High) {
3745 const AsmToken &Tok = Parser.getTok();
3746 if (Tok.isNot(AsmToken::Identifier)) {
3747 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3748 return MatchOperand_ParseFail;
3749 }
3750 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003751 std::string LowerOp = Op.lower();
3752 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003753 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3754 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3755 return MatchOperand_ParseFail;
3756 }
3757 Parser.Lex(); // Eat shift type token.
3758
3759 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003760 if (Parser.getTok().isNot(AsmToken::Hash) &&
3761 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003762 Error(Parser.getTok().getLoc(), "'#' expected");
3763 return MatchOperand_ParseFail;
3764 }
3765 Parser.Lex(); // Eat hash token.
3766
3767 const MCExpr *ShiftAmount;
3768 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003769 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003770 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003771 Error(Loc, "illegal expression");
3772 return MatchOperand_ParseFail;
3773 }
3774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3775 if (!CE) {
3776 Error(Loc, "constant expression expected");
3777 return MatchOperand_ParseFail;
3778 }
3779 int Val = CE->getValue();
3780 if (Val < Low || Val > High) {
3781 Error(Loc, "immediate value out of range");
3782 return MatchOperand_ParseFail;
3783 }
3784
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003785 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003786
3787 return MatchOperand_Success;
3788}
3789
Jim Grosbach0a547702011-07-22 17:44:50 +00003790ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3791parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3792 const AsmToken &Tok = Parser.getTok();
3793 SMLoc S = Tok.getLoc();
3794 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003795 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003796 return MatchOperand_ParseFail;
3797 }
Tim Northover4d141442013-05-31 15:58:45 +00003798 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003799 .Case("be", 1)
3800 .Case("le", 0)
3801 .Default(-1);
3802 Parser.Lex(); // Eat the token.
3803
3804 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003805 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003806 return MatchOperand_ParseFail;
3807 }
3808 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3809 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003810 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003811 return MatchOperand_Success;
3812}
3813
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003814/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3815/// instructions. Legal values are:
3816/// lsl #n 'n' in [0,31]
3817/// asr #n 'n' in [1,32]
3818/// n == 32 encoded as n == 0.
3819ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3820parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3821 const AsmToken &Tok = Parser.getTok();
3822 SMLoc S = Tok.getLoc();
3823 if (Tok.isNot(AsmToken::Identifier)) {
3824 Error(S, "shift operator 'asr' or 'lsl' expected");
3825 return MatchOperand_ParseFail;
3826 }
3827 StringRef ShiftName = Tok.getString();
3828 bool isASR;
3829 if (ShiftName == "lsl" || ShiftName == "LSL")
3830 isASR = false;
3831 else if (ShiftName == "asr" || ShiftName == "ASR")
3832 isASR = true;
3833 else {
3834 Error(S, "shift operator 'asr' or 'lsl' expected");
3835 return MatchOperand_ParseFail;
3836 }
3837 Parser.Lex(); // Eat the operator.
3838
3839 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003840 if (Parser.getTok().isNot(AsmToken::Hash) &&
3841 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003842 Error(Parser.getTok().getLoc(), "'#' expected");
3843 return MatchOperand_ParseFail;
3844 }
3845 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003846 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003847
3848 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003849 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003850 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003851 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003852 return MatchOperand_ParseFail;
3853 }
3854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3855 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003856 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003857 return MatchOperand_ParseFail;
3858 }
3859
3860 int64_t Val = CE->getValue();
3861 if (isASR) {
3862 // Shift amount must be in [1,32]
3863 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003864 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003865 return MatchOperand_ParseFail;
3866 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003867 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3868 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003869 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003870 return MatchOperand_ParseFail;
3871 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003872 if (Val == 32) Val = 0;
3873 } else {
3874 // Shift amount must be in [1,32]
3875 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003876 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003877 return MatchOperand_ParseFail;
3878 }
3879 }
3880
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003881 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003882
3883 return MatchOperand_Success;
3884}
3885
Jim Grosbach833b9d32011-07-27 20:15:40 +00003886/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3887/// of instructions. Legal values are:
3888/// ror #n 'n' in {0, 8, 16, 24}
3889ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3890parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3891 const AsmToken &Tok = Parser.getTok();
3892 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003893 if (Tok.isNot(AsmToken::Identifier))
3894 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003895 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003896 if (ShiftName != "ror" && ShiftName != "ROR")
3897 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003898 Parser.Lex(); // Eat the operator.
3899
3900 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003901 if (Parser.getTok().isNot(AsmToken::Hash) &&
3902 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003903 Error(Parser.getTok().getLoc(), "'#' expected");
3904 return MatchOperand_ParseFail;
3905 }
3906 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003907 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003908
3909 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003910 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003911 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003912 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003913 return MatchOperand_ParseFail;
3914 }
3915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3916 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003917 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003918 return MatchOperand_ParseFail;
3919 }
3920
3921 int64_t Val = CE->getValue();
3922 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3923 // normally, zero is represented in asm by omitting the rotate operand
3924 // entirely.
3925 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003926 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003927 return MatchOperand_ParseFail;
3928 }
3929
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003930 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003931
3932 return MatchOperand_Success;
3933}
3934
Jim Grosbach864b6092011-07-28 21:34:26 +00003935ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3936parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3937 SMLoc S = Parser.getTok().getLoc();
3938 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003939 if (Parser.getTok().isNot(AsmToken::Hash) &&
3940 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003941 Error(Parser.getTok().getLoc(), "'#' expected");
3942 return MatchOperand_ParseFail;
3943 }
3944 Parser.Lex(); // Eat hash token.
3945
3946 const MCExpr *LSBExpr;
3947 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003948 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003949 Error(E, "malformed immediate expression");
3950 return MatchOperand_ParseFail;
3951 }
3952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3953 if (!CE) {
3954 Error(E, "'lsb' operand must be an immediate");
3955 return MatchOperand_ParseFail;
3956 }
3957
3958 int64_t LSB = CE->getValue();
3959 // The LSB must be in the range [0,31]
3960 if (LSB < 0 || LSB > 31) {
3961 Error(E, "'lsb' operand must be in the range [0,31]");
3962 return MatchOperand_ParseFail;
3963 }
3964 E = Parser.getTok().getLoc();
3965
3966 // Expect another immediate operand.
3967 if (Parser.getTok().isNot(AsmToken::Comma)) {
3968 Error(Parser.getTok().getLoc(), "too few operands");
3969 return MatchOperand_ParseFail;
3970 }
3971 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003972 if (Parser.getTok().isNot(AsmToken::Hash) &&
3973 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003974 Error(Parser.getTok().getLoc(), "'#' expected");
3975 return MatchOperand_ParseFail;
3976 }
3977 Parser.Lex(); // Eat hash token.
3978
3979 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003980 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003981 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003982 Error(E, "malformed immediate expression");
3983 return MatchOperand_ParseFail;
3984 }
3985 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3986 if (!CE) {
3987 Error(E, "'width' operand must be an immediate");
3988 return MatchOperand_ParseFail;
3989 }
3990
3991 int64_t Width = CE->getValue();
3992 // The LSB must be in the range [1,32-lsb]
3993 if (Width < 1 || Width > 32 - LSB) {
3994 Error(E, "'width' operand must be in the range [1,32-lsb]");
3995 return MatchOperand_ParseFail;
3996 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003997
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003998 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003999
4000 return MatchOperand_Success;
4001}
4002
Jim Grosbachd3595712011-08-03 23:50:40 +00004003ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4004parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4005 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004006 // postidx_reg := '+' register {, shift}
4007 // | '-' register {, shift}
4008 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004009
4010 // This method must return MatchOperand_NoMatch without consuming any tokens
4011 // in the case where there is no match, as other alternatives take other
4012 // parse methods.
4013 AsmToken Tok = Parser.getTok();
4014 SMLoc S = Tok.getLoc();
4015 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004016 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004017 if (Tok.is(AsmToken::Plus)) {
4018 Parser.Lex(); // Eat the '+' token.
4019 haveEaten = true;
4020 } else if (Tok.is(AsmToken::Minus)) {
4021 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004022 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004023 haveEaten = true;
4024 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004025
4026 SMLoc E = Parser.getTok().getEndLoc();
4027 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004028 if (Reg == -1) {
4029 if (!haveEaten)
4030 return MatchOperand_NoMatch;
4031 Error(Parser.getTok().getLoc(), "register expected");
4032 return MatchOperand_ParseFail;
4033 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004034
Jim Grosbachc320c852011-08-05 21:28:30 +00004035 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4036 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004037 if (Parser.getTok().is(AsmToken::Comma)) {
4038 Parser.Lex(); // Eat the ','.
4039 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4040 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004041
4042 // FIXME: Only approximates end...may include intervening whitespace.
4043 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004044 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004045
4046 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4047 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004048
4049 return MatchOperand_Success;
4050}
4051
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004052ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4053parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4054 // Check for a post-index addressing register operand. Specifically:
4055 // am3offset := '+' register
4056 // | '-' register
4057 // | register
4058 // | # imm
4059 // | # + imm
4060 // | # - imm
4061
4062 // This method must return MatchOperand_NoMatch without consuming any tokens
4063 // in the case where there is no match, as other alternatives take other
4064 // parse methods.
4065 AsmToken Tok = Parser.getTok();
4066 SMLoc S = Tok.getLoc();
4067
4068 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004069 if (Parser.getTok().is(AsmToken::Hash) ||
4070 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004071 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004072 // Explicitly look for a '-', as we need to encode negative zero
4073 // differently.
4074 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4075 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004076 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004077 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004078 return MatchOperand_ParseFail;
4079 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4080 if (!CE) {
4081 Error(S, "constant expression expected");
4082 return MatchOperand_ParseFail;
4083 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004084 // Negative zero is encoded as the flag value INT32_MIN.
4085 int32_t Val = CE->getValue();
4086 if (isNegative && Val == 0)
4087 Val = INT32_MIN;
4088
4089 Operands.push_back(
4090 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4091
4092 return MatchOperand_Success;
4093 }
4094
4095
4096 bool haveEaten = false;
4097 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004098 if (Tok.is(AsmToken::Plus)) {
4099 Parser.Lex(); // Eat the '+' token.
4100 haveEaten = true;
4101 } else if (Tok.is(AsmToken::Minus)) {
4102 Parser.Lex(); // Eat the '-' token.
4103 isAdd = false;
4104 haveEaten = true;
4105 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004106
4107 Tok = Parser.getTok();
4108 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004109 if (Reg == -1) {
4110 if (!haveEaten)
4111 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004112 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004113 return MatchOperand_ParseFail;
4114 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004115
4116 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004117 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004118
4119 return MatchOperand_Success;
4120}
4121
Tim Northovereb5e4d52013-07-22 09:06:12 +00004122/// Convert parsed operands to MCInst. Needed here because this instruction
4123/// only has two register operands, but multiplication is commutative so
4124/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004125void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004126cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004127 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004128 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4129 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004130 // If we have a three-operand form, make sure to set Rn to be the operand
4131 // that isn't the same as Rd.
4132 unsigned RegOp = 4;
4133 if (Operands.size() == 6 &&
4134 ((ARMOperand*)Operands[4])->getReg() ==
4135 ((ARMOperand*)Operands[3])->getReg())
4136 RegOp = 5;
4137 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4138 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004139 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004140}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004141
Mihai Popaad18d3c2013-08-09 10:38:32 +00004142void ARMAsmParser::
4143cvtThumbBranches(MCInst &Inst,
4144 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4145 int CondOp = -1, ImmOp = -1;
4146 switch(Inst.getOpcode()) {
4147 case ARM::tB:
4148 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4149
4150 case ARM::t2B:
4151 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4152
4153 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4154 }
4155 // first decide whether or not the branch should be conditional
4156 // by looking at it's location relative to an IT block
4157 if(inITBlock()) {
4158 // inside an IT block we cannot have any conditional branches. any
4159 // such instructions needs to be converted to unconditional form
4160 switch(Inst.getOpcode()) {
4161 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4162 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4163 }
4164 } else {
4165 // outside IT blocks we can only have unconditional branches with AL
4166 // condition code or conditional branches with non-AL condition code
4167 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4168 switch(Inst.getOpcode()) {
4169 case ARM::tB:
4170 case ARM::tBcc:
4171 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4172 break;
4173 case ARM::t2B:
4174 case ARM::t2Bcc:
4175 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4176 break;
4177 }
4178 }
4179
4180 // now decide on encoding size based on branch target range
4181 switch(Inst.getOpcode()) {
4182 // classify tB as either t2B or t1B based on range of immediate operand
4183 case ARM::tB: {
4184 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4185 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4186 Inst.setOpcode(ARM::t2B);
4187 break;
4188 }
4189 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4190 case ARM::tBcc: {
4191 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4192 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4193 Inst.setOpcode(ARM::t2Bcc);
4194 break;
4195 }
4196 }
4197 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4198 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4199}
4200
Bill Wendlinge18980a2010-11-06 22:36:58 +00004201/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004202/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004203bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004204parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004205 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004206 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004207 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004208 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004209 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004210
Sean Callanan936b0d32010-01-19 21:44:56 +00004211 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004212 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004213 if (BaseRegNum == -1)
4214 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004215
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004216 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004217 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004218 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4219 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004220 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004221
Jim Grosbachd3595712011-08-03 23:50:40 +00004222 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004223 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004224 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004225
Jim Grosbachd3595712011-08-03 23:50:40 +00004226 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004227 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004228
Jim Grosbach40700e02011-09-19 18:42:21 +00004229 // If there's a pre-indexing writeback marker, '!', just add it as a token
4230 // operand. It's rather odd, but syntactically valid.
4231 if (Parser.getTok().is(AsmToken::Exclaim)) {
4232 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4233 Parser.Lex(); // Eat the '!'.
4234 }
4235
Jim Grosbachd3595712011-08-03 23:50:40 +00004236 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004237 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004238
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004239 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4240 "Lost colon or comma in memory operand?!");
4241 if (Tok.is(AsmToken::Comma)) {
4242 Parser.Lex(); // Eat the comma.
4243 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004244
Jim Grosbacha95ec992011-10-11 17:29:55 +00004245 // If we have a ':', it's an alignment specifier.
4246 if (Parser.getTok().is(AsmToken::Colon)) {
4247 Parser.Lex(); // Eat the ':'.
4248 E = Parser.getTok().getLoc();
4249
4250 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004251 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004252 return true;
4253
4254 // The expression has to be a constant. Memory references with relocations
4255 // don't come through here, as they use the <label> forms of the relevant
4256 // instructions.
4257 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4258 if (!CE)
4259 return Error (E, "constant expression expected");
4260
4261 unsigned Align = 0;
4262 switch (CE->getValue()) {
4263 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004264 return Error(E,
4265 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4266 case 16: Align = 2; break;
4267 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004268 case 64: Align = 8; break;
4269 case 128: Align = 16; break;
4270 case 256: Align = 32; break;
4271 }
4272
4273 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004274 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004275 return Error(Parser.getTok().getLoc(), "']' expected");
4276 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004277 Parser.Lex(); // Eat right bracket token.
4278
4279 // Don't worry about range checking the value here. That's handled by
4280 // the is*() predicates.
4281 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4282 ARM_AM::no_shift, 0, Align,
4283 false, S, E));
4284
4285 // If there's a pre-indexing writeback marker, '!', just add it as a token
4286 // operand.
4287 if (Parser.getTok().is(AsmToken::Exclaim)) {
4288 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4289 Parser.Lex(); // Eat the '!'.
4290 }
4291
4292 return false;
4293 }
4294
4295 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004296 // offset. Be friendly and also accept a plain integer (without a leading
4297 // hash) for gas compatibility.
4298 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004299 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004300 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004301 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004302 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004303 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004304
Owen Anderson967674d2011-08-29 19:36:44 +00004305 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004306 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004307 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004308 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004309
4310 // The expression has to be a constant. Memory references with relocations
4311 // don't come through here, as they use the <label> forms of the relevant
4312 // instructions.
4313 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4314 if (!CE)
4315 return Error (E, "constant expression expected");
4316
Owen Anderson967674d2011-08-29 19:36:44 +00004317 // If the constant was #-0, represent it as INT32_MIN.
4318 int32_t Val = CE->getValue();
4319 if (isNegative && Val == 0)
4320 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4321
Jim Grosbachd3595712011-08-03 23:50:40 +00004322 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004323 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004324 return Error(Parser.getTok().getLoc(), "']' expected");
4325 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004326 Parser.Lex(); // Eat right bracket token.
4327
4328 // Don't worry about range checking the value here. That's handled by
4329 // the is*() predicates.
4330 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004331 ARM_AM::no_shift, 0, 0,
4332 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004333
4334 // If there's a pre-indexing writeback marker, '!', just add it as a token
4335 // operand.
4336 if (Parser.getTok().is(AsmToken::Exclaim)) {
4337 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4338 Parser.Lex(); // Eat the '!'.
4339 }
4340
4341 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004342 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004343
4344 // The register offset is optionally preceded by a '+' or '-'
4345 bool isNegative = false;
4346 if (Parser.getTok().is(AsmToken::Minus)) {
4347 isNegative = true;
4348 Parser.Lex(); // Eat the '-'.
4349 } else if (Parser.getTok().is(AsmToken::Plus)) {
4350 // Nothing to do.
4351 Parser.Lex(); // Eat the '+'.
4352 }
4353
4354 E = Parser.getTok().getLoc();
4355 int OffsetRegNum = tryParseRegister();
4356 if (OffsetRegNum == -1)
4357 return Error(E, "register expected");
4358
4359 // If there's a shift operator, handle it.
4360 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004361 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004362 if (Parser.getTok().is(AsmToken::Comma)) {
4363 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004364 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004365 return true;
4366 }
4367
4368 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004369 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004370 return Error(Parser.getTok().getLoc(), "']' expected");
4371 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004372 Parser.Lex(); // Eat right bracket token.
4373
4374 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004375 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004376 S, E));
4377
Jim Grosbachc320c852011-08-05 21:28:30 +00004378 // If there's a pre-indexing writeback marker, '!', just add it as a token
4379 // operand.
4380 if (Parser.getTok().is(AsmToken::Exclaim)) {
4381 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4382 Parser.Lex(); // Eat the '!'.
4383 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004384
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004385 return false;
4386}
4387
Jim Grosbachd3595712011-08-03 23:50:40 +00004388/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004389/// ( lsl | lsr | asr | ror ) , # shift_amount
4390/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004391/// return true if it parses a shift otherwise it returns false.
4392bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4393 unsigned &Amount) {
4394 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004395 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004396 if (Tok.isNot(AsmToken::Identifier))
4397 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004398 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004399 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4400 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004401 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004402 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004403 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004404 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004405 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004407 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004408 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004409 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004410 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004411 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004412 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004413
Jim Grosbachd3595712011-08-03 23:50:40 +00004414 // rrx stands alone.
4415 Amount = 0;
4416 if (St != ARM_AM::rrx) {
4417 Loc = Parser.getTok().getLoc();
4418 // A '#' and a shift amount.
4419 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004420 if (HashTok.isNot(AsmToken::Hash) &&
4421 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004422 return Error(HashTok.getLoc(), "'#' expected");
4423 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004424
Jim Grosbachd3595712011-08-03 23:50:40 +00004425 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004426 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004427 return true;
4428 // Range check the immediate.
4429 // lsl, ror: 0 <= imm <= 31
4430 // lsr, asr: 0 <= imm <= 32
4431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4432 if (!CE)
4433 return Error(Loc, "shift amount must be an immediate");
4434 int64_t Imm = CE->getValue();
4435 if (Imm < 0 ||
4436 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4437 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4438 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004439 // If <ShiftTy> #0, turn it into a no_shift.
4440 if (Imm == 0)
4441 St = ARM_AM::lsl;
4442 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4443 if (Imm == 32)
4444 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004445 Amount = Imm;
4446 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004447
4448 return false;
4449}
4450
Jim Grosbache7fbce72011-10-03 23:38:36 +00004451/// parseFPImm - A floating point immediate expression operand.
4452ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4453parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004454 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004455 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004456 // integer only.
4457 //
4458 // This routine still creates a generic Immediate operand, containing
4459 // a bitcast of the 64-bit floating point value. The various operands
4460 // that accept floats can check whether the value is valid for them
4461 // via the standard is*() predicates.
4462
Jim Grosbache7fbce72011-10-03 23:38:36 +00004463 SMLoc S = Parser.getTok().getLoc();
4464
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004465 if (Parser.getTok().isNot(AsmToken::Hash) &&
4466 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004467 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004468
4469 // Disambiguate the VMOV forms that can accept an FP immediate.
4470 // vmov.f32 <sreg>, #imm
4471 // vmov.f64 <dreg>, #imm
4472 // vmov.f32 <dreg>, #imm @ vector f32x2
4473 // vmov.f32 <qreg>, #imm @ vector f32x4
4474 //
4475 // There are also the NEON VMOV instructions which expect an
4476 // integer constant. Make sure we don't try to parse an FPImm
4477 // for these:
4478 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4479 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4480 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4481 TyOp->getToken() != ".f64"))
4482 return MatchOperand_NoMatch;
4483
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004484 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004485
4486 // Handle negation, as that still comes through as a separate token.
4487 bool isNegative = false;
4488 if (Parser.getTok().is(AsmToken::Minus)) {
4489 isNegative = true;
4490 Parser.Lex();
4491 }
4492 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004493 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004494 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004495 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004496 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4497 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004498 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004499 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004500 Operands.push_back(ARMOperand::CreateImm(
4501 MCConstantExpr::Create(IntVal, getContext()),
4502 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004503 return MatchOperand_Success;
4504 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004505 // Also handle plain integers. Instructions which allow floating point
4506 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004507 if (Tok.is(AsmToken::Integer)) {
4508 int64_t Val = Tok.getIntVal();
4509 Parser.Lex(); // Eat the token.
4510 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004511 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004512 return MatchOperand_ParseFail;
4513 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004514 double RealVal = ARM_AM::getFPImmFloat(Val);
4515 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4516 Operands.push_back(ARMOperand::CreateImm(
4517 MCConstantExpr::Create(Val, getContext()), S,
4518 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004519 return MatchOperand_Success;
4520 }
4521
Jim Grosbach235c8d22012-01-19 02:47:30 +00004522 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004523 return MatchOperand_ParseFail;
4524}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004525
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004526/// Parse a arm instruction operand. For now this parses the operand regardless
4527/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004528bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004529 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004530 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004531
4532 // Check if the current operand has a custom associated parser, if so, try to
4533 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004534 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4535 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004536 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004537 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4538 // there was a match, but an error occurred, in which case, just return that
4539 // the operand parsing failed.
4540 if (ResTy == MatchOperand_ParseFail)
4541 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004542
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004543 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004544 default:
4545 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004546 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004547 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004548 // If we've seen a branch mnemonic, the next operand must be a label. This
4549 // is true even if the label is a register name. So "br r1" means branch to
4550 // label "r1".
4551 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4552 if (!ExpectLabel) {
4553 if (!tryParseRegisterWithWriteBack(Operands))
4554 return false;
4555 int Res = tryParseShiftRegister(Operands);
4556 if (Res == 0) // success
4557 return false;
4558 else if (Res == -1) // irrecoverable error
4559 return true;
4560 // If this is VMRS, check for the apsr_nzcv operand.
4561 if (Mnemonic == "vmrs" &&
4562 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4563 S = Parser.getTok().getLoc();
4564 Parser.Lex();
4565 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4566 return false;
4567 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004568 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004569
4570 // Fall though for the Identifier case that is not a register or a
4571 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004572 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004573 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004574 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004575 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004576 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004577 // This was not a register so parse other operands that start with an
4578 // identifier (like labels) as expressions and create them as immediates.
4579 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004580 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004581 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004582 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004583 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004584 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4585 return false;
4586 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004587 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004588 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004589 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004590 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004591 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004592 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004593 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004594 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004595 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004596
4597 if (Parser.getTok().isNot(AsmToken::Colon)) {
4598 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4599 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004600 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004601 return true;
4602 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4603 if (CE) {
4604 int32_t Val = CE->getValue();
4605 if (isNegative && Val == 0)
4606 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4607 }
4608 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4609 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004610
4611 // There can be a trailing '!' on operands that we want as a separate
4612 // '!' Token operand. Handle that here. For example, the compatibilty
4613 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4614 if (Parser.getTok().is(AsmToken::Exclaim)) {
4615 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4616 Parser.getTok().getLoc()));
4617 Parser.Lex(); // Eat exclaim token
4618 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004619 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004620 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004621 // w/ a ':' after the '#', it's just like a plain ':'.
4622 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004623 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004624 case AsmToken::Colon: {
4625 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004626 // FIXME: Check it's an expression prefix,
4627 // e.g. (FOO - :lower16:BAR) isn't legal.
4628 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004629 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004630 return true;
4631
Evan Cheng965b3c72011-01-13 07:58:56 +00004632 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004633 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004634 return true;
4635
Evan Cheng965b3c72011-01-13 07:58:56 +00004636 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004637 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004638 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004639 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004640 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004641 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004642 }
4643}
4644
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004645// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004646// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004647bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004648 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004649
4650 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004651 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004652 Parser.Lex(); // Eat ':'
4653
4654 if (getLexer().isNot(AsmToken::Identifier)) {
4655 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4656 return true;
4657 }
4658
4659 StringRef IDVal = Parser.getTok().getIdentifier();
4660 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004661 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004662 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004663 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004664 } else {
4665 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4666 return true;
4667 }
4668 Parser.Lex();
4669
4670 if (getLexer().isNot(AsmToken::Colon)) {
4671 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4672 return true;
4673 }
4674 Parser.Lex(); // Eat the last ':'
4675 return false;
4676}
4677
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004678/// \brief Given a mnemonic, split out possible predication code and carry
4679/// setting letters to form a canonical mnemonic and flags.
4680//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004681// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004682// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004683StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004684 unsigned &PredicationCode,
4685 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004686 unsigned &ProcessorIMod,
4687 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004688 PredicationCode = ARMCC::AL;
4689 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004690 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004691
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004692 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004693 //
4694 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004695 if ((Mnemonic == "movs" && isThumb()) ||
4696 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4697 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4698 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4699 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004700 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004701 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4702 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004703 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004704 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004705 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4706 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4707 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004708 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004709
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004710 // First, split out any predication code. Ignore mnemonics we know aren't
4711 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004712 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004713 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004714 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004715 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004716 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4717 .Case("eq", ARMCC::EQ)
4718 .Case("ne", ARMCC::NE)
4719 .Case("hs", ARMCC::HS)
4720 .Case("cs", ARMCC::HS)
4721 .Case("lo", ARMCC::LO)
4722 .Case("cc", ARMCC::LO)
4723 .Case("mi", ARMCC::MI)
4724 .Case("pl", ARMCC::PL)
4725 .Case("vs", ARMCC::VS)
4726 .Case("vc", ARMCC::VC)
4727 .Case("hi", ARMCC::HI)
4728 .Case("ls", ARMCC::LS)
4729 .Case("ge", ARMCC::GE)
4730 .Case("lt", ARMCC::LT)
4731 .Case("gt", ARMCC::GT)
4732 .Case("le", ARMCC::LE)
4733 .Case("al", ARMCC::AL)
4734 .Default(~0U);
4735 if (CC != ~0U) {
4736 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4737 PredicationCode = CC;
4738 }
Bill Wendling193961b2010-10-29 23:50:21 +00004739 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004740
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004741 // Next, determine if we have a carry setting bit. We explicitly ignore all
4742 // the instructions we know end in 's'.
4743 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004744 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004745 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4746 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4747 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004748 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004749 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004750 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004751 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004752 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004753 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004754 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4755 CarrySetting = true;
4756 }
4757
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004758 // The "cps" instruction can have a interrupt mode operand which is glued into
4759 // the mnemonic. Check if this is the case, split it and parse the imod op
4760 if (Mnemonic.startswith("cps")) {
4761 // Split out any imod code.
4762 unsigned IMod =
4763 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4764 .Case("ie", ARM_PROC::IE)
4765 .Case("id", ARM_PROC::ID)
4766 .Default(~0U);
4767 if (IMod != ~0U) {
4768 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4769 ProcessorIMod = IMod;
4770 }
4771 }
4772
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004773 // The "it" instruction has the condition mask on the end of the mnemonic.
4774 if (Mnemonic.startswith("it")) {
4775 ITMask = Mnemonic.slice(2, Mnemonic.size());
4776 Mnemonic = Mnemonic.slice(0, 2);
4777 }
4778
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004779 return Mnemonic;
4780}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004781
4782/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4783/// inclusion of carry set or predication code operands.
4784//
4785// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004786void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004787getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004788 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004789 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4790 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004791 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004792 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004793 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004794 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004795 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004796 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004797 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004798 Mnemonic == "mla" || Mnemonic == "smlal" ||
4799 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004800 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004801 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004802 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004803
Tim Northover2c45a382013-06-26 16:52:40 +00004804 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4805 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004806 Mnemonic == "trap" || Mnemonic == "hlt" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004807 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4808 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004809 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4810 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4811 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004812 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004813 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004814 } else if (!isThumb()) {
4815 // Some instructions are only predicable in Thumb mode
4816 CanAcceptPredicationCode
4817 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4818 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4819 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4820 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4821 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4822 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4823 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4824 } else if (isThumbOne()) {
4825 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004826 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004827 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004828}
4829
Jim Grosbach7283da92011-08-16 21:12:37 +00004830bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4831 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004832 // FIXME: This is all horribly hacky. We really need a better way to deal
4833 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004834
4835 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4836 // another does not. Specifically, the MOVW instruction does not. So we
4837 // special case it here and remove the defaulted (non-setting) cc_out
4838 // operand if that's the instruction we're trying to match.
4839 //
4840 // We do this as post-processing of the explicit operands rather than just
4841 // conditionally adding the cc_out in the first place because we need
4842 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004843 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004844 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4845 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4846 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4847 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004848
4849 // Register-register 'add' for thumb does not have a cc_out operand
4850 // when there are only two register operands.
4851 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4852 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4853 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4854 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4855 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004856 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004857 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4858 // have to check the immediate range here since Thumb2 has a variant
4859 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004860 if (((isThumb() && Mnemonic == "add") ||
4861 (isThumbTwo() && Mnemonic == "sub")) &&
4862 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004863 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4864 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4865 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004866 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004867 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004868 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004869 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004870 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4871 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004872 // selecting via the generic "add" mnemonic, so to know that we
4873 // should remove the cc_out operand, we have to explicitly check that
4874 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004875 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4876 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004877 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4878 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4879 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4880 // Nest conditions rather than one big 'if' statement for readability.
4881 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004882 // If both registers are low, we're in an IT block, and the immediate is
4883 // in range, we should use encoding T1 instead, which has a cc_out.
4884 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004885 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004886 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4887 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4888 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004889 // Check against T3. If the second register is the PC, this is an
4890 // alternate form of ADR, which uses encoding T4, so check for that too.
4891 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4892 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4893 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004894
4895 // Otherwise, we use encoding T4, which does not have a cc_out
4896 // operand.
4897 return true;
4898 }
4899
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004900 // The thumb2 multiply instruction doesn't have a CCOut register, so
4901 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4902 // use the 16-bit encoding or not.
4903 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4904 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4905 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4906 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4907 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4908 // If the registers aren't low regs, the destination reg isn't the
4909 // same as one of the source regs, or the cc_out operand is zero
4910 // outside of an IT block, we have to use the 32-bit encoding, so
4911 // remove the cc_out operand.
4912 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4913 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004914 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004915 !inITBlock() ||
4916 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4917 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4918 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4919 static_cast<ARMOperand*>(Operands[4])->getReg())))
4920 return true;
4921
Jim Grosbachefa7e952011-11-15 19:55:16 +00004922 // Also check the 'mul' syntax variant that doesn't specify an explicit
4923 // destination register.
4924 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4925 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4926 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4927 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4928 // If the registers aren't low regs or the cc_out operand is zero
4929 // outside of an IT block, we have to use the 32-bit encoding, so
4930 // remove the cc_out operand.
4931 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4932 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4933 !inITBlock()))
4934 return true;
4935
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004936
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004937
Jim Grosbach4b701af2011-08-24 21:42:27 +00004938 // Register-register 'add/sub' for thumb does not have a cc_out operand
4939 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4940 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4941 // right, this will result in better diagnostics (which operand is off)
4942 // anyway.
4943 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4944 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004945 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4946 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004947 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4948 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4949 (Operands.size() == 6 &&
4950 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004951 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004952
Jim Grosbach7283da92011-08-16 21:12:37 +00004953 return false;
4954}
4955
Joey Goulye8602552013-07-19 16:34:16 +00004956bool ARMAsmParser::shouldOmitPredicateOperand(
4957 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4958 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4959 unsigned RegIdx = 3;
4960 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4961 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4962 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4963 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4964 RegIdx = 4;
4965
4966 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4967 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4968 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4969 ARMMCRegisterClasses[ARM::QPRRegClassID]
4970 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4971 return true;
4972 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004973 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004974}
4975
Jim Grosbach12952fe2011-11-11 23:08:10 +00004976static bool isDataTypeToken(StringRef Tok) {
4977 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4978 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4979 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4980 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4981 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4982 Tok == ".f" || Tok == ".d";
4983}
4984
4985// FIXME: This bit should probably be handled via an explicit match class
4986// in the .td files that matches the suffix instead of having it be
4987// a literal string token the way it is now.
4988static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4989 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4990}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004991static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4992 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004993/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004994bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4995 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004996 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004997 // Apply mnemonic aliases before doing anything else, as the destination
4998 // mnemnonic may include suffices and we want to handle them normally.
4999 // The generic tblgen'erated code does this later, at the start of
5000 // MatchInstructionImpl(), but that's too late for aliases that include
5001 // any sort of suffix.
5002 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005003 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5004 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005005
Jim Grosbachab5830e2011-12-14 02:16:11 +00005006 // First check for the ARM-specific .req directive.
5007 if (Parser.getTok().is(AsmToken::Identifier) &&
5008 Parser.getTok().getIdentifier() == ".req") {
5009 parseDirectiveReq(Name, NameLoc);
5010 // We always return 'error' for this, as we're done with this
5011 // statement and don't need to match the 'instruction."
5012 return true;
5013 }
5014
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005015 // Create the leading tokens for the mnemonic, split by '.' characters.
5016 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005017 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005018
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005019 // Split out the predication code and carry setting flag from the mnemonic.
5020 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005021 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005022 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005023 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005024 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005025 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005026
Jim Grosbach1c171b12011-08-25 17:23:55 +00005027 // In Thumb1, only the branch (B) instruction can be predicated.
5028 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005029 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005030 return Error(NameLoc, "conditional execution not supported in Thumb1");
5031 }
5032
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005033 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5034
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005035 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5036 // is the mask as it will be for the IT encoding if the conditional
5037 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5038 // where the conditional bit0 is zero, the instruction post-processing
5039 // will adjust the mask accordingly.
5040 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005041 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5042 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005043 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005044 return Error(Loc, "too many conditions on IT instruction");
5045 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005046 unsigned Mask = 8;
5047 for (unsigned i = ITMask.size(); i != 0; --i) {
5048 char pos = ITMask[i - 1];
5049 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005050 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005051 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005052 }
5053 Mask >>= 1;
5054 if (ITMask[i - 1] == 't')
5055 Mask |= 8;
5056 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005057 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005058 }
5059
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005060 // FIXME: This is all a pretty gross hack. We should automatically handle
5061 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005062
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005063 // Next, add the CCOut and ConditionCode operands, if needed.
5064 //
5065 // For mnemonics which can ever incorporate a carry setting bit or predication
5066 // code, our matching model involves us always generating CCOut and
5067 // ConditionCode operands to match the mnemonic "as written" and then we let
5068 // the matcher deal with finding the right instruction or generating an
5069 // appropriate error.
5070 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005071 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005072
Jim Grosbach03a8a162011-07-14 22:04:21 +00005073 // If we had a carry-set on an instruction that can't do that, issue an
5074 // error.
5075 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005076 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005077 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005078 "' can not set flags, but 's' suffix specified");
5079 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005080 // If we had a predication code on an instruction that can't do that, issue an
5081 // error.
5082 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005083 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005084 return Error(NameLoc, "instruction '" + Mnemonic +
5085 "' is not predicable, but condition code specified");
5086 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005087
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005088 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005089 if (CanAcceptCarrySet) {
5090 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005091 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005092 Loc));
5093 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005094
5095 // Add the predication code operand, if necessary.
5096 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005097 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5098 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005099 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005100 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005101 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005102
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005103 // Add the processor imod operand, if necessary.
5104 if (ProcessorIMod) {
5105 Operands.push_back(ARMOperand::CreateImm(
5106 MCConstantExpr::Create(ProcessorIMod, getContext()),
5107 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005108 }
5109
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005110 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005111 while (Next != StringRef::npos) {
5112 Start = Next;
5113 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005114 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005115
Jim Grosbach12952fe2011-11-11 23:08:10 +00005116 // Some NEON instructions have an optional datatype suffix that is
5117 // completely ignored. Check for that.
5118 if (isDataTypeToken(ExtraToken) &&
5119 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5120 continue;
5121
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005122 // For for ARM mode generate an error if the .n qualifier is used.
5123 if (ExtraToken == ".n" && !isThumb()) {
5124 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5125 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5126 "arm mode");
5127 }
5128
5129 // The .n qualifier is always discarded as that is what the tables
5130 // and matcher expect. In ARM mode the .w qualifier has no effect,
5131 // so discard it to avoid errors that can be caused by the matcher.
5132 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005133 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5134 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5135 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005136 }
5137
5138 // Read the remaining operands.
5139 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005140 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005141 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005142 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005143 return true;
5144 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005145
5146 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005147 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005148
5149 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005150 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005151 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005152 return true;
5153 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005154 }
5155 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005156
Chris Lattnera2a9d162010-09-11 16:18:25 +00005157 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005158 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005159 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005160 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005161 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005162
Chris Lattner91689c12010-09-08 05:10:46 +00005163 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005164
Jim Grosbach7283da92011-08-16 21:12:37 +00005165 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5166 // do and don't have a cc_out optional-def operand. With some spot-checks
5167 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005168 // parse and adjust accordingly before actually matching. We shouldn't ever
5169 // try to remove a cc_out operand that was explicitly set on the the
5170 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5171 // table driven matcher doesn't fit well with the ARM instruction set.
5172 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005173 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5174 Operands.erase(Operands.begin() + 1);
5175 delete Op;
5176 }
5177
Joey Goulye8602552013-07-19 16:34:16 +00005178 // Some instructions have the same mnemonic, but don't always
5179 // have a predicate. Distinguish them here and delete the
5180 // predicate if needed.
5181 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5182 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5183 Operands.erase(Operands.begin() + 1);
5184 delete Op;
5185 }
5186
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005187 // ARM mode 'blx' need special handling, as the register operand version
5188 // is predicable, but the label operand version is not. So, we can't rely
5189 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005190 // a k_CondCode operand in the list. If we're trying to match the label
5191 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005192 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5193 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5194 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5195 Operands.erase(Operands.begin() + 1);
5196 delete Op;
5197 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005198
Weiming Zhao8f56f882012-11-16 21:55:34 +00005199 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5200 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5201 // a single GPRPair reg operand is used in the .td file to replace the two
5202 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5203 // expressed as a GPRPair, so we have to manually merge them.
5204 // FIXME: We would really like to be able to tablegen'erate this.
5205 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005206 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5207 Mnemonic == "stlexd")) {
5208 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005209 unsigned Idx = isLoad ? 2 : 3;
5210 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5211 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5212
5213 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5214 // Adjust only if Op1 and Op2 are GPRs.
5215 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5216 MRC.contains(Op2->getReg())) {
5217 unsigned Reg1 = Op1->getReg();
5218 unsigned Reg2 = Op2->getReg();
5219 unsigned Rt = MRI->getEncodingValue(Reg1);
5220 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5221
5222 // Rt2 must be Rt + 1 and Rt must be even.
5223 if (Rt + 1 != Rt2 || (Rt & 1)) {
5224 Error(Op2->getStartLoc(), isLoad ?
5225 "destination operands must be sequential" :
5226 "source operands must be sequential");
5227 return true;
5228 }
5229 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5230 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5231 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5232 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5233 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5234 delete Op1;
5235 delete Op2;
5236 }
5237 }
5238
Kevin Enderby78f95722013-07-31 21:05:30 +00005239 // FIXME: As said above, this is all a pretty gross hack. This instruction
5240 // does not fit with other "subs" and tblgen.
5241 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5242 // so the Mnemonic is the original name "subs" and delete the predicate
5243 // operand so it will match the table entry.
5244 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5245 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5246 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5247 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5248 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5249 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5250 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5251 Operands.erase(Operands.begin());
5252 delete Op0;
5253 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5254
5255 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5256 Operands.erase(Operands.begin() + 1);
5257 delete Op1;
5258 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005259 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005260}
5261
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005262// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005263
5264// return 'true' if register list contains non-low GPR registers,
5265// 'false' otherwise. If Reg is in the register list or is HiReg, set
5266// 'containsReg' to true.
5267static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5268 unsigned HiReg, bool &containsReg) {
5269 containsReg = false;
5270 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5271 unsigned OpReg = Inst.getOperand(i).getReg();
5272 if (OpReg == Reg)
5273 containsReg = true;
5274 // Anything other than a low register isn't legal here.
5275 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5276 return true;
5277 }
5278 return false;
5279}
5280
Jim Grosbacha31f2232011-09-07 18:05:34 +00005281// Check if the specified regisgter is in the register list of the inst,
5282// starting at the indicated operand number.
5283static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5284 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5285 unsigned OpReg = Inst.getOperand(i).getReg();
5286 if (OpReg == Reg)
5287 return true;
5288 }
5289 return false;
5290}
5291
Richard Barton8d519fe2013-09-05 14:14:19 +00005292// Return true if instruction has the interesting property of being
5293// allowed in IT blocks, but not being predicable.
5294static bool instIsBreakpoint(const MCInst &Inst) {
5295 return Inst.getOpcode() == ARM::tBKPT ||
5296 Inst.getOpcode() == ARM::BKPT ||
5297 Inst.getOpcode() == ARM::tHLT ||
5298 Inst.getOpcode() == ARM::HLT;
5299
5300}
5301
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005302// FIXME: We would really like to be able to tablegen'erate this.
5303bool ARMAsmParser::
5304validateInstruction(MCInst &Inst,
5305 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005306 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005307 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005308
Jim Grosbached16ec42011-08-29 22:24:09 +00005309 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005310 // NOTE: BKPT and HLT instructions have the interesting property of being
5311 // allowed in IT blocks, but not being predicable. They just always
5312 // execute.
5313 if (inITBlock() && !instIsBreakpoint(Inst)) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005314 unsigned bit = 1;
5315 if (ITState.FirstCond)
5316 ITState.FirstCond = false;
5317 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005318 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005319 // The instruction must be predicable.
5320 if (!MCID.isPredicable())
5321 return Error(Loc, "instructions in IT block must be predicable");
5322 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5323 unsigned ITCond = bit ? ITState.Cond :
5324 ARMCC::getOppositeCondition(ITState.Cond);
5325 if (Cond != ITCond) {
5326 // Find the condition code Operand to get its SMLoc information.
5327 SMLoc CondLoc;
5328 for (unsigned i = 1; i < Operands.size(); ++i)
5329 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5330 CondLoc = Operands[i]->getStartLoc();
5331 return Error(CondLoc, "incorrect condition in IT block; got '" +
5332 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5333 "', but expected '" +
5334 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5335 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005336 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005337 } else if (isThumbTwo() && MCID.isPredicable() &&
5338 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005339 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5340 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005341 return Error(Loc, "predicated instructions must be in IT block");
5342
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005343 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005344 case ARM::LDRD:
5345 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005346 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005347 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005348 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5349 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005350 if (Rt2 != Rt + 1)
5351 return Error(Operands[3]->getStartLoc(),
5352 "destination operands must be sequential");
5353 return false;
5354 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005355 case ARM::STRD: {
5356 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005357 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5358 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005359 if (Rt2 != Rt + 1)
5360 return Error(Operands[3]->getStartLoc(),
5361 "source operands must be sequential");
5362 return false;
5363 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005364 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005365 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005366 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005367 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5368 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005369 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005370 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005371 "source operands must be sequential");
5372 return false;
5373 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005374 case ARM::SBFX:
5375 case ARM::UBFX: {
5376 // width must be in range [1, 32-lsb]
5377 unsigned lsb = Inst.getOperand(2).getImm();
5378 unsigned widthm1 = Inst.getOperand(3).getImm();
5379 if (widthm1 >= 32 - lsb)
5380 return Error(Operands[5]->getStartLoc(),
5381 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005382 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005383 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005384 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005385 // If we're parsing Thumb2, the .w variant is available and handles
5386 // most cases that are normally illegal for a Thumb1 LDM
5387 // instruction. We'll make the transformation in processInstruction()
5388 // if necessary.
5389 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005390 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005391 // in the register list.
5392 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005393 bool hasWritebackToken =
5394 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5395 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005396 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005397 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005398 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5399 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005400 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005401 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005402 return Error(Operands[2]->getStartLoc(),
5403 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005404 // If we should not have writeback, there must not be a '!'. This is
5405 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005406 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005407 return Error(Operands[3]->getStartLoc(),
5408 "writeback operator '!' not allowed when base register "
5409 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005410
5411 break;
5412 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005413 case ARM::t2LDMIA_UPD: {
5414 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5415 return Error(Operands[4]->getStartLoc(),
5416 "writeback operator '!' not allowed when base register "
5417 "in register list");
5418 break;
5419 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005420 case ARM::tMUL: {
5421 // The second source operand must be the same register as the destination
5422 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005423 //
5424 // In this case, we must directly check the parsed operands because the
5425 // cvtThumbMultiply() function is written in such a way that it guarantees
5426 // this first statement is always true for the new Inst. Essentially, the
5427 // destination is unconditionally copied into the second source operand
5428 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005429 if (Operands.size() == 6 &&
5430 (((ARMOperand*)Operands[3])->getReg() !=
5431 ((ARMOperand*)Operands[5])->getReg()) &&
5432 (((ARMOperand*)Operands[3])->getReg() !=
5433 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005434 return Error(Operands[3]->getStartLoc(),
5435 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005436 }
5437 break;
5438 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005439 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5440 // so only issue a diagnostic for thumb1. The instructions will be
5441 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005442 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005443 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005444 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5445 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005446 return Error(Operands[2]->getStartLoc(),
5447 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005448 break;
5449 }
5450 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005451 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005452 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5453 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005454 return Error(Operands[2]->getStartLoc(),
5455 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005456 break;
5457 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005458 case ARM::tSTMIA_UPD: {
5459 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005460 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005461 return Error(Operands[4]->getStartLoc(),
5462 "registers must be in range r0-r7");
5463 break;
5464 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005465 case ARM::tADDrSP: {
5466 // If the non-SP source operand and the destination operand are not the
5467 // same, we need thumb2 (for the wide encoding), or we have an error.
5468 if (!isThumbTwo() &&
5469 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5470 return Error(Operands[4]->getStartLoc(),
5471 "source register must be the same as destination");
5472 }
5473 break;
5474 }
Mihai Popaad18d3c2013-08-09 10:38:32 +00005475 // final range checking for Thumb unconditional branch instructions
5476 case ARM::tB:
5477 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5478 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5479 break;
5480 case ARM::t2B: {
5481 int op = (Operands[2]->isImm()) ? 2 : 3;
5482 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5483 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5484 break;
5485 }
5486 // final range checking for Thumb conditional branch instructions
5487 case ARM::tBcc:
5488 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5489 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5490 break;
5491 case ARM::t2Bcc: {
5492 int op = (Operands[2]->isImm()) ? 2 : 3;
5493 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<20, 1>())
5494 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5495 break;
5496 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005497 }
5498
5499 return false;
5500}
5501
Jim Grosbach1a747242012-01-23 23:45:44 +00005502static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005503 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005504 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005505 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005506 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5507 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5508 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5509 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5510 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5511 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5512 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5513 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5514 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005515
5516 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005517 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5518 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5519 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5520 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5521 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005522
Jim Grosbach1e946a42012-01-24 00:43:12 +00005523 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5524 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5525 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5526 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5527 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005528
Jim Grosbach1e946a42012-01-24 00:43:12 +00005529 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5530 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5531 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5532 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5533 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005534
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005535 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005536 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5537 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5538 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5539 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5540 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5541 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5542 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5543 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5544 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5545 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5546 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5547 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5548 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5549 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5550 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005551
Jim Grosbach1a747242012-01-23 23:45:44 +00005552 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005553 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5554 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5555 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5556 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5557 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5558 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5559 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5560 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5561 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5562 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5563 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5564 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5565 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5566 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5567 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5568 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5569 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5570 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005571
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005572 // VST4LN
5573 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5574 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5575 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5576 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5577 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5578 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5579 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5580 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5581 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5582 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5583 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5584 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5585 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5586 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5587 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5588
Jim Grosbachda70eac2012-01-24 00:58:13 +00005589 // VST4
5590 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5591 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5592 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5593 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5594 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5595 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5596 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5597 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5598 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5599 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5600 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5601 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5602 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5603 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5604 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5605 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5606 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5607 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005608 }
5609}
5610
Jim Grosbach1a747242012-01-23 23:45:44 +00005611static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005612 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005613 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005614 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005615 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5616 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5617 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5618 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5619 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5620 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5621 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5622 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5623 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005624
5625 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005626 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5627 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5628 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5629 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5630 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5631 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5632 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5633 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5634 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5635 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5636 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5637 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5638 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5639 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5640 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005641
Jim Grosbachb78403c2012-01-24 23:47:04 +00005642 // VLD3DUP
5643 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5644 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5645 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5646 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5647 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5648 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5649 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5650 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5651 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5652 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5653 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5654 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5655 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5656 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5657 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5658 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5659 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5660 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5661
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005662 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005663 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5664 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5665 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5666 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5667 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5668 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5669 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5670 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5671 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5672 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5673 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5674 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5675 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5676 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5677 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005678
5679 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005680 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5681 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5682 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5683 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5684 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5685 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5686 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5687 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5688 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5689 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5690 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5691 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5692 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5693 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5694 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5695 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5696 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5697 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005698
Jim Grosbach14952a02012-01-24 18:37:25 +00005699 // VLD4LN
5700 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5701 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5702 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5703 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5704 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5705 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5706 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5707 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5708 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5709 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5710 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5711 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5712 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5713 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5714 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5715
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005716 // VLD4DUP
5717 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5718 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5719 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5720 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5721 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5722 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5723 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5724 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5725 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5726 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5727 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5728 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5729 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5730 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5731 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5732 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5733 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5734 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5735
Jim Grosbached561fc2012-01-24 00:43:17 +00005736 // VLD4
5737 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5738 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5739 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5740 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5741 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5742 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5743 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5744 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5745 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5746 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5747 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5748 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5749 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5750 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5751 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5752 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5753 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5754 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005755 }
5756}
5757
Jim Grosbachafad0532011-11-10 23:42:14 +00005758bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005759processInstruction(MCInst &Inst,
5760 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5761 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005762 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5763 case ARM::ADDri: {
5764 if (Inst.getOperand(1).getReg() != ARM::PC ||
5765 Inst.getOperand(5).getReg() != 0)
5766 return false;
5767 MCInst TmpInst;
5768 TmpInst.setOpcode(ARM::ADR);
5769 TmpInst.addOperand(Inst.getOperand(0));
5770 TmpInst.addOperand(Inst.getOperand(2));
5771 TmpInst.addOperand(Inst.getOperand(3));
5772 TmpInst.addOperand(Inst.getOperand(4));
5773 Inst = TmpInst;
5774 return true;
5775 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005776 // Aliases for alternate PC+imm syntax of LDR instructions.
5777 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005778 // Select the narrow version if the immediate will fit.
5779 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005780 Inst.getOperand(1).getImm() <= 0xff &&
5781 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5782 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005783 Inst.setOpcode(ARM::tLDRpci);
5784 else
5785 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005786 return true;
5787 case ARM::t2LDRBpcrel:
5788 Inst.setOpcode(ARM::t2LDRBpci);
5789 return true;
5790 case ARM::t2LDRHpcrel:
5791 Inst.setOpcode(ARM::t2LDRHpci);
5792 return true;
5793 case ARM::t2LDRSBpcrel:
5794 Inst.setOpcode(ARM::t2LDRSBpci);
5795 return true;
5796 case ARM::t2LDRSHpcrel:
5797 Inst.setOpcode(ARM::t2LDRSHpci);
5798 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005799 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005800 case ARM::VST1LNdWB_register_Asm_8:
5801 case ARM::VST1LNdWB_register_Asm_16:
5802 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005803 MCInst TmpInst;
5804 // Shuffle the operands around so the lane index operand is in the
5805 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005806 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005807 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005808 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5809 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5810 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5811 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5812 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5813 TmpInst.addOperand(Inst.getOperand(1)); // lane
5814 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5815 TmpInst.addOperand(Inst.getOperand(6));
5816 Inst = TmpInst;
5817 return true;
5818 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005819
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005820 case ARM::VST2LNdWB_register_Asm_8:
5821 case ARM::VST2LNdWB_register_Asm_16:
5822 case ARM::VST2LNdWB_register_Asm_32:
5823 case ARM::VST2LNqWB_register_Asm_16:
5824 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005825 MCInst TmpInst;
5826 // Shuffle the operands around so the lane index operand is in the
5827 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005828 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005829 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005830 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5831 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5832 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5833 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5834 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005835 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5836 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005837 TmpInst.addOperand(Inst.getOperand(1)); // lane
5838 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5839 TmpInst.addOperand(Inst.getOperand(6));
5840 Inst = TmpInst;
5841 return true;
5842 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005843
5844 case ARM::VST3LNdWB_register_Asm_8:
5845 case ARM::VST3LNdWB_register_Asm_16:
5846 case ARM::VST3LNdWB_register_Asm_32:
5847 case ARM::VST3LNqWB_register_Asm_16:
5848 case ARM::VST3LNqWB_register_Asm_32: {
5849 MCInst TmpInst;
5850 // Shuffle the operands around so the lane index operand is in the
5851 // right place.
5852 unsigned Spacing;
5853 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5855 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5856 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5857 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5858 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5859 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5860 Spacing));
5861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5862 Spacing * 2));
5863 TmpInst.addOperand(Inst.getOperand(1)); // lane
5864 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5865 TmpInst.addOperand(Inst.getOperand(6));
5866 Inst = TmpInst;
5867 return true;
5868 }
5869
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005870 case ARM::VST4LNdWB_register_Asm_8:
5871 case ARM::VST4LNdWB_register_Asm_16:
5872 case ARM::VST4LNdWB_register_Asm_32:
5873 case ARM::VST4LNqWB_register_Asm_16:
5874 case ARM::VST4LNqWB_register_Asm_32: {
5875 MCInst TmpInst;
5876 // Shuffle the operands around so the lane index operand is in the
5877 // right place.
5878 unsigned Spacing;
5879 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5880 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5881 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5882 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5883 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5884 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5886 Spacing));
5887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5888 Spacing * 2));
5889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5890 Spacing * 3));
5891 TmpInst.addOperand(Inst.getOperand(1)); // lane
5892 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5893 TmpInst.addOperand(Inst.getOperand(6));
5894 Inst = TmpInst;
5895 return true;
5896 }
5897
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005898 case ARM::VST1LNdWB_fixed_Asm_8:
5899 case ARM::VST1LNdWB_fixed_Asm_16:
5900 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005901 MCInst TmpInst;
5902 // Shuffle the operands around so the lane index operand is in the
5903 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005904 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005905 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005906 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5907 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5908 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5909 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5910 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5911 TmpInst.addOperand(Inst.getOperand(1)); // lane
5912 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5913 TmpInst.addOperand(Inst.getOperand(5));
5914 Inst = TmpInst;
5915 return true;
5916 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005917
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005918 case ARM::VST2LNdWB_fixed_Asm_8:
5919 case ARM::VST2LNdWB_fixed_Asm_16:
5920 case ARM::VST2LNdWB_fixed_Asm_32:
5921 case ARM::VST2LNqWB_fixed_Asm_16:
5922 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005923 MCInst TmpInst;
5924 // Shuffle the operands around so the lane index operand is in the
5925 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005926 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005927 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005928 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5929 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5930 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5931 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5932 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5934 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005935 TmpInst.addOperand(Inst.getOperand(1)); // lane
5936 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5937 TmpInst.addOperand(Inst.getOperand(5));
5938 Inst = TmpInst;
5939 return true;
5940 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005941
5942 case ARM::VST3LNdWB_fixed_Asm_8:
5943 case ARM::VST3LNdWB_fixed_Asm_16:
5944 case ARM::VST3LNdWB_fixed_Asm_32:
5945 case ARM::VST3LNqWB_fixed_Asm_16:
5946 case ARM::VST3LNqWB_fixed_Asm_32: {
5947 MCInst TmpInst;
5948 // Shuffle the operands around so the lane index operand is in the
5949 // right place.
5950 unsigned Spacing;
5951 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5952 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5953 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5954 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5955 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5956 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5958 Spacing));
5959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5960 Spacing * 2));
5961 TmpInst.addOperand(Inst.getOperand(1)); // lane
5962 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5963 TmpInst.addOperand(Inst.getOperand(5));
5964 Inst = TmpInst;
5965 return true;
5966 }
5967
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005968 case ARM::VST4LNdWB_fixed_Asm_8:
5969 case ARM::VST4LNdWB_fixed_Asm_16:
5970 case ARM::VST4LNdWB_fixed_Asm_32:
5971 case ARM::VST4LNqWB_fixed_Asm_16:
5972 case ARM::VST4LNqWB_fixed_Asm_32: {
5973 MCInst TmpInst;
5974 // Shuffle the operands around so the lane index operand is in the
5975 // right place.
5976 unsigned Spacing;
5977 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5978 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5979 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5980 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5981 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5982 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5983 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5984 Spacing));
5985 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5986 Spacing * 2));
5987 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5988 Spacing * 3));
5989 TmpInst.addOperand(Inst.getOperand(1)); // lane
5990 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5991 TmpInst.addOperand(Inst.getOperand(5));
5992 Inst = TmpInst;
5993 return true;
5994 }
5995
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005996 case ARM::VST1LNdAsm_8:
5997 case ARM::VST1LNdAsm_16:
5998 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005999 MCInst TmpInst;
6000 // Shuffle the operands around so the lane index operand is in the
6001 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006002 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006003 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006004 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6005 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6006 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6007 TmpInst.addOperand(Inst.getOperand(1)); // lane
6008 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6009 TmpInst.addOperand(Inst.getOperand(5));
6010 Inst = TmpInst;
6011 return true;
6012 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006013
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006014 case ARM::VST2LNdAsm_8:
6015 case ARM::VST2LNdAsm_16:
6016 case ARM::VST2LNdAsm_32:
6017 case ARM::VST2LNqAsm_16:
6018 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006019 MCInst TmpInst;
6020 // Shuffle the operands around so the lane index operand is in the
6021 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006022 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006023 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006024 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6025 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6026 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6028 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006029 TmpInst.addOperand(Inst.getOperand(1)); // lane
6030 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6031 TmpInst.addOperand(Inst.getOperand(5));
6032 Inst = TmpInst;
6033 return true;
6034 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006035
6036 case ARM::VST3LNdAsm_8:
6037 case ARM::VST3LNdAsm_16:
6038 case ARM::VST3LNdAsm_32:
6039 case ARM::VST3LNqAsm_16:
6040 case ARM::VST3LNqAsm_32: {
6041 MCInst TmpInst;
6042 // Shuffle the operands around so the lane index operand is in the
6043 // right place.
6044 unsigned Spacing;
6045 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6046 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6047 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6048 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6050 Spacing));
6051 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6052 Spacing * 2));
6053 TmpInst.addOperand(Inst.getOperand(1)); // lane
6054 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6055 TmpInst.addOperand(Inst.getOperand(5));
6056 Inst = TmpInst;
6057 return true;
6058 }
6059
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006060 case ARM::VST4LNdAsm_8:
6061 case ARM::VST4LNdAsm_16:
6062 case ARM::VST4LNdAsm_32:
6063 case ARM::VST4LNqAsm_16:
6064 case ARM::VST4LNqAsm_32: {
6065 MCInst TmpInst;
6066 // Shuffle the operands around so the lane index operand is in the
6067 // right place.
6068 unsigned Spacing;
6069 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6070 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6071 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6072 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing));
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6076 Spacing * 2));
6077 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6078 Spacing * 3));
6079 TmpInst.addOperand(Inst.getOperand(1)); // lane
6080 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6081 TmpInst.addOperand(Inst.getOperand(5));
6082 Inst = TmpInst;
6083 return true;
6084 }
6085
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006086 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006087 case ARM::VLD1LNdWB_register_Asm_8:
6088 case ARM::VLD1LNdWB_register_Asm_16:
6089 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006090 MCInst TmpInst;
6091 // Shuffle the operands around so the lane index operand is in the
6092 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006093 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006094 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006095 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6096 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6097 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6098 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6099 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6100 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6101 TmpInst.addOperand(Inst.getOperand(1)); // lane
6102 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6103 TmpInst.addOperand(Inst.getOperand(6));
6104 Inst = TmpInst;
6105 return true;
6106 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006107
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006108 case ARM::VLD2LNdWB_register_Asm_8:
6109 case ARM::VLD2LNdWB_register_Asm_16:
6110 case ARM::VLD2LNdWB_register_Asm_32:
6111 case ARM::VLD2LNqWB_register_Asm_16:
6112 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006113 MCInst TmpInst;
6114 // Shuffle the operands around so the lane index operand is in the
6115 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006116 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006117 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006118 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6120 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006121 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6122 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6123 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6124 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6125 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006128 TmpInst.addOperand(Inst.getOperand(1)); // lane
6129 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6130 TmpInst.addOperand(Inst.getOperand(6));
6131 Inst = TmpInst;
6132 return true;
6133 }
6134
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006135 case ARM::VLD3LNdWB_register_Asm_8:
6136 case ARM::VLD3LNdWB_register_Asm_16:
6137 case ARM::VLD3LNdWB_register_Asm_32:
6138 case ARM::VLD3LNqWB_register_Asm_16:
6139 case ARM::VLD3LNqWB_register_Asm_32: {
6140 MCInst TmpInst;
6141 // Shuffle the operands around so the lane index operand is in the
6142 // right place.
6143 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006144 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006145 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6146 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 Spacing));
6148 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006149 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006150 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6151 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6152 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6153 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6154 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6156 Spacing));
6157 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006158 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006159 TmpInst.addOperand(Inst.getOperand(1)); // lane
6160 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6161 TmpInst.addOperand(Inst.getOperand(6));
6162 Inst = TmpInst;
6163 return true;
6164 }
6165
Jim Grosbach14952a02012-01-24 18:37:25 +00006166 case ARM::VLD4LNdWB_register_Asm_8:
6167 case ARM::VLD4LNdWB_register_Asm_16:
6168 case ARM::VLD4LNdWB_register_Asm_32:
6169 case ARM::VLD4LNqWB_register_Asm_16:
6170 case ARM::VLD4LNqWB_register_Asm_32: {
6171 MCInst TmpInst;
6172 // Shuffle the operands around so the lane index operand is in the
6173 // right place.
6174 unsigned Spacing;
6175 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6176 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6178 Spacing));
6179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6180 Spacing * 2));
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6182 Spacing * 3));
6183 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6184 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6185 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6186 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6187 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6188 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 Spacing));
6190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 Spacing * 2));
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 Spacing * 3));
6194 TmpInst.addOperand(Inst.getOperand(1)); // lane
6195 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6196 TmpInst.addOperand(Inst.getOperand(6));
6197 Inst = TmpInst;
6198 return true;
6199 }
6200
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006201 case ARM::VLD1LNdWB_fixed_Asm_8:
6202 case ARM::VLD1LNdWB_fixed_Asm_16:
6203 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006204 MCInst TmpInst;
6205 // Shuffle the operands around so the lane index operand is in the
6206 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006207 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006208 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006209 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6210 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6211 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6212 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6213 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6214 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6215 TmpInst.addOperand(Inst.getOperand(1)); // lane
6216 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6217 TmpInst.addOperand(Inst.getOperand(5));
6218 Inst = TmpInst;
6219 return true;
6220 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006221
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006222 case ARM::VLD2LNdWB_fixed_Asm_8:
6223 case ARM::VLD2LNdWB_fixed_Asm_16:
6224 case ARM::VLD2LNdWB_fixed_Asm_32:
6225 case ARM::VLD2LNqWB_fixed_Asm_16:
6226 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006227 MCInst TmpInst;
6228 // Shuffle the operands around so the lane index operand is in the
6229 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006230 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006231 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006232 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006233 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6234 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006235 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6236 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6237 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6238 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6239 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6241 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006242 TmpInst.addOperand(Inst.getOperand(1)); // lane
6243 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6244 TmpInst.addOperand(Inst.getOperand(5));
6245 Inst = TmpInst;
6246 return true;
6247 }
6248
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006249 case ARM::VLD3LNdWB_fixed_Asm_8:
6250 case ARM::VLD3LNdWB_fixed_Asm_16:
6251 case ARM::VLD3LNdWB_fixed_Asm_32:
6252 case ARM::VLD3LNqWB_fixed_Asm_16:
6253 case ARM::VLD3LNqWB_fixed_Asm_32: {
6254 MCInst TmpInst;
6255 // Shuffle the operands around so the lane index operand is in the
6256 // right place.
6257 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006258 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006259 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 Spacing));
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006263 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006264 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6265 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6266 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6267 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6268 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 Spacing));
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006272 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006273 TmpInst.addOperand(Inst.getOperand(1)); // lane
6274 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6275 TmpInst.addOperand(Inst.getOperand(5));
6276 Inst = TmpInst;
6277 return true;
6278 }
6279
Jim Grosbach14952a02012-01-24 18:37:25 +00006280 case ARM::VLD4LNdWB_fixed_Asm_8:
6281 case ARM::VLD4LNdWB_fixed_Asm_16:
6282 case ARM::VLD4LNdWB_fixed_Asm_32:
6283 case ARM::VLD4LNqWB_fixed_Asm_16:
6284 case ARM::VLD4LNqWB_fixed_Asm_32: {
6285 MCInst TmpInst;
6286 // Shuffle the operands around so the lane index operand is in the
6287 // right place.
6288 unsigned Spacing;
6289 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6290 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6292 Spacing));
6293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6294 Spacing * 2));
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 Spacing * 3));
6297 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6298 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6299 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6300 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6301 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6303 Spacing));
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing * 2));
6306 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 Spacing * 3));
6308 TmpInst.addOperand(Inst.getOperand(1)); // lane
6309 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6310 TmpInst.addOperand(Inst.getOperand(5));
6311 Inst = TmpInst;
6312 return true;
6313 }
6314
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006315 case ARM::VLD1LNdAsm_8:
6316 case ARM::VLD1LNdAsm_16:
6317 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006318 MCInst TmpInst;
6319 // Shuffle the operands around so the lane index operand is in the
6320 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006321 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006322 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006323 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6324 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6325 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6326 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6327 TmpInst.addOperand(Inst.getOperand(1)); // lane
6328 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6329 TmpInst.addOperand(Inst.getOperand(5));
6330 Inst = TmpInst;
6331 return true;
6332 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006333
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006334 case ARM::VLD2LNdAsm_8:
6335 case ARM::VLD2LNdAsm_16:
6336 case ARM::VLD2LNdAsm_32:
6337 case ARM::VLD2LNqAsm_16:
6338 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006339 MCInst TmpInst;
6340 // Shuffle the operands around so the lane index operand is in the
6341 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006342 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006343 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006347 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6348 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6349 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006350 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6351 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006352 TmpInst.addOperand(Inst.getOperand(1)); // lane
6353 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6354 TmpInst.addOperand(Inst.getOperand(5));
6355 Inst = TmpInst;
6356 return true;
6357 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006358
6359 case ARM::VLD3LNdAsm_8:
6360 case ARM::VLD3LNdAsm_16:
6361 case ARM::VLD3LNdAsm_32:
6362 case ARM::VLD3LNqAsm_16:
6363 case ARM::VLD3LNqAsm_32: {
6364 MCInst TmpInst;
6365 // Shuffle the operands around so the lane index operand is in the
6366 // right place.
6367 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006368 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006369 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6370 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 Spacing));
6372 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006373 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006374 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6375 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6376 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6377 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 Spacing));
6379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006380 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006381 TmpInst.addOperand(Inst.getOperand(1)); // lane
6382 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(5));
6384 Inst = TmpInst;
6385 return true;
6386 }
6387
Jim Grosbach14952a02012-01-24 18:37:25 +00006388 case ARM::VLD4LNdAsm_8:
6389 case ARM::VLD4LNdAsm_16:
6390 case ARM::VLD4LNdAsm_32:
6391 case ARM::VLD4LNqAsm_16:
6392 case ARM::VLD4LNqAsm_32: {
6393 MCInst TmpInst;
6394 // Shuffle the operands around so the lane index operand is in the
6395 // right place.
6396 unsigned Spacing;
6397 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6398 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 Spacing));
6401 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6402 Spacing * 2));
6403 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6404 Spacing * 3));
6405 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6406 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6407 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 Spacing));
6410 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6411 Spacing * 2));
6412 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6413 Spacing * 3));
6414 TmpInst.addOperand(Inst.getOperand(1)); // lane
6415 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6416 TmpInst.addOperand(Inst.getOperand(5));
6417 Inst = TmpInst;
6418 return true;
6419 }
6420
Jim Grosbachb78403c2012-01-24 23:47:04 +00006421 // VLD3DUP single 3-element structure to all lanes instructions.
6422 case ARM::VLD3DUPdAsm_8:
6423 case ARM::VLD3DUPdAsm_16:
6424 case ARM::VLD3DUPdAsm_32:
6425 case ARM::VLD3DUPqAsm_8:
6426 case ARM::VLD3DUPqAsm_16:
6427 case ARM::VLD3DUPqAsm_32: {
6428 MCInst TmpInst;
6429 unsigned Spacing;
6430 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6431 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6432 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6433 Spacing));
6434 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6435 Spacing * 2));
6436 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6437 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6438 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6439 TmpInst.addOperand(Inst.getOperand(4));
6440 Inst = TmpInst;
6441 return true;
6442 }
6443
6444 case ARM::VLD3DUPdWB_fixed_Asm_8:
6445 case ARM::VLD3DUPdWB_fixed_Asm_16:
6446 case ARM::VLD3DUPdWB_fixed_Asm_32:
6447 case ARM::VLD3DUPqWB_fixed_Asm_8:
6448 case ARM::VLD3DUPqWB_fixed_Asm_16:
6449 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6450 MCInst TmpInst;
6451 unsigned Spacing;
6452 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6453 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6454 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6455 Spacing));
6456 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 Spacing * 2));
6458 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6459 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6460 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6461 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6462 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6463 TmpInst.addOperand(Inst.getOperand(4));
6464 Inst = TmpInst;
6465 return true;
6466 }
6467
6468 case ARM::VLD3DUPdWB_register_Asm_8:
6469 case ARM::VLD3DUPdWB_register_Asm_16:
6470 case ARM::VLD3DUPdWB_register_Asm_32:
6471 case ARM::VLD3DUPqWB_register_Asm_8:
6472 case ARM::VLD3DUPqWB_register_Asm_16:
6473 case ARM::VLD3DUPqWB_register_Asm_32: {
6474 MCInst TmpInst;
6475 unsigned Spacing;
6476 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6477 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 Spacing));
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 Spacing * 2));
6482 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6483 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6484 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6485 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6486 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6487 TmpInst.addOperand(Inst.getOperand(5));
6488 Inst = TmpInst;
6489 return true;
6490 }
6491
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006492 // VLD3 multiple 3-element structure instructions.
6493 case ARM::VLD3dAsm_8:
6494 case ARM::VLD3dAsm_16:
6495 case ARM::VLD3dAsm_32:
6496 case ARM::VLD3qAsm_8:
6497 case ARM::VLD3qAsm_16:
6498 case ARM::VLD3qAsm_32: {
6499 MCInst TmpInst;
6500 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006501 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006502 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 Spacing));
6505 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 Spacing * 2));
6507 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6508 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6509 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6510 TmpInst.addOperand(Inst.getOperand(4));
6511 Inst = TmpInst;
6512 return true;
6513 }
6514
6515 case ARM::VLD3dWB_fixed_Asm_8:
6516 case ARM::VLD3dWB_fixed_Asm_16:
6517 case ARM::VLD3dWB_fixed_Asm_32:
6518 case ARM::VLD3qWB_fixed_Asm_8:
6519 case ARM::VLD3qWB_fixed_Asm_16:
6520 case ARM::VLD3qWB_fixed_Asm_32: {
6521 MCInst TmpInst;
6522 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006523 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006524 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 Spacing));
6527 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6528 Spacing * 2));
6529 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6530 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6531 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6532 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6533 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6534 TmpInst.addOperand(Inst.getOperand(4));
6535 Inst = TmpInst;
6536 return true;
6537 }
6538
6539 case ARM::VLD3dWB_register_Asm_8:
6540 case ARM::VLD3dWB_register_Asm_16:
6541 case ARM::VLD3dWB_register_Asm_32:
6542 case ARM::VLD3qWB_register_Asm_8:
6543 case ARM::VLD3qWB_register_Asm_16:
6544 case ARM::VLD3qWB_register_Asm_32: {
6545 MCInst TmpInst;
6546 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006547 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006548 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6549 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6550 Spacing));
6551 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 Spacing * 2));
6553 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6554 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6555 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6556 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6557 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6558 TmpInst.addOperand(Inst.getOperand(5));
6559 Inst = TmpInst;
6560 return true;
6561 }
6562
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006563 // VLD4DUP single 3-element structure to all lanes instructions.
6564 case ARM::VLD4DUPdAsm_8:
6565 case ARM::VLD4DUPdAsm_16:
6566 case ARM::VLD4DUPdAsm_32:
6567 case ARM::VLD4DUPqAsm_8:
6568 case ARM::VLD4DUPqAsm_16:
6569 case ARM::VLD4DUPqAsm_32: {
6570 MCInst TmpInst;
6571 unsigned Spacing;
6572 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6573 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 Spacing));
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing * 2));
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 Spacing * 3));
6580 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6581 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6582 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6583 TmpInst.addOperand(Inst.getOperand(4));
6584 Inst = TmpInst;
6585 return true;
6586 }
6587
6588 case ARM::VLD4DUPdWB_fixed_Asm_8:
6589 case ARM::VLD4DUPdWB_fixed_Asm_16:
6590 case ARM::VLD4DUPdWB_fixed_Asm_32:
6591 case ARM::VLD4DUPqWB_fixed_Asm_8:
6592 case ARM::VLD4DUPqWB_fixed_Asm_16:
6593 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6594 MCInst TmpInst;
6595 unsigned Spacing;
6596 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6597 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6598 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 Spacing));
6600 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 Spacing * 2));
6602 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 Spacing * 3));
6604 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6605 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6606 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6607 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6608 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6609 TmpInst.addOperand(Inst.getOperand(4));
6610 Inst = TmpInst;
6611 return true;
6612 }
6613
6614 case ARM::VLD4DUPdWB_register_Asm_8:
6615 case ARM::VLD4DUPdWB_register_Asm_16:
6616 case ARM::VLD4DUPdWB_register_Asm_32:
6617 case ARM::VLD4DUPqWB_register_Asm_8:
6618 case ARM::VLD4DUPqWB_register_Asm_16:
6619 case ARM::VLD4DUPqWB_register_Asm_32: {
6620 MCInst TmpInst;
6621 unsigned Spacing;
6622 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6623 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6624 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6625 Spacing));
6626 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6627 Spacing * 2));
6628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6629 Spacing * 3));
6630 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6631 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6632 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6633 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6634 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6635 TmpInst.addOperand(Inst.getOperand(5));
6636 Inst = TmpInst;
6637 return true;
6638 }
6639
6640 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006641 case ARM::VLD4dAsm_8:
6642 case ARM::VLD4dAsm_16:
6643 case ARM::VLD4dAsm_32:
6644 case ARM::VLD4qAsm_8:
6645 case ARM::VLD4qAsm_16:
6646 case ARM::VLD4qAsm_32: {
6647 MCInst TmpInst;
6648 unsigned Spacing;
6649 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6650 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6651 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 Spacing));
6653 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6654 Spacing * 2));
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 Spacing * 3));
6657 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6658 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6659 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6660 TmpInst.addOperand(Inst.getOperand(4));
6661 Inst = TmpInst;
6662 return true;
6663 }
6664
6665 case ARM::VLD4dWB_fixed_Asm_8:
6666 case ARM::VLD4dWB_fixed_Asm_16:
6667 case ARM::VLD4dWB_fixed_Asm_32:
6668 case ARM::VLD4qWB_fixed_Asm_8:
6669 case ARM::VLD4qWB_fixed_Asm_16:
6670 case ARM::VLD4qWB_fixed_Asm_32: {
6671 MCInst TmpInst;
6672 unsigned Spacing;
6673 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6674 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6675 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 Spacing));
6677 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 Spacing * 2));
6679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6680 Spacing * 3));
6681 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6682 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6683 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6684 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6685 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6686 TmpInst.addOperand(Inst.getOperand(4));
6687 Inst = TmpInst;
6688 return true;
6689 }
6690
6691 case ARM::VLD4dWB_register_Asm_8:
6692 case ARM::VLD4dWB_register_Asm_16:
6693 case ARM::VLD4dWB_register_Asm_32:
6694 case ARM::VLD4qWB_register_Asm_8:
6695 case ARM::VLD4qWB_register_Asm_16:
6696 case ARM::VLD4qWB_register_Asm_32: {
6697 MCInst TmpInst;
6698 unsigned Spacing;
6699 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6700 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6701 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6702 Spacing));
6703 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 Spacing * 2));
6705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 Spacing * 3));
6707 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6708 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6709 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6710 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6711 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6712 TmpInst.addOperand(Inst.getOperand(5));
6713 Inst = TmpInst;
6714 return true;
6715 }
6716
Jim Grosbach1a747242012-01-23 23:45:44 +00006717 // VST3 multiple 3-element structure instructions.
6718 case ARM::VST3dAsm_8:
6719 case ARM::VST3dAsm_16:
6720 case ARM::VST3dAsm_32:
6721 case ARM::VST3qAsm_8:
6722 case ARM::VST3qAsm_16:
6723 case ARM::VST3qAsm_32: {
6724 MCInst TmpInst;
6725 unsigned Spacing;
6726 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6727 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6728 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6729 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6731 Spacing));
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 Spacing * 2));
6734 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6735 TmpInst.addOperand(Inst.getOperand(4));
6736 Inst = TmpInst;
6737 return true;
6738 }
6739
6740 case ARM::VST3dWB_fixed_Asm_8:
6741 case ARM::VST3dWB_fixed_Asm_16:
6742 case ARM::VST3dWB_fixed_Asm_32:
6743 case ARM::VST3qWB_fixed_Asm_8:
6744 case ARM::VST3qWB_fixed_Asm_16:
6745 case ARM::VST3qWB_fixed_Asm_32: {
6746 MCInst TmpInst;
6747 unsigned Spacing;
6748 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6749 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6751 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6752 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6753 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6755 Spacing));
6756 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6757 Spacing * 2));
6758 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6759 TmpInst.addOperand(Inst.getOperand(4));
6760 Inst = TmpInst;
6761 return true;
6762 }
6763
6764 case ARM::VST3dWB_register_Asm_8:
6765 case ARM::VST3dWB_register_Asm_16:
6766 case ARM::VST3dWB_register_Asm_32:
6767 case ARM::VST3qWB_register_Asm_8:
6768 case ARM::VST3qWB_register_Asm_16:
6769 case ARM::VST3qWB_register_Asm_32: {
6770 MCInst TmpInst;
6771 unsigned Spacing;
6772 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6773 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6774 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6775 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6776 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6777 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6778 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6779 Spacing));
6780 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 Spacing * 2));
6782 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6783 TmpInst.addOperand(Inst.getOperand(5));
6784 Inst = TmpInst;
6785 return true;
6786 }
6787
Jim Grosbachda70eac2012-01-24 00:58:13 +00006788 // VST4 multiple 3-element structure instructions.
6789 case ARM::VST4dAsm_8:
6790 case ARM::VST4dAsm_16:
6791 case ARM::VST4dAsm_32:
6792 case ARM::VST4qAsm_8:
6793 case ARM::VST4qAsm_16:
6794 case ARM::VST4qAsm_32: {
6795 MCInst TmpInst;
6796 unsigned Spacing;
6797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6798 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6799 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6800 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6802 Spacing));
6803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6804 Spacing * 2));
6805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6806 Spacing * 3));
6807 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6808 TmpInst.addOperand(Inst.getOperand(4));
6809 Inst = TmpInst;
6810 return true;
6811 }
6812
6813 case ARM::VST4dWB_fixed_Asm_8:
6814 case ARM::VST4dWB_fixed_Asm_16:
6815 case ARM::VST4dWB_fixed_Asm_32:
6816 case ARM::VST4qWB_fixed_Asm_8:
6817 case ARM::VST4qWB_fixed_Asm_16:
6818 case ARM::VST4qWB_fixed_Asm_32: {
6819 MCInst TmpInst;
6820 unsigned Spacing;
6821 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6822 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6823 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6824 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6825 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6826 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6827 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6828 Spacing));
6829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 Spacing * 2));
6831 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6832 Spacing * 3));
6833 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6834 TmpInst.addOperand(Inst.getOperand(4));
6835 Inst = TmpInst;
6836 return true;
6837 }
6838
6839 case ARM::VST4dWB_register_Asm_8:
6840 case ARM::VST4dWB_register_Asm_16:
6841 case ARM::VST4dWB_register_Asm_32:
6842 case ARM::VST4qWB_register_Asm_8:
6843 case ARM::VST4qWB_register_Asm_16:
6844 case ARM::VST4qWB_register_Asm_32: {
6845 MCInst TmpInst;
6846 unsigned Spacing;
6847 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6848 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6849 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6850 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6851 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6854 Spacing));
6855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6856 Spacing * 2));
6857 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6858 Spacing * 3));
6859 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6860 TmpInst.addOperand(Inst.getOperand(5));
6861 Inst = TmpInst;
6862 return true;
6863 }
6864
Jim Grosbachad66de12012-04-11 00:15:16 +00006865 // Handle encoding choice for the shift-immediate instructions.
6866 case ARM::t2LSLri:
6867 case ARM::t2LSRri:
6868 case ARM::t2ASRri: {
6869 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6870 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6871 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6872 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6873 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6874 unsigned NewOpc;
6875 switch (Inst.getOpcode()) {
6876 default: llvm_unreachable("unexpected opcode");
6877 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6878 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6879 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6880 }
6881 // The Thumb1 operands aren't in the same order. Awesome, eh?
6882 MCInst TmpInst;
6883 TmpInst.setOpcode(NewOpc);
6884 TmpInst.addOperand(Inst.getOperand(0));
6885 TmpInst.addOperand(Inst.getOperand(5));
6886 TmpInst.addOperand(Inst.getOperand(1));
6887 TmpInst.addOperand(Inst.getOperand(2));
6888 TmpInst.addOperand(Inst.getOperand(3));
6889 TmpInst.addOperand(Inst.getOperand(4));
6890 Inst = TmpInst;
6891 return true;
6892 }
6893 return false;
6894 }
6895
Jim Grosbach485e5622011-12-13 22:45:11 +00006896 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006897 case ARM::t2MOVsr:
6898 case ARM::t2MOVSsr: {
6899 // Which instruction to expand to depends on the CCOut operand and
6900 // whether we're in an IT block if the register operands are low
6901 // registers.
6902 bool isNarrow = false;
6903 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6904 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6905 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6906 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6907 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6908 isNarrow = true;
6909 MCInst TmpInst;
6910 unsigned newOpc;
6911 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6912 default: llvm_unreachable("unexpected opcode!");
6913 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6914 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6915 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6916 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6917 }
6918 TmpInst.setOpcode(newOpc);
6919 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6920 if (isNarrow)
6921 TmpInst.addOperand(MCOperand::CreateReg(
6922 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6923 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6924 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6925 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6926 TmpInst.addOperand(Inst.getOperand(5));
6927 if (!isNarrow)
6928 TmpInst.addOperand(MCOperand::CreateReg(
6929 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6930 Inst = TmpInst;
6931 return true;
6932 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006933 case ARM::t2MOVsi:
6934 case ARM::t2MOVSsi: {
6935 // Which instruction to expand to depends on the CCOut operand and
6936 // whether we're in an IT block if the register operands are low
6937 // registers.
6938 bool isNarrow = false;
6939 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6940 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6941 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6942 isNarrow = true;
6943 MCInst TmpInst;
6944 unsigned newOpc;
6945 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6946 default: llvm_unreachable("unexpected opcode!");
6947 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6948 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6949 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6950 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006951 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006952 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006953 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6954 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006955 TmpInst.setOpcode(newOpc);
6956 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6957 if (isNarrow)
6958 TmpInst.addOperand(MCOperand::CreateReg(
6959 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6960 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006961 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006962 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006963 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6964 TmpInst.addOperand(Inst.getOperand(4));
6965 if (!isNarrow)
6966 TmpInst.addOperand(MCOperand::CreateReg(
6967 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6968 Inst = TmpInst;
6969 return true;
6970 }
6971 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006972 case ARM::ASRr:
6973 case ARM::LSRr:
6974 case ARM::LSLr:
6975 case ARM::RORr: {
6976 ARM_AM::ShiftOpc ShiftTy;
6977 switch(Inst.getOpcode()) {
6978 default: llvm_unreachable("unexpected opcode!");
6979 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6980 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6981 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6982 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6983 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006984 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6985 MCInst TmpInst;
6986 TmpInst.setOpcode(ARM::MOVsr);
6987 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6988 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6989 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6990 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6991 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6992 TmpInst.addOperand(Inst.getOperand(4));
6993 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6994 Inst = TmpInst;
6995 return true;
6996 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006997 case ARM::ASRi:
6998 case ARM::LSRi:
6999 case ARM::LSLi:
7000 case ARM::RORi: {
7001 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007002 switch(Inst.getOpcode()) {
7003 default: llvm_unreachable("unexpected opcode!");
7004 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7005 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7006 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7007 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7008 }
7009 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007010 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007011 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007012 // A shift by 32 should be encoded as 0 when permitted
7013 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7014 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007015 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007016 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007017 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007018 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7019 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007020 if (Opc == ARM::MOVsi)
7021 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007022 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7023 TmpInst.addOperand(Inst.getOperand(4));
7024 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7025 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007026 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007027 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007028 case ARM::RRXi: {
7029 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7030 MCInst TmpInst;
7031 TmpInst.setOpcode(ARM::MOVsi);
7032 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7033 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7034 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7035 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7036 TmpInst.addOperand(Inst.getOperand(3));
7037 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7038 Inst = TmpInst;
7039 return true;
7040 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007041 case ARM::t2LDMIA_UPD: {
7042 // If this is a load of a single register, then we should use
7043 // a post-indexed LDR instruction instead, per the ARM ARM.
7044 if (Inst.getNumOperands() != 5)
7045 return false;
7046 MCInst TmpInst;
7047 TmpInst.setOpcode(ARM::t2LDR_POST);
7048 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7049 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7050 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7051 TmpInst.addOperand(MCOperand::CreateImm(4));
7052 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7053 TmpInst.addOperand(Inst.getOperand(3));
7054 Inst = TmpInst;
7055 return true;
7056 }
7057 case ARM::t2STMDB_UPD: {
7058 // If this is a store of a single register, then we should use
7059 // a pre-indexed STR instruction instead, per the ARM ARM.
7060 if (Inst.getNumOperands() != 5)
7061 return false;
7062 MCInst TmpInst;
7063 TmpInst.setOpcode(ARM::t2STR_PRE);
7064 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7065 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7066 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7067 TmpInst.addOperand(MCOperand::CreateImm(-4));
7068 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7069 TmpInst.addOperand(Inst.getOperand(3));
7070 Inst = TmpInst;
7071 return true;
7072 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007073 case ARM::LDMIA_UPD:
7074 // If this is a load of a single register via a 'pop', then we should use
7075 // a post-indexed LDR instruction instead, per the ARM ARM.
7076 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7077 Inst.getNumOperands() == 5) {
7078 MCInst TmpInst;
7079 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7080 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7081 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7082 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7083 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7084 TmpInst.addOperand(MCOperand::CreateImm(4));
7085 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7086 TmpInst.addOperand(Inst.getOperand(3));
7087 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007088 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007089 }
7090 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007091 case ARM::STMDB_UPD:
7092 // If this is a store of a single register via a 'push', then we should use
7093 // a pre-indexed STR instruction instead, per the ARM ARM.
7094 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7095 Inst.getNumOperands() == 5) {
7096 MCInst TmpInst;
7097 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7098 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7099 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7100 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7101 TmpInst.addOperand(MCOperand::CreateImm(-4));
7102 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7103 TmpInst.addOperand(Inst.getOperand(3));
7104 Inst = TmpInst;
7105 }
7106 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007107 case ARM::t2ADDri12:
7108 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7109 // mnemonic was used (not "addw"), encoding T3 is preferred.
7110 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7111 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7112 break;
7113 Inst.setOpcode(ARM::t2ADDri);
7114 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7115 break;
7116 case ARM::t2SUBri12:
7117 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7118 // mnemonic was used (not "subw"), encoding T3 is preferred.
7119 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7120 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7121 break;
7122 Inst.setOpcode(ARM::t2SUBri);
7123 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7124 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007125 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007126 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007127 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7128 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7129 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007130 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007131 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007132 return true;
7133 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007134 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007135 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007136 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007137 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7138 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7139 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007140 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007141 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007142 return true;
7143 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007144 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007145 case ARM::t2ADDri:
7146 case ARM::t2SUBri: {
7147 // If the destination and first source operand are the same, and
7148 // the flags are compatible with the current IT status, use encoding T2
7149 // instead of T3. For compatibility with the system 'as'. Make sure the
7150 // wide encoding wasn't explicit.
7151 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007152 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007153 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7154 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7155 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7156 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7157 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7158 break;
7159 MCInst TmpInst;
7160 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7161 ARM::tADDi8 : ARM::tSUBi8);
7162 TmpInst.addOperand(Inst.getOperand(0));
7163 TmpInst.addOperand(Inst.getOperand(5));
7164 TmpInst.addOperand(Inst.getOperand(0));
7165 TmpInst.addOperand(Inst.getOperand(2));
7166 TmpInst.addOperand(Inst.getOperand(3));
7167 TmpInst.addOperand(Inst.getOperand(4));
7168 Inst = TmpInst;
7169 return true;
7170 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007171 case ARM::t2ADDrr: {
7172 // If the destination and first source operand are the same, and
7173 // there's no setting of the flags, use encoding T2 instead of T3.
7174 // Note that this is only for ADD, not SUB. This mirrors the system
7175 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7176 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7177 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007178 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7179 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007180 break;
7181 MCInst TmpInst;
7182 TmpInst.setOpcode(ARM::tADDhirr);
7183 TmpInst.addOperand(Inst.getOperand(0));
7184 TmpInst.addOperand(Inst.getOperand(0));
7185 TmpInst.addOperand(Inst.getOperand(2));
7186 TmpInst.addOperand(Inst.getOperand(3));
7187 TmpInst.addOperand(Inst.getOperand(4));
7188 Inst = TmpInst;
7189 return true;
7190 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007191 case ARM::tADDrSP: {
7192 // If the non-SP source operand and the destination operand are not the
7193 // same, we need to use the 32-bit encoding if it's available.
7194 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7195 Inst.setOpcode(ARM::t2ADDrr);
7196 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7197 return true;
7198 }
7199 break;
7200 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007201 case ARM::tB:
7202 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007203 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007204 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007205 return true;
7206 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007207 break;
7208 case ARM::t2B:
7209 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007210 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007211 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007212 return true;
7213 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007214 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007215 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007216 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007217 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007218 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007219 return true;
7220 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007221 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007222 case ARM::tBcc:
7223 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007224 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007225 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007226 return true;
7227 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007228 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007229 case ARM::tLDMIA: {
7230 // If the register list contains any high registers, or if the writeback
7231 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7232 // instead if we're in Thumb2. Otherwise, this should have generated
7233 // an error in validateInstruction().
7234 unsigned Rn = Inst.getOperand(0).getReg();
7235 bool hasWritebackToken =
7236 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7237 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7238 bool listContainsBase;
7239 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7240 (!listContainsBase && !hasWritebackToken) ||
7241 (listContainsBase && hasWritebackToken)) {
7242 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7243 assert (isThumbTwo());
7244 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7245 // If we're switching to the updating version, we need to insert
7246 // the writeback tied operand.
7247 if (hasWritebackToken)
7248 Inst.insert(Inst.begin(),
7249 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007250 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007251 }
7252 break;
7253 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007254 case ARM::tSTMIA_UPD: {
7255 // If the register list contains any high registers, we need to use
7256 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7257 // should have generated an error in validateInstruction().
7258 unsigned Rn = Inst.getOperand(0).getReg();
7259 bool listContainsBase;
7260 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7261 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7262 assert (isThumbTwo());
7263 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007264 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007265 }
7266 break;
7267 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007268 case ARM::tPOP: {
7269 bool listContainsBase;
7270 // If the register list contains any high registers, we need to use
7271 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7272 // should have generated an error in validateInstruction().
7273 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007274 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007275 assert (isThumbTwo());
7276 Inst.setOpcode(ARM::t2LDMIA_UPD);
7277 // Add the base register and writeback operands.
7278 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7279 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007280 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007281 }
7282 case ARM::tPUSH: {
7283 bool listContainsBase;
7284 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007285 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007286 assert (isThumbTwo());
7287 Inst.setOpcode(ARM::t2STMDB_UPD);
7288 // Add the base register and writeback operands.
7289 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7290 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007291 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007292 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007293 case ARM::t2MOVi: {
7294 // If we can use the 16-bit encoding and the user didn't explicitly
7295 // request the 32-bit variant, transform it here.
7296 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007297 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007298 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7299 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7300 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007301 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7302 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7303 // The operands aren't in the same order for tMOVi8...
7304 MCInst TmpInst;
7305 TmpInst.setOpcode(ARM::tMOVi8);
7306 TmpInst.addOperand(Inst.getOperand(0));
7307 TmpInst.addOperand(Inst.getOperand(4));
7308 TmpInst.addOperand(Inst.getOperand(1));
7309 TmpInst.addOperand(Inst.getOperand(2));
7310 TmpInst.addOperand(Inst.getOperand(3));
7311 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007312 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007313 }
7314 break;
7315 }
7316 case ARM::t2MOVr: {
7317 // If we can use the 16-bit encoding and the user didn't explicitly
7318 // request the 32-bit variant, transform it here.
7319 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7320 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7321 Inst.getOperand(2).getImm() == ARMCC::AL &&
7322 Inst.getOperand(4).getReg() == ARM::CPSR &&
7323 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7324 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7325 // The operands aren't the same for tMOV[S]r... (no cc_out)
7326 MCInst TmpInst;
7327 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7328 TmpInst.addOperand(Inst.getOperand(0));
7329 TmpInst.addOperand(Inst.getOperand(1));
7330 TmpInst.addOperand(Inst.getOperand(2));
7331 TmpInst.addOperand(Inst.getOperand(3));
7332 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007333 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007334 }
7335 break;
7336 }
Jim Grosbach82213192011-09-19 20:29:33 +00007337 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007338 case ARM::t2SXTB:
7339 case ARM::t2UXTH:
7340 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007341 // If we can use the 16-bit encoding and the user didn't explicitly
7342 // request the 32-bit variant, transform it here.
7343 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7344 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7345 Inst.getOperand(2).getImm() == 0 &&
7346 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7347 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007348 unsigned NewOpc;
7349 switch (Inst.getOpcode()) {
7350 default: llvm_unreachable("Illegal opcode!");
7351 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7352 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7353 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7354 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7355 }
Jim Grosbach82213192011-09-19 20:29:33 +00007356 // The operands aren't the same for thumb1 (no rotate operand).
7357 MCInst TmpInst;
7358 TmpInst.setOpcode(NewOpc);
7359 TmpInst.addOperand(Inst.getOperand(0));
7360 TmpInst.addOperand(Inst.getOperand(1));
7361 TmpInst.addOperand(Inst.getOperand(3));
7362 TmpInst.addOperand(Inst.getOperand(4));
7363 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007364 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007365 }
7366 break;
7367 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007368 case ARM::MOVsi: {
7369 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007370 // rrx shifts and asr/lsr of #32 is encoded as 0
7371 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7372 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007373 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7374 // Shifting by zero is accepted as a vanilla 'MOVr'
7375 MCInst TmpInst;
7376 TmpInst.setOpcode(ARM::MOVr);
7377 TmpInst.addOperand(Inst.getOperand(0));
7378 TmpInst.addOperand(Inst.getOperand(1));
7379 TmpInst.addOperand(Inst.getOperand(3));
7380 TmpInst.addOperand(Inst.getOperand(4));
7381 TmpInst.addOperand(Inst.getOperand(5));
7382 Inst = TmpInst;
7383 return true;
7384 }
7385 return false;
7386 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007387 case ARM::ANDrsi:
7388 case ARM::ORRrsi:
7389 case ARM::EORrsi:
7390 case ARM::BICrsi:
7391 case ARM::SUBrsi:
7392 case ARM::ADDrsi: {
7393 unsigned newOpc;
7394 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7395 if (SOpc == ARM_AM::rrx) return false;
7396 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007397 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007398 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7399 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7400 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7401 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7402 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7403 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7404 }
7405 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007406 // The exception is for right shifts, where 0 == 32
7407 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7408 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007409 MCInst TmpInst;
7410 TmpInst.setOpcode(newOpc);
7411 TmpInst.addOperand(Inst.getOperand(0));
7412 TmpInst.addOperand(Inst.getOperand(1));
7413 TmpInst.addOperand(Inst.getOperand(2));
7414 TmpInst.addOperand(Inst.getOperand(4));
7415 TmpInst.addOperand(Inst.getOperand(5));
7416 TmpInst.addOperand(Inst.getOperand(6));
7417 Inst = TmpInst;
7418 return true;
7419 }
7420 return false;
7421 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007422 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007423 case ARM::t2IT: {
7424 // The mask bits for all but the first condition are represented as
7425 // the low bit of the condition code value implies 't'. We currently
7426 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007427 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007428 MCOperand &MO = Inst.getOperand(1);
7429 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007430 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007431 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007432 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007433 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007434 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007435 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007436 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007437
7438 // Set up the IT block state according to the IT instruction we just
7439 // matched.
7440 assert(!inITBlock() && "nested IT blocks?!");
7441 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7442 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7443 ITState.CurPosition = 0;
7444 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007445 break;
7446 }
Richard Bartona39625e2012-07-09 16:12:24 +00007447 case ARM::t2LSLrr:
7448 case ARM::t2LSRrr:
7449 case ARM::t2ASRrr:
7450 case ARM::t2SBCrr:
7451 case ARM::t2RORrr:
7452 case ARM::t2BICrr:
7453 {
Richard Bartond5660372012-07-09 16:14:28 +00007454 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007455 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7456 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7457 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007458 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7459 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007460 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7461 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7462 unsigned NewOpc;
7463 switch (Inst.getOpcode()) {
7464 default: llvm_unreachable("unexpected opcode");
7465 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7466 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7467 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7468 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7469 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7470 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7471 }
7472 MCInst TmpInst;
7473 TmpInst.setOpcode(NewOpc);
7474 TmpInst.addOperand(Inst.getOperand(0));
7475 TmpInst.addOperand(Inst.getOperand(5));
7476 TmpInst.addOperand(Inst.getOperand(1));
7477 TmpInst.addOperand(Inst.getOperand(2));
7478 TmpInst.addOperand(Inst.getOperand(3));
7479 TmpInst.addOperand(Inst.getOperand(4));
7480 Inst = TmpInst;
7481 return true;
7482 }
7483 return false;
7484 }
7485 case ARM::t2ANDrr:
7486 case ARM::t2EORrr:
7487 case ARM::t2ADCrr:
7488 case ARM::t2ORRrr:
7489 {
Richard Bartond5660372012-07-09 16:14:28 +00007490 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007491 // These instructions are special in that they are commutable, so shorter encodings
7492 // are available more often.
7493 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7494 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7495 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7496 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007497 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7498 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007499 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7500 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7501 unsigned NewOpc;
7502 switch (Inst.getOpcode()) {
7503 default: llvm_unreachable("unexpected opcode");
7504 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7505 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7506 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7507 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7508 }
7509 MCInst TmpInst;
7510 TmpInst.setOpcode(NewOpc);
7511 TmpInst.addOperand(Inst.getOperand(0));
7512 TmpInst.addOperand(Inst.getOperand(5));
7513 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7514 TmpInst.addOperand(Inst.getOperand(1));
7515 TmpInst.addOperand(Inst.getOperand(2));
7516 } else {
7517 TmpInst.addOperand(Inst.getOperand(2));
7518 TmpInst.addOperand(Inst.getOperand(1));
7519 }
7520 TmpInst.addOperand(Inst.getOperand(3));
7521 TmpInst.addOperand(Inst.getOperand(4));
7522 Inst = TmpInst;
7523 return true;
7524 }
7525 return false;
7526 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007527 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007528 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007529}
7530
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007531unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7532 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7533 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007534 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007535 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007536 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7537 assert(MCID.hasOptionalDef() &&
7538 "optionally flag setting instruction missing optional def operand");
7539 assert(MCID.NumOperands == Inst.getNumOperands() &&
7540 "operand count mismatch!");
7541 // Find the optional-def operand (cc_out).
7542 unsigned OpNo;
7543 for (OpNo = 0;
7544 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7545 ++OpNo)
7546 ;
7547 // If we're parsing Thumb1, reject it completely.
7548 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7549 return Match_MnemonicFail;
7550 // If we're parsing Thumb2, which form is legal depends on whether we're
7551 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007552 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7553 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007554 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007555 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7556 inITBlock())
7557 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007558 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007559 // Some high-register supporting Thumb1 encodings only allow both registers
7560 // to be from r0-r7 when in Thumb2.
7561 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7562 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7563 isARMLowRegister(Inst.getOperand(2).getReg()))
7564 return Match_RequiresThumb2;
7565 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007566 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007567 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7568 isARMLowRegister(Inst.getOperand(1).getReg()))
7569 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007570 return Match_Success;
7571}
7572
Jim Grosbach5117ef72012-04-24 22:40:08 +00007573static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007574bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007575MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007576 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007577 MCStreamer &Out, unsigned &ErrorInfo,
7578 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007579 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007580 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007581
Chad Rosier2f480a82012-10-12 22:53:36 +00007582 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007583 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007584 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007585 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007586 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007587 // Context sensitive operand constraints aren't handled by the matcher,
7588 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007589 if (validateInstruction(Inst, Operands)) {
7590 // Still progress the IT block, otherwise one wrong condition causes
7591 // nasty cascading errors.
7592 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007593 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007594 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007595
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007596 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007597 // encoding is selected. Loop on it while changes happen so the
7598 // individual transformations can chain off each other. E.g.,
7599 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7600 while (processInstruction(Inst, Operands))
7601 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007602
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007603 // Only move forward at the very end so that everything in validate
7604 // and process gets a consistent answer about whether we're in an IT
7605 // block.
7606 forwardITPosition();
7607
Jim Grosbach82f76d12012-01-25 19:52:01 +00007608 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7609 // doesn't actually encode.
7610 if (Inst.getOpcode() == ARM::ITasm)
7611 return false;
7612
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007613 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007614 Out.EmitInstruction(Inst);
7615 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007616 case Match_MissingFeature: {
7617 assert(ErrorInfo && "Unknown missing feature!");
7618 // Special case the error message for the very common case where only
7619 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7620 std::string Msg = "instruction requires:";
7621 unsigned Mask = 1;
7622 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7623 if (ErrorInfo & Mask) {
7624 Msg += " ";
7625 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7626 }
7627 Mask <<= 1;
7628 }
7629 return Error(IDLoc, Msg);
7630 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007631 case Match_InvalidOperand: {
7632 SMLoc ErrorLoc = IDLoc;
7633 if (ErrorInfo != ~0U) {
7634 if (ErrorInfo >= Operands.size())
7635 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007636
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007637 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7638 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7639 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007640
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007641 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007642 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007643 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007644 return Error(IDLoc, "invalid instruction",
7645 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007646 case Match_RequiresNotITBlock:
7647 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007648 case Match_RequiresITBlock:
7649 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007650 case Match_RequiresV6:
7651 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7652 case Match_RequiresThumb2:
7653 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007654 case Match_ImmRange0_4: {
7655 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7656 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7657 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7658 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007659 case Match_ImmRange0_15: {
7660 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7661 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7662 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7663 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007664 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007665
Eric Christopher91d7b902010-10-29 09:26:59 +00007666 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007667}
7668
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007669/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007670bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7671 StringRef IDVal = DirectiveID.getIdentifier();
7672 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007673 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007674 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007675 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007676 else if (IDVal == ".arm")
7677 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007678 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007679 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007680 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007681 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007682 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007683 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007684 else if (IDVal == ".unreq")
7685 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007686 else if (IDVal == ".arch")
7687 return parseDirectiveArch(DirectiveID.getLoc());
7688 else if (IDVal == ".eabi_attribute")
7689 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007690 else if (IDVal == ".fnstart")
7691 return parseDirectiveFnStart(DirectiveID.getLoc());
7692 else if (IDVal == ".fnend")
7693 return parseDirectiveFnEnd(DirectiveID.getLoc());
7694 else if (IDVal == ".cantunwind")
7695 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7696 else if (IDVal == ".personality")
7697 return parseDirectivePersonality(DirectiveID.getLoc());
7698 else if (IDVal == ".handlerdata")
7699 return parseDirectiveHandlerData(DirectiveID.getLoc());
7700 else if (IDVal == ".setfp")
7701 return parseDirectiveSetFP(DirectiveID.getLoc());
7702 else if (IDVal == ".pad")
7703 return parseDirectivePad(DirectiveID.getLoc());
7704 else if (IDVal == ".save")
7705 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7706 else if (IDVal == ".vsave")
7707 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007708 return true;
7709}
7710
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007711/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007712/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007713bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007714 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7715 for (;;) {
7716 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007717 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007718 return true;
7719
Eric Christopherbf7bc492013-01-09 03:52:05 +00007720 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007721
7722 if (getLexer().is(AsmToken::EndOfStatement))
7723 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007724
Kevin Enderbyccab3172009-09-15 00:27:25 +00007725 // FIXME: Improve diagnostic.
7726 if (getLexer().isNot(AsmToken::Comma))
7727 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007728 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007729 }
7730 }
7731
Sean Callanana83fd7d2010-01-19 20:27:46 +00007732 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007733 return false;
7734}
7735
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007736/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007737/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007738bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007739 if (getLexer().isNot(AsmToken::EndOfStatement))
7740 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007741 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007742
Tim Northovera2292d02013-06-10 23:20:58 +00007743 if (!hasThumb())
7744 return Error(L, "target does not support Thumb mode");
7745
Jim Grosbach7f882392011-12-07 18:04:19 +00007746 if (!isThumb())
7747 SwitchMode();
7748 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7749 return false;
7750}
7751
7752/// parseDirectiveARM
7753/// ::= .arm
7754bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7755 if (getLexer().isNot(AsmToken::EndOfStatement))
7756 return Error(L, "unexpected token in directive");
7757 Parser.Lex();
7758
Tim Northovera2292d02013-06-10 23:20:58 +00007759 if (!hasARM())
7760 return Error(L, "target does not support ARM mode");
7761
Jim Grosbach7f882392011-12-07 18:04:19 +00007762 if (isThumb())
7763 SwitchMode();
7764 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007765 return false;
7766}
7767
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007768/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007769/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007770bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007771 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7772 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007773 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007774 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007775
Jim Grosbach1152cc02011-12-21 22:30:16 +00007776 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007777 // ELF doesn't
7778 if (isMachO) {
7779 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007780 if (Tok.isNot(AsmToken::EndOfStatement)) {
7781 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7782 return Error(L, "unexpected token in .thumb_func directive");
7783 Name = Tok.getIdentifier();
7784 Parser.Lex(); // Consume the identifier token.
7785 needFuncName = false;
7786 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007787 }
7788
Jim Grosbach1152cc02011-12-21 22:30:16 +00007789 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007790 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007791
7792 // Eat the end of statement and any blank lines that follow.
7793 while (getLexer().is(AsmToken::EndOfStatement))
7794 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007795
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007796 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007797 // We really should be checking the next symbol definition even if there's
7798 // stuff in between.
7799 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007800 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007801 }
7802
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007803 // Mark symbol as a thumb symbol.
7804 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7805 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007806 return false;
7807}
7808
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007809/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007810/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007811bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007812 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007813 if (Tok.isNot(AsmToken::Identifier))
7814 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007815 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007816 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007817 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007818 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007819 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007820 else
7821 return Error(L, "unrecognized syntax mode in .syntax directive");
7822
7823 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007824 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007825 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007826
7827 // TODO tell the MC streamer the mode
7828 // getParser().getStreamer().Emit???();
7829 return false;
7830}
7831
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007832/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007833/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007834bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007835 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007836 if (Tok.isNot(AsmToken::Integer))
7837 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007838 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007839 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007840 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007841 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007842 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007843 else
7844 return Error(L, "invalid operand to .code directive");
7845
7846 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007847 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007848 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007849
Evan Cheng284b4672011-07-08 22:36:29 +00007850 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007851 if (!hasThumb())
7852 return Error(L, "target does not support Thumb mode");
7853
Jim Grosbachf471ac32011-09-06 18:46:23 +00007854 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007855 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007856 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007857 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007858 if (!hasARM())
7859 return Error(L, "target does not support ARM mode");
7860
Jim Grosbachf471ac32011-09-06 18:46:23 +00007861 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007862 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007863 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007864 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007865
Kevin Enderby146dcf22009-10-15 20:48:48 +00007866 return false;
7867}
7868
Jim Grosbachab5830e2011-12-14 02:16:11 +00007869/// parseDirectiveReq
7870/// ::= name .req registername
7871bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7872 Parser.Lex(); // Eat the '.req' token.
7873 unsigned Reg;
7874 SMLoc SRegLoc, ERegLoc;
7875 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007876 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007877 return Error(SRegLoc, "register name expected");
7878 }
7879
7880 // Shouldn't be anything else.
7881 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007882 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007883 return Error(Parser.getTok().getLoc(),
7884 "unexpected input in .req directive.");
7885 }
7886
7887 Parser.Lex(); // Consume the EndOfStatement
7888
7889 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7890 return Error(SRegLoc, "redefinition of '" + Name +
7891 "' does not match original.");
7892
7893 return false;
7894}
7895
7896/// parseDirectiveUneq
7897/// ::= .unreq registername
7898bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7899 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007900 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007901 return Error(L, "unexpected input in .unreq directive.");
7902 }
7903 RegisterReqs.erase(Parser.getTok().getIdentifier());
7904 Parser.Lex(); // Eat the identifier.
7905 return false;
7906}
7907
Jason W Kim135d2442011-12-20 17:38:12 +00007908/// parseDirectiveArch
7909/// ::= .arch token
7910bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7911 return true;
7912}
7913
7914/// parseDirectiveEabiAttr
7915/// ::= .eabi_attribute int, int
7916bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7917 return true;
7918}
7919
Logan Chien4ea23b52013-05-10 16:17:24 +00007920/// parseDirectiveFnStart
7921/// ::= .fnstart
7922bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7923 if (FnStartLoc.isValid()) {
7924 Error(L, ".fnstart starts before the end of previous one");
7925 Error(FnStartLoc, "previous .fnstart starts here");
7926 return true;
7927 }
7928
7929 FnStartLoc = L;
7930 getParser().getStreamer().EmitFnStart();
7931 return false;
7932}
7933
7934/// parseDirectiveFnEnd
7935/// ::= .fnend
7936bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7937 // Check the ordering of unwind directives
7938 if (!FnStartLoc.isValid())
7939 return Error(L, ".fnstart must precede .fnend directive");
7940
7941 // Reset the unwind directives parser state
7942 resetUnwindDirectiveParserState();
7943
7944 getParser().getStreamer().EmitFnEnd();
7945 return false;
7946}
7947
7948/// parseDirectiveCantUnwind
7949/// ::= .cantunwind
7950bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7951 // Check the ordering of unwind directives
7952 CantUnwindLoc = L;
7953 if (!FnStartLoc.isValid())
7954 return Error(L, ".fnstart must precede .cantunwind directive");
7955 if (HandlerDataLoc.isValid()) {
7956 Error(L, ".cantunwind can't be used with .handlerdata directive");
7957 Error(HandlerDataLoc, ".handlerdata was specified here");
7958 return true;
7959 }
7960 if (PersonalityLoc.isValid()) {
7961 Error(L, ".cantunwind can't be used with .personality directive");
7962 Error(PersonalityLoc, ".personality was specified here");
7963 return true;
7964 }
7965
7966 getParser().getStreamer().EmitCantUnwind();
7967 return false;
7968}
7969
7970/// parseDirectivePersonality
7971/// ::= .personality name
7972bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7973 // Check the ordering of unwind directives
7974 PersonalityLoc = L;
7975 if (!FnStartLoc.isValid())
7976 return Error(L, ".fnstart must precede .personality directive");
7977 if (CantUnwindLoc.isValid()) {
7978 Error(L, ".personality can't be used with .cantunwind directive");
7979 Error(CantUnwindLoc, ".cantunwind was specified here");
7980 return true;
7981 }
7982 if (HandlerDataLoc.isValid()) {
7983 Error(L, ".personality must precede .handlerdata directive");
7984 Error(HandlerDataLoc, ".handlerdata was specified here");
7985 return true;
7986 }
7987
7988 // Parse the name of the personality routine
7989 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7990 Parser.eatToEndOfStatement();
7991 return Error(L, "unexpected input in .personality directive.");
7992 }
7993 StringRef Name(Parser.getTok().getIdentifier());
7994 Parser.Lex();
7995
7996 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7997 getParser().getStreamer().EmitPersonality(PR);
7998 return false;
7999}
8000
8001/// parseDirectiveHandlerData
8002/// ::= .handlerdata
8003bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8004 // Check the ordering of unwind directives
8005 HandlerDataLoc = L;
8006 if (!FnStartLoc.isValid())
8007 return Error(L, ".fnstart must precede .personality directive");
8008 if (CantUnwindLoc.isValid()) {
8009 Error(L, ".handlerdata can't be used with .cantunwind directive");
8010 Error(CantUnwindLoc, ".cantunwind was specified here");
8011 return true;
8012 }
8013
8014 getParser().getStreamer().EmitHandlerData();
8015 return false;
8016}
8017
8018/// parseDirectiveSetFP
8019/// ::= .setfp fpreg, spreg [, offset]
8020bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8021 // Check the ordering of unwind directives
8022 if (!FnStartLoc.isValid())
8023 return Error(L, ".fnstart must precede .setfp directive");
8024 if (HandlerDataLoc.isValid())
8025 return Error(L, ".setfp must precede .handlerdata directive");
8026
8027 // Parse fpreg
8028 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8029 int NewFPReg = tryParseRegister();
8030 if (NewFPReg == -1)
8031 return Error(NewFPRegLoc, "frame pointer register expected");
8032
8033 // Consume comma
8034 if (!Parser.getTok().is(AsmToken::Comma))
8035 return Error(Parser.getTok().getLoc(), "comma expected");
8036 Parser.Lex(); // skip comma
8037
8038 // Parse spreg
8039 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8040 int NewSPReg = tryParseRegister();
8041 if (NewSPReg == -1)
8042 return Error(NewSPRegLoc, "stack pointer register expected");
8043
8044 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8045 return Error(NewSPRegLoc,
8046 "register should be either $sp or the latest fp register");
8047
8048 // Update the frame pointer register
8049 FPReg = NewFPReg;
8050
8051 // Parse offset
8052 int64_t Offset = 0;
8053 if (Parser.getTok().is(AsmToken::Comma)) {
8054 Parser.Lex(); // skip comma
8055
8056 if (Parser.getTok().isNot(AsmToken::Hash) &&
8057 Parser.getTok().isNot(AsmToken::Dollar)) {
8058 return Error(Parser.getTok().getLoc(), "'#' expected");
8059 }
8060 Parser.Lex(); // skip hash token.
8061
8062 const MCExpr *OffsetExpr;
8063 SMLoc ExLoc = Parser.getTok().getLoc();
8064 SMLoc EndLoc;
8065 if (getParser().parseExpression(OffsetExpr, EndLoc))
8066 return Error(ExLoc, "malformed setfp offset");
8067 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8068 if (!CE)
8069 return Error(ExLoc, "setfp offset must be an immediate");
8070
8071 Offset = CE->getValue();
8072 }
8073
8074 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8075 static_cast<unsigned>(NewSPReg),
8076 Offset);
8077 return false;
8078}
8079
8080/// parseDirective
8081/// ::= .pad offset
8082bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8083 // Check the ordering of unwind directives
8084 if (!FnStartLoc.isValid())
8085 return Error(L, ".fnstart must precede .pad directive");
8086 if (HandlerDataLoc.isValid())
8087 return Error(L, ".pad must precede .handlerdata directive");
8088
8089 // Parse the offset
8090 if (Parser.getTok().isNot(AsmToken::Hash) &&
8091 Parser.getTok().isNot(AsmToken::Dollar)) {
8092 return Error(Parser.getTok().getLoc(), "'#' expected");
8093 }
8094 Parser.Lex(); // skip hash token.
8095
8096 const MCExpr *OffsetExpr;
8097 SMLoc ExLoc = Parser.getTok().getLoc();
8098 SMLoc EndLoc;
8099 if (getParser().parseExpression(OffsetExpr, EndLoc))
8100 return Error(ExLoc, "malformed pad offset");
8101 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8102 if (!CE)
8103 return Error(ExLoc, "pad offset must be an immediate");
8104
8105 getParser().getStreamer().EmitPad(CE->getValue());
8106 return false;
8107}
8108
8109/// parseDirectiveRegSave
8110/// ::= .save { registers }
8111/// ::= .vsave { registers }
8112bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8113 // Check the ordering of unwind directives
8114 if (!FnStartLoc.isValid())
8115 return Error(L, ".fnstart must precede .save or .vsave directives");
8116 if (HandlerDataLoc.isValid())
8117 return Error(L, ".save or .vsave must precede .handlerdata directive");
8118
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008119 // RAII object to make sure parsed operands are deleted.
8120 struct CleanupObject {
8121 SmallVector<MCParsedAsmOperand *, 1> Operands;
8122 ~CleanupObject() {
8123 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8124 delete Operands[I];
8125 }
8126 } CO;
8127
Logan Chien4ea23b52013-05-10 16:17:24 +00008128 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008129 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008130 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008131 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008132 if (!IsVector && !Op->isRegList())
8133 return Error(L, ".save expects GPR registers");
8134 if (IsVector && !Op->isDPRRegList())
8135 return Error(L, ".vsave expects DPR registers");
8136
8137 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8138 return false;
8139}
8140
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008141/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008142extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008143 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8144 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008145}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008146
Chris Lattner3e4582a2010-09-06 19:11:01 +00008147#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008148#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008149#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008150#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008151
8152// Define this matcher function after the auto-generated include so we
8153// have the match class enum definitions.
8154unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8155 unsigned Kind) {
8156 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8157 // If the kind is a token for a literal immediate, check if our asm
8158 // operand matches. This is for InstAliases which have a fixed-value
8159 // immediate in the syntax.
8160 if (Kind == MCK__35_0 && Op->isImm()) {
8161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8162 if (!CE)
8163 return Match_InvalidOperand;
8164 if (CE->getValue() == 0)
8165 return Match_Success;
8166 }
8167 return Match_InvalidOperand;
8168}