blob: 8eae642d5d99797ba249ff6c13ca5f516a1b657e [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"
21#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCInst.h"
24#include "llvm/MC/MCInstrDesc.h"
25#include "llvm/MC/MCParser/MCAsmLexer.h"
26#include "llvm/MC/MCParser/MCAsmParser.h"
27#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
28#include "llvm/MC/MCRegisterInfo.h"
29#include "llvm/MC/MCStreamer.h"
30#include "llvm/MC/MCSubtargetInfo.h"
31#include "llvm/Support/MathExtras.h"
32#include "llvm/Support/SourceMgr.h"
33#include "llvm/Support/TargetRegistry.h"
34#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000035
Kevin Enderbyccab3172009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000038namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000041
Jim Grosbach04945c42011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000043
Evan Cheng11424442011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000048
Jim Grosbachab5830e2011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbached16ec42011-08-29 22:24:09 +000052 struct {
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
60
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
64 // handling.
65
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
70 } ITState;
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000072 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
79 }
Jim Grosbached16ec42011-08-29 22:24:09 +000080
81
Kevin Enderbyccab3172009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
Benjamin Kramer673824b2012-04-15 17:04:27 +000085 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
88 }
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
92 }
Kevin Enderbyccab3172009-09-15 00:27:25 +000093
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000094 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +000096 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000097 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +000098 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000099 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000105 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000113
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000115 bool &CarrySetting, unsigned &ProcessorIMod,
116 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000118 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000119
Evan Cheng4d1ca962011-07-08 01:53:10 +0000120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000123 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000124 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000126 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
129 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
132 }
James Molloy21efa7d2011-09-28 14:21:38 +0000133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
135 }
Evan Cheng284b4672011-07-08 22:36:29 +0000136 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000139 }
James Molloy21efa7d2011-09-28 14:21:38 +0000140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
142 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000143
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000144 /// @name Auto-generated Match Functions
145 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000146
Chris Lattner3e4582a2010-09-06 19:11:01 +0000147#define GET_ASSEMBLER_HEADER
148#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000149
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000150 /// }
151
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000153 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000155 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000159 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000160 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000161 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000162 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000163 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000164 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
169 }
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
172 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
182 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000183
184 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000185 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
187 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000188 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000189 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000190 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000191 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000192 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000193 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000194 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000195 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000196 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000197 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000198 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000199 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000200 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000201 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000202 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000203 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000204 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000205 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000206 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000207 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000208 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000209 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
211 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000212 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000213 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000214 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000215 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000216 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000217 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000218 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000219 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000220 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000221 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000222 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000223 bool validateInstruction(MCInst &Inst,
224 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000225 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000226 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000227 bool shouldOmitCCOutOperand(StringRef Mnemonic,
228 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000229
Kevin Enderbyccab3172009-09-15 00:27:25 +0000230public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000231 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000232 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000233 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000234 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000235 Match_RequiresThumb2,
236#define GET_OPERAND_DIAGNOSTIC_TYPES
237#include "ARMGenAsmMatcher.inc"
238
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000239 };
240
Evan Cheng91111d22011-07-09 05:47:46 +0000241 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng11424442011-07-26 00:24:13 +0000242 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000243 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000244
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000245 // Cache the MCRegisterInfo.
246 MRI = &getContext().getRegisterInfo();
247
Evan Cheng4d1ca962011-07-08 01:53:10 +0000248 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000249 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000250
251 // Not in an ITBlock to start with.
252 ITState.CurPosition = ~0U;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000253 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000254
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000255 // Implementation of the MCTargetAsmParser interface:
256 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000257 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
258 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000259 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000260 bool ParseDirective(AsmToken DirectiveID);
261
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000262 unsigned checkTargetMatchPredicate(MCInst &Inst);
263
Chad Rosier49963552012-10-13 00:26:04 +0000264 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000265 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000266 MCStreamer &Out, unsigned &ErrorInfo,
267 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000268};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000269} // end anonymous namespace
270
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000271namespace {
272
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000273/// ARMOperand - Instances of this class represent a parsed ARM machine
274/// instruction.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000275class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000276 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000277 k_CondCode,
278 k_CCOut,
279 k_ITCondMask,
280 k_CoprocNum,
281 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000282 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000283 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000284 k_MemBarrierOpt,
285 k_Memory,
286 k_PostIndexRegister,
287 k_MSRMask,
288 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000289 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000290 k_Register,
291 k_RegisterList,
292 k_DPRRegisterList,
293 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000294 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000295 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000296 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000297 k_ShiftedRegister,
298 k_ShiftedImmediate,
299 k_ShifterImmediate,
300 k_RotateImmediate,
301 k_BitfieldDescriptor,
302 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000303 } Kind;
304
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000305 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000306 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000307
308 union {
309 struct {
Daniel Dunbard8042b72010-08-11 06:36:53 +0000310 ARMCC::CondCodes Val;
311 } CC;
312
313 struct {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000314 unsigned Val;
315 } Cop;
316
317 struct {
Jim Grosbach48399582011-10-12 17:34:41 +0000318 unsigned Val;
319 } CoprocOption;
320
321 struct {
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000322 unsigned Mask:4;
323 } ITMask;
324
325 struct {
326 ARM_MB::MemBOpt Val;
327 } MBOpt;
328
329 struct {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000330 ARM_PROC::IFlags Val;
331 } IFlags;
332
333 struct {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000334 unsigned Val;
335 } MMask;
336
337 struct {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000338 const char *Data;
339 unsigned Length;
340 } Tok;
341
342 struct {
343 unsigned RegNum;
344 } Reg;
345
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000346 // A vector register list is a sequential list of 1 to 4 registers.
347 struct {
348 unsigned RegNum;
349 unsigned Count;
Jim Grosbach04945c42011-12-02 00:35:16 +0000350 unsigned LaneIndex;
Jim Grosbach2f50e922011-12-15 21:44:33 +0000351 bool isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000352 } VectorList;
353
Bill Wendlingb884a8e2010-11-06 22:19:43 +0000354 struct {
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000355 unsigned Val;
356 } VectorIndex;
357
358 struct {
Kevin Enderbyf5079942009-10-13 22:19:02 +0000359 const MCExpr *Val;
360 } Imm;
Jim Grosbach624bcc72010-10-29 14:46:02 +0000361
Daniel Dunbar2be732a2011-01-10 15:26:21 +0000362 /// Combined record for all forms of ARM address expressions.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000363 struct {
364 unsigned BaseRegNum;
Jim Grosbachd3595712011-08-03 23:50:40 +0000365 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
366 // was specified.
367 const MCConstantExpr *OffsetImm; // Offset immediate value
368 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
369 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbacha95ec992011-10-11 17:29:55 +0000370 unsigned ShiftImm; // shift for OffsetReg.
371 unsigned Alignment; // 0 = no alignment specified
Jim Grosbachcef98cd2011-12-19 18:31:43 +0000372 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbachd3595712011-08-03 23:50:40 +0000373 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbach871dff72011-10-11 15:59:20 +0000374 } Memory;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000375
376 struct {
Jim Grosbachd3595712011-08-03 23:50:40 +0000377 unsigned RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +0000378 bool isAdd;
379 ARM_AM::ShiftOpc ShiftTy;
380 unsigned ShiftImm;
Jim Grosbachd3595712011-08-03 23:50:40 +0000381 } PostIdxReg;
382
383 struct {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000384 bool isASR;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000385 unsigned Imm;
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000386 } ShifterImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000387 struct {
388 ARM_AM::ShiftOpc ShiftTy;
389 unsigned SrcReg;
390 unsigned ShiftReg;
391 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000392 } RegShiftedReg;
Owen Andersonb595ed02011-07-21 18:54:16 +0000393 struct {
394 ARM_AM::ShiftOpc ShiftTy;
395 unsigned SrcReg;
396 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000397 } RegShiftedImm;
Jim Grosbach833b9d32011-07-27 20:15:40 +0000398 struct {
399 unsigned Imm;
400 } RotImm;
Jim Grosbach864b6092011-07-28 21:34:26 +0000401 struct {
402 unsigned LSB;
403 unsigned Width;
404 } Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000405 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000406
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000407 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
408public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000409 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
410 Kind = o.Kind;
411 StartLoc = o.StartLoc;
412 EndLoc = o.EndLoc;
413 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000414 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000415 CC = o.CC;
416 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000417 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000418 ITMask = o.ITMask;
419 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000420 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000421 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000422 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000423 case k_CCOut:
424 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000425 Reg = o.Reg;
426 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000427 case k_RegisterList:
428 case k_DPRRegisterList:
429 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000430 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000431 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000432 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000433 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000434 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000435 VectorList = o.VectorList;
436 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000437 case k_CoprocNum:
438 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000439 Cop = o.Cop;
440 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000441 case k_CoprocOption:
442 CoprocOption = o.CoprocOption;
443 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000444 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000445 Imm = o.Imm;
446 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000447 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000448 MBOpt = o.MBOpt;
449 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000450 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000451 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000452 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000453 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000454 PostIdxReg = o.PostIdxReg;
455 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000456 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000457 MMask = o.MMask;
458 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000459 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000460 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000462 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000463 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000465 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000466 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000468 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000469 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000470 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000471 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000472 RotImm = o.RotImm;
473 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000474 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000475 Bitfield = o.Bitfield;
476 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000477 case k_VectorIndex:
478 VectorIndex = o.VectorIndex;
479 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000480 }
481 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000482
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000483 /// getStartLoc - Get the location of the first token of this operand.
484 SMLoc getStartLoc() const { return StartLoc; }
485 /// getEndLoc - Get the location of the last token of this operand.
486 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000487 /// getLocRange - Get the range between the first and last token of this
488 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000489 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
490
Daniel Dunbard8042b72010-08-11 06:36:53 +0000491 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000492 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000493 return CC.Val;
494 }
495
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000496 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000497 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000498 return Cop.Val;
499 }
500
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000501 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000503 return StringRef(Tok.Data, Tok.Length);
504 }
505
506 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000507 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000508 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000509 }
510
Bill Wendlingbed94652010-11-09 23:28:44 +0000511 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
513 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000514 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000515 }
516
Kevin Enderbyf5079942009-10-13 22:19:02 +0000517 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000518 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000519 return Imm.Val;
520 }
521
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000522 unsigned getVectorIndex() const {
523 assert(Kind == k_VectorIndex && "Invalid access!");
524 return VectorIndex.Val;
525 }
526
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000527 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000528 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000529 return MBOpt.Val;
530 }
531
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000532 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000533 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000534 return IFlags.Val;
535 }
536
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000537 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000538 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000539 return MMask.Val;
540 }
541
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000542 bool isCoprocNum() const { return Kind == k_CoprocNum; }
543 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000544 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 bool isCondCode() const { return Kind == k_CondCode; }
546 bool isCCOut() const { return Kind == k_CCOut; }
547 bool isITMask() const { return Kind == k_ITCondMask; }
548 bool isITCondCode() const { return Kind == k_CondCode; }
549 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000550 bool isFPImm() const {
551 if (!isImm()) return false;
552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
553 if (!CE) return false;
554 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
555 return Val != -1;
556 }
Jim Grosbachea231912011-12-22 22:19:05 +0000557 bool isFBits16() const {
558 if (!isImm()) return false;
559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
560 if (!CE) return false;
561 int64_t Value = CE->getValue();
562 return Value >= 0 && Value <= 16;
563 }
564 bool isFBits32() const {
565 if (!isImm()) return false;
566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
567 if (!CE) return false;
568 int64_t Value = CE->getValue();
569 return Value >= 1 && Value <= 32;
570 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000571 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000572 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
574 if (!CE) return false;
575 int64_t Value = CE->getValue();
576 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
577 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000578 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000579 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
581 if (!CE) return false;
582 int64_t Value = CE->getValue();
583 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
584 }
585 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000586 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
588 if (!CE) return false;
589 int64_t Value = CE->getValue();
590 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
591 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000592 bool isImm0_508s4Neg() const {
593 if (!isImm()) return false;
594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
595 if (!CE) return false;
596 int64_t Value = -CE->getValue();
597 // explicitly exclude zero. we want that to use the normal 0_508 version.
598 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
599 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000600 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000601 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000602 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
603 if (!CE) return false;
604 int64_t Value = CE->getValue();
605 return Value >= 0 && Value < 256;
606 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000607 bool isImm0_4095() const {
608 if (!isImm()) return false;
609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
610 if (!CE) return false;
611 int64_t Value = CE->getValue();
612 return Value >= 0 && Value < 4096;
613 }
614 bool isImm0_4095Neg() const {
615 if (!isImm()) return false;
616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
617 if (!CE) return false;
618 int64_t Value = -CE->getValue();
619 return Value > 0 && Value < 4096;
620 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000621 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000622 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
624 if (!CE) return false;
625 int64_t Value = CE->getValue();
626 return Value >= 0 && Value < 2;
627 }
628 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000629 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
631 if (!CE) return false;
632 int64_t Value = CE->getValue();
633 return Value >= 0 && Value < 4;
634 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000635 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000636 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
638 if (!CE) return false;
639 int64_t Value = CE->getValue();
640 return Value >= 0 && Value < 8;
641 }
642 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000643 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
645 if (!CE) return false;
646 int64_t Value = CE->getValue();
647 return Value >= 0 && Value < 16;
648 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000649 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000650 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
652 if (!CE) return false;
653 int64_t Value = CE->getValue();
654 return Value >= 0 && Value < 32;
655 }
Jim Grosbach00326402011-12-08 01:30:04 +0000656 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000657 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
659 if (!CE) return false;
660 int64_t Value = CE->getValue();
661 return Value >= 0 && Value < 64;
662 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000663 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000664 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
666 if (!CE) return false;
667 int64_t Value = CE->getValue();
668 return Value == 8;
669 }
670 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000671 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
673 if (!CE) return false;
674 int64_t Value = CE->getValue();
675 return Value == 16;
676 }
677 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000678 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
680 if (!CE) return false;
681 int64_t Value = CE->getValue();
682 return Value == 32;
683 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000684 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000685 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
687 if (!CE) return false;
688 int64_t Value = CE->getValue();
689 return Value > 0 && Value <= 8;
690 }
691 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000692 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000693 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
694 if (!CE) return false;
695 int64_t Value = CE->getValue();
696 return Value > 0 && Value <= 16;
697 }
698 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000699 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
701 if (!CE) return false;
702 int64_t Value = CE->getValue();
703 return Value > 0 && Value <= 32;
704 }
705 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000706 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
708 if (!CE) return false;
709 int64_t Value = CE->getValue();
710 return Value > 0 && Value <= 64;
711 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000712 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000713 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000714 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
715 if (!CE) return false;
716 int64_t Value = CE->getValue();
717 return Value > 0 && Value < 8;
718 }
719 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000720 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
722 if (!CE) return false;
723 int64_t Value = CE->getValue();
724 return Value > 0 && Value < 16;
725 }
726 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000727 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
729 if (!CE) return false;
730 int64_t Value = CE->getValue();
731 return Value > 0 && Value < 32;
732 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000733 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000734 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
736 if (!CE) return false;
737 int64_t Value = CE->getValue();
738 return Value > 0 && Value < 17;
739 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000740 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000741 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
743 if (!CE) return false;
744 int64_t Value = CE->getValue();
745 return Value > 0 && Value < 33;
746 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000747 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000748 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
750 if (!CE) return false;
751 int64_t Value = CE->getValue();
752 return Value >= 0 && Value < 33;
753 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000754 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000755 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
757 if (!CE) return false;
758 int64_t Value = CE->getValue();
759 return Value >= 0 && Value < 65536;
760 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000761 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000762 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
764 // If it's not a constant expression, it'll generate a fixup and be
765 // handled later.
766 if (!CE) return true;
767 int64_t Value = CE->getValue();
768 return Value >= 0 && Value < 65536;
769 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000770 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000771 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
773 if (!CE) return false;
774 int64_t Value = CE->getValue();
775 return Value >= 0 && Value <= 0xffffff;
776 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000777 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000778 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
780 if (!CE) return false;
781 int64_t Value = CE->getValue();
782 return Value > 0 && Value < 33;
783 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000784 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000785 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
787 if (!CE) return false;
788 int64_t Value = CE->getValue();
789 return Value >= 0 && Value < 32;
790 }
791 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000792 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
794 if (!CE) return false;
795 int64_t Value = CE->getValue();
796 return Value > 0 && Value <= 32;
797 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000798 bool isAdrLabel() const {
799 // If we have an immediate that's not a constant, treat it as a label
800 // reference needing a fixup. If it is a constant, but it can't fit
801 // into shift immediate encoding, we reject it.
802 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
803 else return (isARMSOImm() || isARMSOImmNeg());
804 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000805 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000806 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000807 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
808 if (!CE) return false;
809 int64_t Value = CE->getValue();
810 return ARM_AM::getSOImmVal(Value) != -1;
811 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000812 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000813 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
815 if (!CE) return false;
816 int64_t Value = CE->getValue();
817 return ARM_AM::getSOImmVal(~Value) != -1;
818 }
Jim Grosbach30506252011-12-08 00:31:07 +0000819 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000820 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000824 // Only use this when not representable as a plain so_imm.
825 return ARM_AM::getSOImmVal(Value) == -1 &&
826 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000827 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000828 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000829 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
831 if (!CE) return false;
832 int64_t Value = CE->getValue();
833 return ARM_AM::getT2SOImmVal(Value) != -1;
834 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000835 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000836 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return ARM_AM::getT2SOImmVal(~Value) != -1;
841 }
Jim Grosbach30506252011-12-08 00:31:07 +0000842 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000843 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000847 // Only use this when not representable as a plain so_imm.
848 return ARM_AM::getT2SOImmVal(Value) == -1 &&
849 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000850 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000851 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000852 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
854 if (!CE) return false;
855 int64_t Value = CE->getValue();
856 return Value == 1 || Value == 0;
857 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000858 bool isReg() const { return Kind == k_Register; }
859 bool isRegList() const { return Kind == k_RegisterList; }
860 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
861 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
862 bool isToken() const { return Kind == k_Token; }
863 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000864 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000865 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
866 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
867 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
868 bool isRotImm() const { return Kind == k_RotateImmediate; }
869 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
870 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000871 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000872 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000873 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000874 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000875 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000876 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000877 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000878 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
879 (alignOK || Memory.Alignment == 0);
880 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000881 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000882 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000883 return false;
884 // Base register must be PC.
885 if (Memory.BaseRegNum != ARM::PC)
886 return false;
887 // Immediate offset in range [-4095, 4095].
888 if (!Memory.OffsetImm) return true;
889 int64_t Val = Memory.OffsetImm->getValue();
890 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
891 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000892 bool isAlignedMemory() const {
893 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000894 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000895 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000896 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000897 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000898 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000899 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000900 if (!Memory.OffsetImm) return true;
901 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000902 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000903 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000904 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000905 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000906 // Immediate offset in range [-4095, 4095].
907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Val = CE->getValue();
910 return Val > -4096 && Val < 4096;
911 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000912 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000913 // If we have an immediate that's not a constant, treat it as a label
914 // reference needing a fixup. If it is a constant, it's something else
915 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000917 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000918 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000919 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000920 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000921 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000922 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000923 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000924 if (!Memory.OffsetImm) return true;
925 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000926 // The #-0 offset is encoded as INT32_MIN, and we have to check
927 // for this too.
928 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000929 }
930 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000931 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000932 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000933 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000934 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
935 // Immediate offset in range [-255, 255].
936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000939 // Special case, #-0 is INT32_MIN.
940 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000941 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000942 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000943 // If we have an immediate that's not a constant, treat it as a label
944 // reference needing a fixup. If it is a constant, it's something else
945 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000946 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000947 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000948 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000949 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000950 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000951 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +0000952 if (!Memory.OffsetImm) return true;
953 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +0000954 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000955 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +0000956 }
Jim Grosbach05541f42011-09-19 22:21:13 +0000957 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +0000958 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000959 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +0000960 return false;
961 return true;
962 }
963 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +0000964 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000965 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
966 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +0000967 return false;
968 return true;
969 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000970 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000971 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +0000972 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +0000973 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000974 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000975 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000976 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000977 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000978 return false;
979 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +0000980 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000981 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +0000982 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000983 return false;
984 return true;
985 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000986 bool isMemThumbRR() const {
987 // Thumb reg+reg addressing is simple. Just two registers, a base and
988 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +0000989 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000990 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +0000991 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +0000992 return isARMLowRegister(Memory.BaseRegNum) &&
993 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000994 }
995 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +0000996 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000997 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000998 return false;
999 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001000 if (!Memory.OffsetImm) return true;
1001 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001002 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1003 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001004 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001005 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001006 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001007 return false;
1008 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001009 if (!Memory.OffsetImm) return true;
1010 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001011 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1012 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001013 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001014 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001015 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001016 return false;
1017 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001018 if (!Memory.OffsetImm) return true;
1019 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001020 return Val >= 0 && Val <= 31;
1021 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001022 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001023 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001024 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001025 return false;
1026 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001027 if (!Memory.OffsetImm) return true;
1028 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001029 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001030 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001031 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001032 // If we have an immediate that's not a constant, treat it as a label
1033 // reference needing a fixup. If it is a constant, it's something else
1034 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001035 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001036 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001037 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001038 return false;
1039 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001040 if (!Memory.OffsetImm) return true;
1041 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001042 // Special case, #-0 is INT32_MIN.
1043 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001044 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001045 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001046 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001047 return false;
1048 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001049 if (!Memory.OffsetImm) return true;
1050 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001051 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1052 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001053 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001054 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001055 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001056 // Base reg of PC isn't allowed for these encodings.
1057 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001058 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001059 if (!Memory.OffsetImm) return true;
1060 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001061 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001062 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001063 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001064 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001065 return false;
1066 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001067 if (!Memory.OffsetImm) return true;
1068 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001069 return Val >= 0 && Val < 256;
1070 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001071 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001072 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001073 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001074 // Base reg of PC isn't allowed for these encodings.
1075 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001076 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001077 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001078 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001079 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001080 }
1081 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001082 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001083 return false;
1084 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001085 if (!Memory.OffsetImm) return true;
1086 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001087 return (Val >= 0 && Val < 4096);
1088 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001089 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001090 // If we have an immediate that's not a constant, treat it as a label
1091 // reference needing a fixup. If it is a constant, it's something else
1092 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001093 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001094 return true;
1095
Chad Rosier41099832012-09-11 23:02:35 +00001096 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001097 return false;
1098 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001099 if (!Memory.OffsetImm) return true;
1100 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001101 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001102 }
1103 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001104 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001105 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1106 if (!CE) return false;
1107 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001108 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001109 }
Jim Grosbach93981412011-10-11 21:55:36 +00001110 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001111 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001112 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1113 if (!CE) return false;
1114 int64_t Val = CE->getValue();
1115 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1116 (Val == INT32_MIN);
1117 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001118
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001119 bool isMSRMask() const { return Kind == k_MSRMask; }
1120 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001121
Jim Grosbach741cd732011-10-17 22:26:03 +00001122 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001123 bool isSingleSpacedVectorList() const {
1124 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1125 }
1126 bool isDoubleSpacedVectorList() const {
1127 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1128 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001129 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001130 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001131 return VectorList.Count == 1;
1132 }
1133
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001134 bool isVecListDPair() const {
1135 if (!isSingleSpacedVectorList()) return false;
1136 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1137 .contains(VectorList.RegNum));
1138 }
1139
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001140 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001141 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001142 return VectorList.Count == 3;
1143 }
1144
Jim Grosbach846bcff2011-10-21 20:35:01 +00001145 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001146 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001147 return VectorList.Count == 4;
1148 }
1149
Jim Grosbache5307f92012-03-05 21:43:40 +00001150 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001151 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001152 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1153 .contains(VectorList.RegNum));
1154 }
1155
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001156 bool isVecListThreeQ() const {
1157 if (!isDoubleSpacedVectorList()) return false;
1158 return VectorList.Count == 3;
1159 }
1160
Jim Grosbach1e946a42012-01-24 00:43:12 +00001161 bool isVecListFourQ() const {
1162 if (!isDoubleSpacedVectorList()) return false;
1163 return VectorList.Count == 4;
1164 }
1165
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001166 bool isSingleSpacedVectorAllLanes() const {
1167 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1168 }
1169 bool isDoubleSpacedVectorAllLanes() const {
1170 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1171 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001172 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001173 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001174 return VectorList.Count == 1;
1175 }
1176
Jim Grosbach13a292c2012-03-06 22:01:44 +00001177 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001178 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001179 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1180 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001181 }
1182
Jim Grosbached428bc2012-03-06 23:10:38 +00001183 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001184 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001185 return VectorList.Count == 2;
1186 }
1187
Jim Grosbachb78403c2012-01-24 23:47:04 +00001188 bool isVecListThreeDAllLanes() const {
1189 if (!isSingleSpacedVectorAllLanes()) return false;
1190 return VectorList.Count == 3;
1191 }
1192
1193 bool isVecListThreeQAllLanes() const {
1194 if (!isDoubleSpacedVectorAllLanes()) return false;
1195 return VectorList.Count == 3;
1196 }
1197
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001198 bool isVecListFourDAllLanes() const {
1199 if (!isSingleSpacedVectorAllLanes()) return false;
1200 return VectorList.Count == 4;
1201 }
1202
1203 bool isVecListFourQAllLanes() const {
1204 if (!isDoubleSpacedVectorAllLanes()) return false;
1205 return VectorList.Count == 4;
1206 }
1207
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001208 bool isSingleSpacedVectorIndexed() const {
1209 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1210 }
1211 bool isDoubleSpacedVectorIndexed() const {
1212 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1213 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001214 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001215 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001216 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1217 }
1218
Jim Grosbachda511042011-12-14 23:35:06 +00001219 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001220 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001221 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1222 }
1223
1224 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001225 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001226 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1227 }
1228
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001229 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001230 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001231 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1232 }
1233
Jim Grosbachda511042011-12-14 23:35:06 +00001234 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001235 if (!isSingleSpacedVectorIndexed()) return false;
1236 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1237 }
1238
1239 bool isVecListTwoQWordIndexed() const {
1240 if (!isDoubleSpacedVectorIndexed()) return false;
1241 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1242 }
1243
1244 bool isVecListTwoQHWordIndexed() const {
1245 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001246 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1247 }
1248
1249 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001250 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001251 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1252 }
1253
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001254 bool isVecListThreeDByteIndexed() const {
1255 if (!isSingleSpacedVectorIndexed()) return false;
1256 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1257 }
1258
1259 bool isVecListThreeDHWordIndexed() const {
1260 if (!isSingleSpacedVectorIndexed()) return false;
1261 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1262 }
1263
1264 bool isVecListThreeQWordIndexed() const {
1265 if (!isDoubleSpacedVectorIndexed()) return false;
1266 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1267 }
1268
1269 bool isVecListThreeQHWordIndexed() const {
1270 if (!isDoubleSpacedVectorIndexed()) return false;
1271 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1272 }
1273
1274 bool isVecListThreeDWordIndexed() const {
1275 if (!isSingleSpacedVectorIndexed()) return false;
1276 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1277 }
1278
Jim Grosbach14952a02012-01-24 18:37:25 +00001279 bool isVecListFourDByteIndexed() const {
1280 if (!isSingleSpacedVectorIndexed()) return false;
1281 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1282 }
1283
1284 bool isVecListFourDHWordIndexed() const {
1285 if (!isSingleSpacedVectorIndexed()) return false;
1286 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1287 }
1288
1289 bool isVecListFourQWordIndexed() const {
1290 if (!isDoubleSpacedVectorIndexed()) return false;
1291 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1292 }
1293
1294 bool isVecListFourQHWordIndexed() const {
1295 if (!isDoubleSpacedVectorIndexed()) return false;
1296 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1297 }
1298
1299 bool isVecListFourDWordIndexed() const {
1300 if (!isSingleSpacedVectorIndexed()) return false;
1301 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1302 }
1303
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001304 bool isVectorIndex8() const {
1305 if (Kind != k_VectorIndex) return false;
1306 return VectorIndex.Val < 8;
1307 }
1308 bool isVectorIndex16() const {
1309 if (Kind != k_VectorIndex) return false;
1310 return VectorIndex.Val < 4;
1311 }
1312 bool isVectorIndex32() const {
1313 if (Kind != k_VectorIndex) return false;
1314 return VectorIndex.Val < 2;
1315 }
1316
Jim Grosbach741cd732011-10-17 22:26:03 +00001317 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001318 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001319 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1320 // Must be a constant.
1321 if (!CE) return false;
1322 int64_t Value = CE->getValue();
1323 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1324 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001325 return Value >= 0 && Value < 256;
1326 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001327
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001328 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001329 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1331 // Must be a constant.
1332 if (!CE) return false;
1333 int64_t Value = CE->getValue();
1334 // i16 value in the range [0,255] or [0x0100, 0xff00]
1335 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1336 }
1337
Jim Grosbach8211c052011-10-18 00:22:00 +00001338 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001339 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001340 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1341 // Must be a constant.
1342 if (!CE) return false;
1343 int64_t Value = CE->getValue();
1344 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1345 return (Value >= 0 && Value < 256) ||
1346 (Value >= 0x0100 && Value <= 0xff00) ||
1347 (Value >= 0x010000 && Value <= 0xff0000) ||
1348 (Value >= 0x01000000 && Value <= 0xff000000);
1349 }
1350
1351 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001352 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001353 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1354 // Must be a constant.
1355 if (!CE) return false;
1356 int64_t Value = CE->getValue();
1357 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1358 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1359 return (Value >= 0 && Value < 256) ||
1360 (Value >= 0x0100 && Value <= 0xff00) ||
1361 (Value >= 0x010000 && Value <= 0xff0000) ||
1362 (Value >= 0x01000000 && Value <= 0xff000000) ||
1363 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1364 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1365 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001366 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001367 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001368 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1369 // Must be a constant.
1370 if (!CE) return false;
1371 int64_t Value = ~CE->getValue();
1372 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1373 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1374 return (Value >= 0 && Value < 256) ||
1375 (Value >= 0x0100 && Value <= 0xff00) ||
1376 (Value >= 0x010000 && Value <= 0xff0000) ||
1377 (Value >= 0x01000000 && Value <= 0xff000000) ||
1378 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1379 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1380 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001381
Jim Grosbache4454e02011-10-18 16:18:11 +00001382 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001383 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001384 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1385 // Must be a constant.
1386 if (!CE) return false;
1387 uint64_t Value = CE->getValue();
1388 // i64 value with each byte being either 0 or 0xff.
1389 for (unsigned i = 0; i < 8; ++i)
1390 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1391 return true;
1392 }
1393
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001394 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001395 // Add as immediates when possible. Null MCExpr = 0.
1396 if (Expr == 0)
1397 Inst.addOperand(MCOperand::CreateImm(0));
1398 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001399 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1400 else
1401 Inst.addOperand(MCOperand::CreateExpr(Expr));
1402 }
1403
Daniel Dunbard8042b72010-08-11 06:36:53 +00001404 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001405 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001406 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001407 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1408 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001409 }
1410
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001411 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1412 assert(N == 1 && "Invalid number of operands!");
1413 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1414 }
1415
Jim Grosbach48399582011-10-12 17:34:41 +00001416 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1417 assert(N == 1 && "Invalid number of operands!");
1418 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1419 }
1420
1421 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1422 assert(N == 1 && "Invalid number of operands!");
1423 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1424 }
1425
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001426 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1427 assert(N == 1 && "Invalid number of operands!");
1428 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1429 }
1430
1431 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1432 assert(N == 1 && "Invalid number of operands!");
1433 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1434 }
1435
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001436 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1437 assert(N == 1 && "Invalid number of operands!");
1438 Inst.addOperand(MCOperand::CreateReg(getReg()));
1439 }
1440
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001441 void addRegOperands(MCInst &Inst, unsigned N) const {
1442 assert(N == 1 && "Invalid number of operands!");
1443 Inst.addOperand(MCOperand::CreateReg(getReg()));
1444 }
1445
Jim Grosbachac798e12011-07-25 20:49:51 +00001446 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001447 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001448 assert(isRegShiftedReg() &&
1449 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001450 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1451 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001452 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001453 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001454 }
1455
Jim Grosbachac798e12011-07-25 20:49:51 +00001456 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001457 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001458 assert(isRegShiftedImm() &&
1459 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001460 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001461 // Shift of #32 is encoded as 0 where permitted
1462 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001463 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001464 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001465 }
1466
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001467 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001468 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001469 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1470 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001471 }
1472
Bill Wendling8d2aa032010-11-08 23:49:57 +00001473 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001474 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001475 const SmallVectorImpl<unsigned> &RegList = getRegList();
1476 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001477 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1478 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001479 }
1480
Bill Wendling9898ac92010-11-17 04:32:08 +00001481 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1482 addRegListOperands(Inst, N);
1483 }
1484
1485 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1486 addRegListOperands(Inst, N);
1487 }
1488
Jim Grosbach833b9d32011-07-27 20:15:40 +00001489 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1490 assert(N == 1 && "Invalid number of operands!");
1491 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1492 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1493 }
1494
Jim Grosbach864b6092011-07-28 21:34:26 +00001495 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1496 assert(N == 1 && "Invalid number of operands!");
1497 // Munge the lsb/width into a bitfield mask.
1498 unsigned lsb = Bitfield.LSB;
1499 unsigned width = Bitfield.Width;
1500 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1501 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1502 (32 - (lsb + width)));
1503 Inst.addOperand(MCOperand::CreateImm(Mask));
1504 }
1505
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001506 void addImmOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 addExpr(Inst, getImm());
1509 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001510
Jim Grosbachea231912011-12-22 22:19:05 +00001511 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1514 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1515 }
1516
1517 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1518 assert(N == 1 && "Invalid number of operands!");
1519 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1520 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1521 }
1522
Jim Grosbache7fbce72011-10-03 23:38:36 +00001523 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1524 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1526 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1527 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001528 }
1529
Jim Grosbach7db8d692011-09-08 22:07:06 +00001530 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1531 assert(N == 1 && "Invalid number of operands!");
1532 // FIXME: We really want to scale the value here, but the LDRD/STRD
1533 // instruction don't encode operands that way yet.
1534 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1535 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1536 }
1537
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001538 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 // The immediate is scaled by four in the encoding and is stored
1541 // in the MCInst as such. Lop off the low two bits here.
1542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1543 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1544 }
1545
Jim Grosbach930f2f62012-04-05 20:57:13 +00001546 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 1 && "Invalid number of operands!");
1548 // The immediate is scaled by four in the encoding and is stored
1549 // in the MCInst as such. Lop off the low two bits here.
1550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1551 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1552 }
1553
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001554 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1555 assert(N == 1 && "Invalid number of operands!");
1556 // The immediate is scaled by four in the encoding and is stored
1557 // in the MCInst as such. Lop off the low two bits here.
1558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1559 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1560 }
1561
Jim Grosbach475c6db2011-07-25 23:09:14 +00001562 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1563 assert(N == 1 && "Invalid number of operands!");
1564 // The constant encodes as the immediate-1, and we store in the instruction
1565 // the bits as encoded, so subtract off one here.
1566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1567 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1568 }
1569
Jim Grosbach801e0a32011-07-22 23:16:18 +00001570 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
1572 // The constant encodes as the immediate-1, and we store in the instruction
1573 // the bits as encoded, so subtract off one here.
1574 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1575 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1576 }
1577
Jim Grosbach46dd4132011-08-17 21:51:27 +00001578 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1579 assert(N == 1 && "Invalid number of operands!");
1580 // The constant encodes as the immediate, except for 32, which encodes as
1581 // zero.
1582 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1583 unsigned Imm = CE->getValue();
1584 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1585 }
1586
Jim Grosbach27c1e252011-07-21 17:23:04 +00001587 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1588 assert(N == 1 && "Invalid number of operands!");
1589 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1590 // the instruction as well.
1591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1592 int Val = CE->getValue();
1593 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1594 }
1595
Jim Grosbachb009a872011-10-28 22:36:30 +00001596 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1597 assert(N == 1 && "Invalid number of operands!");
1598 // The operand is actually a t2_so_imm, but we have its bitwise
1599 // negation in the assembly source, so twiddle it here.
1600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1601 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1602 }
1603
Jim Grosbach30506252011-12-08 00:31:07 +00001604 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1605 assert(N == 1 && "Invalid number of operands!");
1606 // The operand is actually a t2_so_imm, but we have its
1607 // negation in the assembly source, so twiddle it here.
1608 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1609 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1610 }
1611
Jim Grosbach930f2f62012-04-05 20:57:13 +00001612 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1613 assert(N == 1 && "Invalid number of operands!");
1614 // The operand is actually an imm0_4095, but we have its
1615 // negation in the assembly source, so twiddle it here.
1616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1617 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1618 }
1619
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001620 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1621 assert(N == 1 && "Invalid number of operands!");
1622 // The operand is actually a so_imm, but we have its bitwise
1623 // negation in the assembly source, so twiddle it here.
1624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1625 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1626 }
1627
Jim Grosbach30506252011-12-08 00:31:07 +00001628 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 // The operand is actually a so_imm, but we have its
1631 // negation in the assembly source, so twiddle it here.
1632 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1633 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1634 }
1635
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001636 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1637 assert(N == 1 && "Invalid number of operands!");
1638 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1639 }
1640
Jim Grosbachd3595712011-08-03 23:50:40 +00001641 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1642 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001643 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001644 }
1645
Jim Grosbach94298a92012-01-18 22:46:46 +00001646 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1647 assert(N == 1 && "Invalid number of operands!");
1648 int32_t Imm = Memory.OffsetImm->getValue();
1649 // FIXME: Handle #-0
1650 if (Imm == INT32_MIN) Imm = 0;
1651 Inst.addOperand(MCOperand::CreateImm(Imm));
1652 }
1653
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001654 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1655 assert(N == 1 && "Invalid number of operands!");
1656 assert(isImm() && "Not an immediate!");
1657
1658 // If we have an immediate that's not a constant, treat it as a label
1659 // reference needing a fixup.
1660 if (!isa<MCConstantExpr>(getImm())) {
1661 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1662 return;
1663 }
1664
1665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1666 int Val = CE->getValue();
1667 Inst.addOperand(MCOperand::CreateImm(Val));
1668 }
1669
Jim Grosbacha95ec992011-10-11 17:29:55 +00001670 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1671 assert(N == 2 && "Invalid number of operands!");
1672 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1673 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1674 }
1675
Jim Grosbachd3595712011-08-03 23:50:40 +00001676 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1677 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001678 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1679 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001680 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1681 // Special case for #-0
1682 if (Val == INT32_MIN) Val = 0;
1683 if (Val < 0) Val = -Val;
1684 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1685 } else {
1686 // For register offset, we encode the shift type and negation flag
1687 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001688 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1689 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001690 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001691 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1692 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001693 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001694 }
1695
Jim Grosbachcd17c122011-08-04 23:01:30 +00001696 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1697 assert(N == 2 && "Invalid number of operands!");
1698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1699 assert(CE && "non-constant AM2OffsetImm operand!");
1700 int32_t Val = CE->getValue();
1701 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1702 // Special case for #-0
1703 if (Val == INT32_MIN) Val = 0;
1704 if (Val < 0) Val = -Val;
1705 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1706 Inst.addOperand(MCOperand::CreateReg(0));
1707 Inst.addOperand(MCOperand::CreateImm(Val));
1708 }
1709
Jim Grosbach5b96b802011-08-10 20:29:19 +00001710 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1711 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001712 // If we have an immediate that's not a constant, treat it as a label
1713 // reference needing a fixup. If it is a constant, it's something else
1714 // and we reject it.
1715 if (isImm()) {
1716 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1717 Inst.addOperand(MCOperand::CreateReg(0));
1718 Inst.addOperand(MCOperand::CreateImm(0));
1719 return;
1720 }
1721
Jim Grosbach871dff72011-10-11 15:59:20 +00001722 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1723 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001724 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1725 // Special case for #-0
1726 if (Val == INT32_MIN) Val = 0;
1727 if (Val < 0) Val = -Val;
1728 Val = ARM_AM::getAM3Opc(AddSub, Val);
1729 } else {
1730 // For register offset, we encode the shift type and negation flag
1731 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001732 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001733 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001734 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1735 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001736 Inst.addOperand(MCOperand::CreateImm(Val));
1737 }
1738
1739 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1740 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001741 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001742 int32_t Val =
1743 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1744 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1745 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001746 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001747 }
1748
1749 // Constant offset.
1750 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1751 int32_t Val = CE->getValue();
1752 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1753 // Special case for #-0
1754 if (Val == INT32_MIN) Val = 0;
1755 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001756 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001757 Inst.addOperand(MCOperand::CreateReg(0));
1758 Inst.addOperand(MCOperand::CreateImm(Val));
1759 }
1760
Jim Grosbachd3595712011-08-03 23:50:40 +00001761 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1762 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001763 // If we have an immediate that's not a constant, treat it as a label
1764 // reference needing a fixup. If it is a constant, it's something else
1765 // and we reject it.
1766 if (isImm()) {
1767 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1768 Inst.addOperand(MCOperand::CreateImm(0));
1769 return;
1770 }
1771
Jim Grosbachd3595712011-08-03 23:50:40 +00001772 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001773 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001774 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1775 // Special case for #-0
1776 if (Val == INT32_MIN) Val = 0;
1777 if (Val < 0) Val = -Val;
1778 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001779 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001780 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001781 }
1782
Jim Grosbach7db8d692011-09-08 22:07:06 +00001783 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1784 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001785 // If we have an immediate that's not a constant, treat it as a label
1786 // reference needing a fixup. If it is a constant, it's something else
1787 // and we reject it.
1788 if (isImm()) {
1789 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1790 Inst.addOperand(MCOperand::CreateImm(0));
1791 return;
1792 }
1793
Jim Grosbach871dff72011-10-11 15:59:20 +00001794 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1795 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001796 Inst.addOperand(MCOperand::CreateImm(Val));
1797 }
1798
Jim Grosbacha05627e2011-09-09 18:37:27 +00001799 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 2 && "Invalid number of operands!");
1801 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001802 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001804 Inst.addOperand(MCOperand::CreateImm(Val));
1805 }
1806
Jim Grosbachd3595712011-08-03 23:50:40 +00001807 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1808 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001809 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001811 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001812 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001813
Jim Grosbach2392c532011-09-07 23:39:14 +00001814 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1815 addMemImm8OffsetOperands(Inst, N);
1816 }
1817
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001818 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001819 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001820 }
1821
1822 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1823 assert(N == 2 && "Invalid number of operands!");
1824 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001825 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001826 addExpr(Inst, getImm());
1827 Inst.addOperand(MCOperand::CreateImm(0));
1828 return;
1829 }
1830
1831 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001832 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1833 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001834 Inst.addOperand(MCOperand::CreateImm(Val));
1835 }
1836
Jim Grosbachd3595712011-08-03 23:50:40 +00001837 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1838 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001839 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001840 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001841 addExpr(Inst, getImm());
1842 Inst.addOperand(MCOperand::CreateImm(0));
1843 return;
1844 }
1845
1846 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001847 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1848 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001849 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001850 }
Bill Wendling811c9362010-11-30 07:44:32 +00001851
Jim Grosbach05541f42011-09-19 22:21:13 +00001852 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1853 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001854 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1855 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001856 }
1857
1858 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1859 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001860 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1861 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001862 }
1863
Jim Grosbachd3595712011-08-03 23:50:40 +00001864 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001866 unsigned Val =
1867 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1868 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001869 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1870 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001871 Inst.addOperand(MCOperand::CreateImm(Val));
1872 }
1873
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001874 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1875 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001876 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1877 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1878 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001879 }
1880
Jim Grosbachd3595712011-08-03 23:50:40 +00001881 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1882 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001883 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1884 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001885 }
1886
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001887 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1888 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001889 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001891 Inst.addOperand(MCOperand::CreateImm(Val));
1892 }
1893
Jim Grosbach26d35872011-08-19 18:55:51 +00001894 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001896 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1897 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001898 Inst.addOperand(MCOperand::CreateImm(Val));
1899 }
1900
Jim Grosbacha32c7532011-08-19 18:49:59 +00001901 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001903 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1904 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001905 Inst.addOperand(MCOperand::CreateImm(Val));
1906 }
1907
Jim Grosbach23983d62011-08-19 18:13:48 +00001908 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1909 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001910 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1911 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001912 Inst.addOperand(MCOperand::CreateImm(Val));
1913 }
1914
Jim Grosbachd3595712011-08-03 23:50:40 +00001915 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1916 assert(N == 1 && "Invalid number of operands!");
1917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1918 assert(CE && "non-constant post-idx-imm8 operand!");
1919 int Imm = CE->getValue();
1920 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00001921 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001922 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1923 Inst.addOperand(MCOperand::CreateImm(Imm));
1924 }
1925
Jim Grosbach93981412011-10-11 21:55:36 +00001926 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1927 assert(N == 1 && "Invalid number of operands!");
1928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1929 assert(CE && "non-constant post-idx-imm8s4 operand!");
1930 int Imm = CE->getValue();
1931 bool isAdd = Imm >= 0;
1932 if (Imm == INT32_MIN) Imm = 0;
1933 // Immediate is scaled by 4.
1934 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1935 Inst.addOperand(MCOperand::CreateImm(Imm));
1936 }
1937
Jim Grosbachd3595712011-08-03 23:50:40 +00001938 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 2 && "Invalid number of operands!");
1940 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00001941 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1942 }
1943
1944 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
1946 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1947 // The sign, shift type, and shift amount are encoded in a single operand
1948 // using the AM2 encoding helpers.
1949 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1950 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1951 PostIdxReg.ShiftTy);
1952 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00001953 }
1954
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00001955 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 1 && "Invalid number of operands!");
1957 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1958 }
1959
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00001960 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1961 assert(N == 1 && "Invalid number of operands!");
1962 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1963 }
1964
Jim Grosbach182b6a02011-11-29 23:51:09 +00001965 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001966 assert(N == 1 && "Invalid number of operands!");
1967 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1968 }
1969
Jim Grosbach04945c42011-12-02 00:35:16 +00001970 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1971 assert(N == 2 && "Invalid number of operands!");
1972 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1973 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1974 }
1975
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001976 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1977 assert(N == 1 && "Invalid number of operands!");
1978 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1979 }
1980
1981 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1982 assert(N == 1 && "Invalid number of operands!");
1983 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1984 }
1985
1986 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1987 assert(N == 1 && "Invalid number of operands!");
1988 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1989 }
1990
Jim Grosbach741cd732011-10-17 22:26:03 +00001991 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1992 assert(N == 1 && "Invalid number of operands!");
1993 // The immediate encodes the type of constant as well as the value.
1994 // Mask in that this is an i8 splat.
1995 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1996 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1997 }
1998
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001999 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2000 assert(N == 1 && "Invalid number of operands!");
2001 // The immediate encodes the type of constant as well as the value.
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 unsigned Value = CE->getValue();
2004 if (Value >= 256)
2005 Value = (Value >> 8) | 0xa00;
2006 else
2007 Value |= 0x800;
2008 Inst.addOperand(MCOperand::CreateImm(Value));
2009 }
2010
Jim Grosbach8211c052011-10-18 00:22:00 +00002011 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2012 assert(N == 1 && "Invalid number of operands!");
2013 // The immediate encodes the type of constant as well as the value.
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 unsigned Value = CE->getValue();
2016 if (Value >= 256 && Value <= 0xff00)
2017 Value = (Value >> 8) | 0x200;
2018 else if (Value > 0xffff && Value <= 0xff0000)
2019 Value = (Value >> 16) | 0x400;
2020 else if (Value > 0xffffff)
2021 Value = (Value >> 24) | 0x600;
2022 Inst.addOperand(MCOperand::CreateImm(Value));
2023 }
2024
2025 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2026 assert(N == 1 && "Invalid number of operands!");
2027 // The immediate encodes the type of constant as well as the value.
2028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2029 unsigned Value = CE->getValue();
2030 if (Value >= 256 && Value <= 0xffff)
2031 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2032 else if (Value > 0xffff && Value <= 0xffffff)
2033 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2034 else if (Value > 0xffffff)
2035 Value = (Value >> 24) | 0x600;
2036 Inst.addOperand(MCOperand::CreateImm(Value));
2037 }
2038
Jim Grosbach045b6c72011-12-19 23:51:07 +00002039 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2040 assert(N == 1 && "Invalid number of operands!");
2041 // The immediate encodes the type of constant as well as the value.
2042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2043 unsigned Value = ~CE->getValue();
2044 if (Value >= 256 && Value <= 0xffff)
2045 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2046 else if (Value > 0xffff && Value <= 0xffffff)
2047 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2048 else if (Value > 0xffffff)
2049 Value = (Value >> 24) | 0x600;
2050 Inst.addOperand(MCOperand::CreateImm(Value));
2051 }
2052
Jim Grosbache4454e02011-10-18 16:18:11 +00002053 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2054 assert(N == 1 && "Invalid number of operands!");
2055 // The immediate encodes the type of constant as well as the value.
2056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2057 uint64_t Value = CE->getValue();
2058 unsigned Imm = 0;
2059 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2060 Imm |= (Value & 1) << i;
2061 }
2062 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2063 }
2064
Jim Grosbach602aa902011-07-13 15:34:57 +00002065 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002066
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002067 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002068 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002069 Op->ITMask.Mask = Mask;
2070 Op->StartLoc = S;
2071 Op->EndLoc = S;
2072 return Op;
2073 }
2074
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002075 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002076 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002077 Op->CC.Val = CC;
2078 Op->StartLoc = S;
2079 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002080 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002081 }
2082
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002083 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002084 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002085 Op->Cop.Val = CopVal;
2086 Op->StartLoc = S;
2087 Op->EndLoc = S;
2088 return Op;
2089 }
2090
2091 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002092 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002093 Op->Cop.Val = CopVal;
2094 Op->StartLoc = S;
2095 Op->EndLoc = S;
2096 return Op;
2097 }
2098
Jim Grosbach48399582011-10-12 17:34:41 +00002099 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2100 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2101 Op->Cop.Val = Val;
2102 Op->StartLoc = S;
2103 Op->EndLoc = E;
2104 return Op;
2105 }
2106
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002107 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002108 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002109 Op->Reg.RegNum = RegNum;
2110 Op->StartLoc = S;
2111 Op->EndLoc = S;
2112 return Op;
2113 }
2114
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002115 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002116 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002117 Op->Tok.Data = Str.data();
2118 Op->Tok.Length = Str.size();
2119 Op->StartLoc = S;
2120 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002121 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002122 }
2123
Bill Wendling2063b842010-11-18 23:43:05 +00002124 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002125 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002126 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002127 Op->StartLoc = S;
2128 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002129 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002130 }
2131
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002132 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2133 unsigned SrcReg,
2134 unsigned ShiftReg,
2135 unsigned ShiftImm,
2136 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002137 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002138 Op->RegShiftedReg.ShiftTy = ShTy;
2139 Op->RegShiftedReg.SrcReg = SrcReg;
2140 Op->RegShiftedReg.ShiftReg = ShiftReg;
2141 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002142 Op->StartLoc = S;
2143 Op->EndLoc = E;
2144 return Op;
2145 }
2146
Owen Andersonb595ed02011-07-21 18:54:16 +00002147 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2148 unsigned SrcReg,
2149 unsigned ShiftImm,
2150 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002151 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002152 Op->RegShiftedImm.ShiftTy = ShTy;
2153 Op->RegShiftedImm.SrcReg = SrcReg;
2154 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002155 Op->StartLoc = S;
2156 Op->EndLoc = E;
2157 return Op;
2158 }
2159
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002160 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002161 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002162 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002163 Op->ShifterImm.isASR = isASR;
2164 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002165 Op->StartLoc = S;
2166 Op->EndLoc = E;
2167 return Op;
2168 }
2169
Jim Grosbach833b9d32011-07-27 20:15:40 +00002170 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002171 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002172 Op->RotImm.Imm = Imm;
2173 Op->StartLoc = S;
2174 Op->EndLoc = E;
2175 return Op;
2176 }
2177
Jim Grosbach864b6092011-07-28 21:34:26 +00002178 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2179 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002180 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002181 Op->Bitfield.LSB = LSB;
2182 Op->Bitfield.Width = Width;
2183 Op->StartLoc = S;
2184 Op->EndLoc = E;
2185 return Op;
2186 }
2187
Bill Wendling2cae3272010-11-09 22:44:22 +00002188 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002189 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002190 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002191 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002192
Jim Grosbach75461af2011-09-13 22:56:44 +00002193 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002194 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002195 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002196 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002197 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002198
2199 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002200 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002201 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002202 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002203 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002204 Op->StartLoc = StartLoc;
2205 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002206 return Op;
2207 }
2208
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002209 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002210 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002211 ARMOperand *Op = new ARMOperand(k_VectorList);
2212 Op->VectorList.RegNum = RegNum;
2213 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002214 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002215 Op->StartLoc = S;
2216 Op->EndLoc = E;
2217 return Op;
2218 }
2219
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002220 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002221 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002222 SMLoc S, SMLoc E) {
2223 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2224 Op->VectorList.RegNum = RegNum;
2225 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002226 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002227 Op->StartLoc = S;
2228 Op->EndLoc = E;
2229 return Op;
2230 }
2231
Jim Grosbach04945c42011-12-02 00:35:16 +00002232 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002233 unsigned Index,
2234 bool isDoubleSpaced,
2235 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002236 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2237 Op->VectorList.RegNum = RegNum;
2238 Op->VectorList.Count = Count;
2239 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002240 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002241 Op->StartLoc = S;
2242 Op->EndLoc = E;
2243 return Op;
2244 }
2245
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002246 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2247 MCContext &Ctx) {
2248 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2249 Op->VectorIndex.Val = Idx;
2250 Op->StartLoc = S;
2251 Op->EndLoc = E;
2252 return Op;
2253 }
2254
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002255 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002256 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002257 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002258 Op->StartLoc = S;
2259 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002260 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002261 }
2262
Jim Grosbachd3595712011-08-03 23:50:40 +00002263 static ARMOperand *CreateMem(unsigned BaseRegNum,
2264 const MCConstantExpr *OffsetImm,
2265 unsigned OffsetRegNum,
2266 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002267 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002268 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002269 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002270 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002272 Op->Memory.BaseRegNum = BaseRegNum;
2273 Op->Memory.OffsetImm = OffsetImm;
2274 Op->Memory.OffsetRegNum = OffsetRegNum;
2275 Op->Memory.ShiftType = ShiftType;
2276 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002277 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002278 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002279 Op->StartLoc = S;
2280 Op->EndLoc = E;
2281 return Op;
2282 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002283
Jim Grosbachc320c852011-08-05 21:28:30 +00002284 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2285 ARM_AM::ShiftOpc ShiftTy,
2286 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002287 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002288 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002289 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002290 Op->PostIdxReg.isAdd = isAdd;
2291 Op->PostIdxReg.ShiftTy = ShiftTy;
2292 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002293 Op->StartLoc = S;
2294 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002295 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002296 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002297
2298 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002299 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002300 Op->MBOpt.Val = Opt;
2301 Op->StartLoc = S;
2302 Op->EndLoc = S;
2303 return Op;
2304 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002305
2306 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002307 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002308 Op->IFlags.Val = IFlags;
2309 Op->StartLoc = S;
2310 Op->EndLoc = S;
2311 return Op;
2312 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002313
2314 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002315 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002316 Op->MMask.Val = MMask;
2317 Op->StartLoc = S;
2318 Op->EndLoc = S;
2319 return Op;
2320 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002321};
2322
2323} // end anonymous namespace.
2324
Jim Grosbach602aa902011-07-13 15:34:57 +00002325void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002326 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002327 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002328 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002329 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002330 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002331 OS << "<ccout " << getReg() << ">";
2332 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002333 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002334 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002335 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2336 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2337 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002338 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2339 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2340 break;
2341 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002342 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002343 OS << "<coprocessor number: " << getCoproc() << ">";
2344 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002345 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002346 OS << "<coprocessor register: " << getCoproc() << ">";
2347 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002348 case k_CoprocOption:
2349 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2350 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002351 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002352 OS << "<mask: " << getMSRMask() << ">";
2353 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002354 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002355 getImm()->print(OS);
2356 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002357 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002358 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2359 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002360 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002361 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002362 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002363 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002364 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002365 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002366 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2367 << PostIdxReg.RegNum;
2368 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2369 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2370 << PostIdxReg.ShiftImm;
2371 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002372 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002373 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002374 OS << "<ARM_PROC::";
2375 unsigned IFlags = getProcIFlags();
2376 for (int i=2; i >= 0; --i)
2377 if (IFlags & (1 << i))
2378 OS << ARM_PROC::IFlagsToString(1 << i);
2379 OS << ">";
2380 break;
2381 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002382 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002383 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002384 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002385 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002386 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2387 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002388 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002389 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002390 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002391 << RegShiftedReg.SrcReg << " "
2392 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2393 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002394 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002395 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002396 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002397 << RegShiftedImm.SrcReg << " "
2398 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2399 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002400 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002401 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002402 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2403 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002404 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002405 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2406 << ", width: " << Bitfield.Width << ">";
2407 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002408 case k_RegisterList:
2409 case k_DPRRegisterList:
2410 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002411 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002412
Bill Wendlingbed94652010-11-09 23:28:44 +00002413 const SmallVectorImpl<unsigned> &RegList = getRegList();
2414 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002415 I = RegList.begin(), E = RegList.end(); I != E; ) {
2416 OS << *I;
2417 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002418 }
2419
2420 OS << ">";
2421 break;
2422 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002423 case k_VectorList:
2424 OS << "<vector_list " << VectorList.Count << " * "
2425 << VectorList.RegNum << ">";
2426 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002427 case k_VectorListAllLanes:
2428 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2429 << VectorList.RegNum << ">";
2430 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002431 case k_VectorListIndexed:
2432 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2433 << VectorList.Count << " * " << VectorList.RegNum << ">";
2434 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002435 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002436 OS << "'" << getToken() << "'";
2437 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002438 case k_VectorIndex:
2439 OS << "<vectorindex " << getVectorIndex() << ">";
2440 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002441 }
2442}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002443
2444/// @name Auto-generated Match Functions
2445/// {
2446
2447static unsigned MatchRegisterName(StringRef Name);
2448
2449/// }
2450
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002451bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2452 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002453 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002454 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002455 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002456
2457 return (RegNo == (unsigned)-1);
2458}
2459
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002460/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002461/// and if it is a register name the token is eaten and the register number is
2462/// returned. Otherwise return -1.
2463///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002464int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002465 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002466 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002467
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002468 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002469 unsigned RegNum = MatchRegisterName(lowerCase);
2470 if (!RegNum) {
2471 RegNum = StringSwitch<unsigned>(lowerCase)
2472 .Case("r13", ARM::SP)
2473 .Case("r14", ARM::LR)
2474 .Case("r15", ARM::PC)
2475 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002476 // Additional register name aliases for 'gas' compatibility.
2477 .Case("a1", ARM::R0)
2478 .Case("a2", ARM::R1)
2479 .Case("a3", ARM::R2)
2480 .Case("a4", ARM::R3)
2481 .Case("v1", ARM::R4)
2482 .Case("v2", ARM::R5)
2483 .Case("v3", ARM::R6)
2484 .Case("v4", ARM::R7)
2485 .Case("v5", ARM::R8)
2486 .Case("v6", ARM::R9)
2487 .Case("v7", ARM::R10)
2488 .Case("v8", ARM::R11)
2489 .Case("sb", ARM::R9)
2490 .Case("sl", ARM::R10)
2491 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002492 .Default(0);
2493 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002494 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002495 // Check for aliases registered via .req. Canonicalize to lower case.
2496 // That's more consistent since register names are case insensitive, and
2497 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2498 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002499 // If no match, return failure.
2500 if (Entry == RegisterReqs.end())
2501 return -1;
2502 Parser.Lex(); // Eat identifier token.
2503 return Entry->getValue();
2504 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002505
Chris Lattner44e5981c2010-10-30 04:09:10 +00002506 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002507
Chris Lattner44e5981c2010-10-30 04:09:10 +00002508 return RegNum;
2509}
Jim Grosbach99710a82010-11-01 16:44:21 +00002510
Jim Grosbachbb24c592011-07-13 18:49:30 +00002511// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2512// If a recoverable error occurs, return 1. If an irrecoverable error
2513// occurs, return -1. An irrecoverable error is one where tokens have been
2514// consumed in the process of trying to parse the shifter (i.e., when it is
2515// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002516int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002517 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2518 SMLoc S = Parser.getTok().getLoc();
2519 const AsmToken &Tok = Parser.getTok();
2520 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2521
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002522 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002523 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002524 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002525 .Case("lsl", ARM_AM::lsl)
2526 .Case("lsr", ARM_AM::lsr)
2527 .Case("asr", ARM_AM::asr)
2528 .Case("ror", ARM_AM::ror)
2529 .Case("rrx", ARM_AM::rrx)
2530 .Default(ARM_AM::no_shift);
2531
2532 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002533 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002534
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002535 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002536
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002537 // The source register for the shift has already been added to the
2538 // operand list, so we need to pop it off and combine it into the shifted
2539 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002540 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002541 if (!PrevOp->isReg())
2542 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2543 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002544
2545 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002546 int64_t Imm = 0;
2547 int ShiftReg = 0;
2548 if (ShiftTy == ARM_AM::rrx) {
2549 // RRX Doesn't have an explicit shift amount. The encoder expects
2550 // the shift register to be the same as the source register. Seems odd,
2551 // but OK.
2552 ShiftReg = SrcReg;
2553 } else {
2554 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002555 if (Parser.getTok().is(AsmToken::Hash) ||
2556 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002557 Parser.Lex(); // Eat hash.
2558 SMLoc ImmLoc = Parser.getTok().getLoc();
2559 const MCExpr *ShiftExpr = 0;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002560 if (getParser().ParseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002561 Error(ImmLoc, "invalid immediate shift value");
2562 return -1;
2563 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002564 // The expression must be evaluatable as an immediate.
2565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002566 if (!CE) {
2567 Error(ImmLoc, "invalid immediate shift value");
2568 return -1;
2569 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002570 // Range check the immediate.
2571 // lsl, ror: 0 <= imm <= 31
2572 // lsr, asr: 0 <= imm <= 32
2573 Imm = CE->getValue();
2574 if (Imm < 0 ||
2575 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2576 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002577 Error(ImmLoc, "immediate shift value out of range");
2578 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002579 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002580 // shift by zero is a nop. Always send it through as lsl.
2581 // ('as' compatibility)
2582 if (Imm == 0)
2583 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002584 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002585 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002586 EndLoc = Parser.getTok().getEndLoc();
2587 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002588 if (ShiftReg == -1) {
2589 Error (L, "expected immediate or register in shift operand");
2590 return -1;
2591 }
2592 } else {
2593 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002594 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002595 return -1;
2596 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002597 }
2598
Owen Andersonb595ed02011-07-21 18:54:16 +00002599 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2600 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002601 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002602 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002603 else
2604 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002605 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002606
Jim Grosbachbb24c592011-07-13 18:49:30 +00002607 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002608}
2609
2610
Bill Wendling2063b842010-11-18 23:43:05 +00002611/// Try to parse a register name. The token must be an Identifier when called.
2612/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2613/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002614///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002615/// TODO this is likely to change to allow different register types and or to
2616/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002617bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002618tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002619 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002620 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002621 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002622 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002623
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002624 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2625 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002626
Chris Lattner44e5981c2010-10-30 04:09:10 +00002627 const AsmToken &ExclaimTok = Parser.getTok();
2628 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002629 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2630 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002631 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002632 return false;
2633 }
2634
2635 // Also check for an index operand. This is only legal for vector registers,
2636 // but that'll get caught OK in operand matching, so we don't need to
2637 // explicitly filter everything else out here.
2638 if (Parser.getTok().is(AsmToken::LBrac)) {
2639 SMLoc SIdx = Parser.getTok().getLoc();
2640 Parser.Lex(); // Eat left bracket token.
2641
2642 const MCExpr *ImmVal;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002643 if (getParser().ParseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002644 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002645 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002646 if (!MCE)
2647 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002648
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002649 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002650 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002651
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002652 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002653 Parser.Lex(); // Eat right bracket token.
2654
2655 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2656 SIdx, E,
2657 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002658 }
2659
Bill Wendling2063b842010-11-18 23:43:05 +00002660 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002661}
2662
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002663/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2664/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2665/// "c5", ...
2666static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002667 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2668 // but efficient.
2669 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002670 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002671 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002672 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002673 return -1;
2674 switch (Name[1]) {
2675 default: return -1;
2676 case '0': return 0;
2677 case '1': return 1;
2678 case '2': return 2;
2679 case '3': return 3;
2680 case '4': return 4;
2681 case '5': return 5;
2682 case '6': return 6;
2683 case '7': return 7;
2684 case '8': return 8;
2685 case '9': return 9;
2686 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002687 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002688 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002689 return -1;
2690 switch (Name[2]) {
2691 default: return -1;
2692 case '0': return 10;
2693 case '1': return 11;
2694 case '2': return 12;
2695 case '3': return 13;
2696 case '4': return 14;
2697 case '5': return 15;
2698 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002699 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002700}
2701
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002702/// parseITCondCode - Try to parse a condition code for an IT instruction.
2703ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2704parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2705 SMLoc S = Parser.getTok().getLoc();
2706 const AsmToken &Tok = Parser.getTok();
2707 if (!Tok.is(AsmToken::Identifier))
2708 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002709 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002710 .Case("eq", ARMCC::EQ)
2711 .Case("ne", ARMCC::NE)
2712 .Case("hs", ARMCC::HS)
2713 .Case("cs", ARMCC::HS)
2714 .Case("lo", ARMCC::LO)
2715 .Case("cc", ARMCC::LO)
2716 .Case("mi", ARMCC::MI)
2717 .Case("pl", ARMCC::PL)
2718 .Case("vs", ARMCC::VS)
2719 .Case("vc", ARMCC::VC)
2720 .Case("hi", ARMCC::HI)
2721 .Case("ls", ARMCC::LS)
2722 .Case("ge", ARMCC::GE)
2723 .Case("lt", ARMCC::LT)
2724 .Case("gt", ARMCC::GT)
2725 .Case("le", ARMCC::LE)
2726 .Case("al", ARMCC::AL)
2727 .Default(~0U);
2728 if (CC == ~0U)
2729 return MatchOperand_NoMatch;
2730 Parser.Lex(); // Eat the token.
2731
2732 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2733
2734 return MatchOperand_Success;
2735}
2736
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002737/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002738/// token must be an Identifier when called, and if it is a coprocessor
2739/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002740ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002741parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002742 SMLoc S = Parser.getTok().getLoc();
2743 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002744 if (Tok.isNot(AsmToken::Identifier))
2745 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002746
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002747 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002748 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002749 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002750
2751 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002752 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002753 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002754}
2755
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002756/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002757/// token must be an Identifier when called, and if it is a coprocessor
2758/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002759ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002760parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002761 SMLoc S = Parser.getTok().getLoc();
2762 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002763 if (Tok.isNot(AsmToken::Identifier))
2764 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002765
2766 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2767 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002768 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002769
2770 Parser.Lex(); // Eat identifier token.
2771 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002772 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002773}
2774
Jim Grosbach48399582011-10-12 17:34:41 +00002775/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2776/// coproc_option : '{' imm0_255 '}'
2777ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2778parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2779 SMLoc S = Parser.getTok().getLoc();
2780
2781 // If this isn't a '{', this isn't a coprocessor immediate operand.
2782 if (Parser.getTok().isNot(AsmToken::LCurly))
2783 return MatchOperand_NoMatch;
2784 Parser.Lex(); // Eat the '{'
2785
2786 const MCExpr *Expr;
2787 SMLoc Loc = Parser.getTok().getLoc();
2788 if (getParser().ParseExpression(Expr)) {
2789 Error(Loc, "illegal expression");
2790 return MatchOperand_ParseFail;
2791 }
2792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2793 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2794 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2795 return MatchOperand_ParseFail;
2796 }
2797 int Val = CE->getValue();
2798
2799 // Check for and consume the closing '}'
2800 if (Parser.getTok().isNot(AsmToken::RCurly))
2801 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002802 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002803 Parser.Lex(); // Eat the '}'
2804
2805 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2806 return MatchOperand_Success;
2807}
2808
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002809// For register list parsing, we need to map from raw GPR register numbering
2810// to the enumeration values. The enumeration values aren't sorted by
2811// register number due to our using "sp", "lr" and "pc" as canonical names.
2812static unsigned getNextRegister(unsigned Reg) {
2813 // If this is a GPR, we need to do it manually, otherwise we can rely
2814 // on the sort ordering of the enumeration since the other reg-classes
2815 // are sane.
2816 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2817 return Reg + 1;
2818 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002819 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002820 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2821 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2822 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2823 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2824 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2825 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2826 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2827 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2828 }
2829}
2830
Jim Grosbach85a23432011-11-11 21:27:40 +00002831// Return the low-subreg of a given Q register.
2832static unsigned getDRegFromQReg(unsigned QReg) {
2833 switch (QReg) {
2834 default: llvm_unreachable("expected a Q register!");
2835 case ARM::Q0: return ARM::D0;
2836 case ARM::Q1: return ARM::D2;
2837 case ARM::Q2: return ARM::D4;
2838 case ARM::Q3: return ARM::D6;
2839 case ARM::Q4: return ARM::D8;
2840 case ARM::Q5: return ARM::D10;
2841 case ARM::Q6: return ARM::D12;
2842 case ARM::Q7: return ARM::D14;
2843 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002844 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002845 case ARM::Q10: return ARM::D20;
2846 case ARM::Q11: return ARM::D22;
2847 case ARM::Q12: return ARM::D24;
2848 case ARM::Q13: return ARM::D26;
2849 case ARM::Q14: return ARM::D28;
2850 case ARM::Q15: return ARM::D30;
2851 }
2852}
2853
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002854/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002855bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002856parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002857 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002858 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002859 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002860 Parser.Lex(); // Eat '{' token.
2861 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002862
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002863 // Check the first register in the list to see what register class
2864 // this is a list of.
2865 int Reg = tryParseRegister();
2866 if (Reg == -1)
2867 return Error(RegLoc, "register expected");
2868
Jim Grosbach85a23432011-11-11 21:27:40 +00002869 // The reglist instructions have at most 16 registers, so reserve
2870 // space for that many.
2871 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2872
2873 // Allow Q regs and just interpret them as the two D sub-registers.
2874 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2875 Reg = getDRegFromQReg(Reg);
2876 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2877 ++Reg;
2878 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002879 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002880 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2881 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2882 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2883 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2884 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2885 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2886 else
2887 return Error(RegLoc, "invalid register in register list");
2888
Jim Grosbach85a23432011-11-11 21:27:40 +00002889 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002890 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002891
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002892 // This starts immediately after the first register token in the list,
2893 // so we can see either a comma or a minus (range separator) as a legal
2894 // next token.
2895 while (Parser.getTok().is(AsmToken::Comma) ||
2896 Parser.getTok().is(AsmToken::Minus)) {
2897 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00002898 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002899 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002900 int EndReg = tryParseRegister();
2901 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002902 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002903 // Allow Q regs and just interpret them as the two D sub-registers.
2904 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2905 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002906 // If the register is the same as the start reg, there's nothing
2907 // more to do.
2908 if (Reg == EndReg)
2909 continue;
2910 // The register must be in the same register class as the first.
2911 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002912 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002913 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002914 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002915 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00002916
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002917 // Add all the registers in the range to the register list.
2918 while (Reg != EndReg) {
2919 Reg = getNextRegister(Reg);
2920 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2921 }
2922 continue;
2923 }
2924 Parser.Lex(); // Eat the comma.
2925 RegLoc = Parser.getTok().getLoc();
2926 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00002927 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002928 Reg = tryParseRegister();
2929 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00002930 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002931 // Allow Q regs and just interpret them as the two D sub-registers.
2932 bool isQReg = false;
2933 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2934 Reg = getDRegFromQReg(Reg);
2935 isQReg = true;
2936 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002937 // The register must be in the same register class as the first.
2938 if (!RC->contains(Reg))
2939 return Error(RegLoc, "invalid register in register list");
2940 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002941 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00002942 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2943 Warning(RegLoc, "register list not in ascending order");
2944 else
2945 return Error(RegLoc, "register list not in ascending order");
2946 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00002947 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00002948 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2949 ") in register list");
2950 continue;
2951 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002952 // VFP register lists must also be contiguous.
2953 // It's OK to use the enumeration values directly here rather, as the
2954 // VFP register classes have the enum sorted properly.
2955 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2956 Reg != OldReg + 1)
2957 return Error(RegLoc, "non-contiguous register range");
2958 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00002959 if (isQReg)
2960 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00002961 }
2962
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002963 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002964 return Error(Parser.getTok().getLoc(), "'}' expected");
2965 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002966 Parser.Lex(); // Eat '}' token.
2967
Jim Grosbach18bf3632011-12-13 21:48:29 +00002968 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00002969 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00002970
2971 // The ARM system instruction variants for LDM/STM have a '^' token here.
2972 if (Parser.getTok().is(AsmToken::Caret)) {
2973 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2974 Parser.Lex(); // Eat '^' token.
2975 }
2976
Bill Wendling2063b842010-11-18 23:43:05 +00002977 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00002978}
2979
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002980// Helper function to parse the lane index for vector lists.
2981ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002982parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002983 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002984 if (Parser.getTok().is(AsmToken::LBrac)) {
2985 Parser.Lex(); // Eat the '['.
2986 if (Parser.getTok().is(AsmToken::RBrac)) {
2987 // "Dn[]" is the 'all lanes' syntax.
2988 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002989 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002990 Parser.Lex(); // Eat the ']'.
2991 return MatchOperand_Success;
2992 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00002993
2994 // There's an optional '#' token here. Normally there wouldn't be, but
2995 // inline assemble puts one in, and it's friendly to accept that.
2996 if (Parser.getTok().is(AsmToken::Hash))
2997 Parser.Lex(); // Eat the '#'
2998
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002999 const MCExpr *LaneIndex;
3000 SMLoc Loc = Parser.getTok().getLoc();
3001 if (getParser().ParseExpression(LaneIndex)) {
3002 Error(Loc, "illegal expression");
3003 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003004 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3006 if (!CE) {
3007 Error(Loc, "lane index must be empty or an integer");
3008 return MatchOperand_ParseFail;
3009 }
3010 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3011 Error(Parser.getTok().getLoc(), "']' expected");
3012 return MatchOperand_ParseFail;
3013 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003014 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003015 Parser.Lex(); // Eat the ']'.
3016 int64_t Val = CE->getValue();
3017
3018 // FIXME: Make this range check context sensitive for .8, .16, .32.
3019 if (Val < 0 || Val > 7) {
3020 Error(Parser.getTok().getLoc(), "lane index out of range");
3021 return MatchOperand_ParseFail;
3022 }
3023 Index = Val;
3024 LaneKind = IndexedLane;
3025 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003026 }
3027 LaneKind = NoLanes;
3028 return MatchOperand_Success;
3029}
3030
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003031// parse a vector register list
3032ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3033parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003034 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003035 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003036 SMLoc S = Parser.getTok().getLoc();
3037 // As an extension (to match gas), support a plain D register or Q register
3038 // (without encosing curly braces) as a single or double entry list,
3039 // respectively.
3040 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003041 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003042 int Reg = tryParseRegister();
3043 if (Reg == -1)
3044 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003045 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003046 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003047 if (Res != MatchOperand_Success)
3048 return Res;
3049 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003050 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003051 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003052 break;
3053 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003054 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3055 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003056 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003057 case IndexedLane:
3058 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003059 LaneIndex,
3060 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003061 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003062 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003063 return MatchOperand_Success;
3064 }
3065 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3066 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003067 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003068 if (Res != MatchOperand_Success)
3069 return Res;
3070 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003071 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003072 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003073 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003074 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003075 break;
3076 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003077 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3078 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003079 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3080 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003081 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003082 case IndexedLane:
3083 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003084 LaneIndex,
3085 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003086 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003087 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003088 return MatchOperand_Success;
3089 }
3090 Error(S, "vector register expected");
3091 return MatchOperand_ParseFail;
3092 }
3093
3094 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003095 return MatchOperand_NoMatch;
3096
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003097 Parser.Lex(); // Eat '{' token.
3098 SMLoc RegLoc = Parser.getTok().getLoc();
3099
3100 int Reg = tryParseRegister();
3101 if (Reg == -1) {
3102 Error(RegLoc, "register expected");
3103 return MatchOperand_ParseFail;
3104 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003105 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003106 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003107 unsigned FirstReg = Reg;
3108 // The list is of D registers, but we also allow Q regs and just interpret
3109 // them as the two D sub-registers.
3110 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3111 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003112 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3113 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003114 ++Reg;
3115 ++Count;
3116 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003117
3118 SMLoc E;
3119 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003120 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003121
Jim Grosbache891fe82011-11-15 23:19:15 +00003122 while (Parser.getTok().is(AsmToken::Comma) ||
3123 Parser.getTok().is(AsmToken::Minus)) {
3124 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003125 if (!Spacing)
3126 Spacing = 1; // Register range implies a single spaced list.
3127 else if (Spacing == 2) {
3128 Error(Parser.getTok().getLoc(),
3129 "sequential registers in double spaced list");
3130 return MatchOperand_ParseFail;
3131 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003132 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003133 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003134 int EndReg = tryParseRegister();
3135 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003136 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003137 return MatchOperand_ParseFail;
3138 }
3139 // Allow Q regs and just interpret them as the two D sub-registers.
3140 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3141 EndReg = getDRegFromQReg(EndReg) + 1;
3142 // If the register is the same as the start reg, there's nothing
3143 // more to do.
3144 if (Reg == EndReg)
3145 continue;
3146 // The register must be in the same register class as the first.
3147 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003148 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003149 return MatchOperand_ParseFail;
3150 }
3151 // Ranges must go from low to high.
3152 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003153 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003154 return MatchOperand_ParseFail;
3155 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156 // Parse the lane specifier if present.
3157 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003158 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003159 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3160 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003161 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003162 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003163 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003164 return MatchOperand_ParseFail;
3165 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003166
3167 // Add all the registers in the range to the register list.
3168 Count += EndReg - Reg;
3169 Reg = EndReg;
3170 continue;
3171 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003172 Parser.Lex(); // Eat the comma.
3173 RegLoc = Parser.getTok().getLoc();
3174 int OldReg = Reg;
3175 Reg = tryParseRegister();
3176 if (Reg == -1) {
3177 Error(RegLoc, "register expected");
3178 return MatchOperand_ParseFail;
3179 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003180 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003181 // It's OK to use the enumeration values directly here rather, as the
3182 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003183 //
3184 // The list is of D registers, but we also allow Q regs and just interpret
3185 // them as the two D sub-registers.
3186 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003187 if (!Spacing)
3188 Spacing = 1; // Register range implies a single spaced list.
3189 else if (Spacing == 2) {
3190 Error(RegLoc,
3191 "invalid register in double-spaced list (must be 'D' register')");
3192 return MatchOperand_ParseFail;
3193 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003194 Reg = getDRegFromQReg(Reg);
3195 if (Reg != OldReg + 1) {
3196 Error(RegLoc, "non-contiguous register range");
3197 return MatchOperand_ParseFail;
3198 }
3199 ++Reg;
3200 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003201 // Parse the lane specifier if present.
3202 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003203 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003204 SMLoc LaneLoc = Parser.getTok().getLoc();
3205 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3206 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003207 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003208 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003209 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003210 return MatchOperand_ParseFail;
3211 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003212 continue;
3213 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003214 // Normal D register.
3215 // Figure out the register spacing (single or double) of the list if
3216 // we don't know it already.
3217 if (!Spacing)
3218 Spacing = 1 + (Reg == OldReg + 2);
3219
3220 // Just check that it's contiguous and keep going.
3221 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003222 Error(RegLoc, "non-contiguous register range");
3223 return MatchOperand_ParseFail;
3224 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003225 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 // Parse the lane specifier if present.
3227 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003228 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003229 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003230 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003231 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003232 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003233 Error(EndLoc, "mismatched lane index in register list");
3234 return MatchOperand_ParseFail;
3235 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003236 }
3237
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003238 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003239 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003240 return MatchOperand_ParseFail;
3241 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003242 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003243 Parser.Lex(); // Eat '}' token.
3244
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003245 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003246 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003247 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003248 // composite register classes.
3249 if (Count == 2) {
3250 const MCRegisterClass *RC = (Spacing == 1) ?
3251 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3252 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3253 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3254 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003255
Jim Grosbach2f50e922011-12-15 21:44:33 +00003256 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3257 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003258 break;
3259 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003260 // Two-register operands have been converted to the
3261 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003262 if (Count == 2) {
3263 const MCRegisterClass *RC = (Spacing == 1) ?
3264 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3265 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003266 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3267 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003268 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003269 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003270 S, E));
3271 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003272 case IndexedLane:
3273 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003274 LaneIndex,
3275 (Spacing == 2),
3276 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003277 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003278 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003279 return MatchOperand_Success;
3280}
3281
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003282/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003283ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003284parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003285 SMLoc S = Parser.getTok().getLoc();
3286 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003287 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003288
Jiangning Liu288e1af2012-08-02 08:21:27 +00003289 if (Tok.is(AsmToken::Identifier)) {
3290 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003291
Jiangning Liu288e1af2012-08-02 08:21:27 +00003292 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3293 .Case("sy", ARM_MB::SY)
3294 .Case("st", ARM_MB::ST)
3295 .Case("sh", ARM_MB::ISH)
3296 .Case("ish", ARM_MB::ISH)
3297 .Case("shst", ARM_MB::ISHST)
3298 .Case("ishst", ARM_MB::ISHST)
3299 .Case("nsh", ARM_MB::NSH)
3300 .Case("un", ARM_MB::NSH)
3301 .Case("nshst", ARM_MB::NSHST)
3302 .Case("unst", ARM_MB::NSHST)
3303 .Case("osh", ARM_MB::OSH)
3304 .Case("oshst", ARM_MB::OSHST)
3305 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003306
Jiangning Liu288e1af2012-08-02 08:21:27 +00003307 if (Opt == ~0U)
3308 return MatchOperand_NoMatch;
3309
3310 Parser.Lex(); // Eat identifier token.
3311 } else if (Tok.is(AsmToken::Hash) ||
3312 Tok.is(AsmToken::Dollar) ||
3313 Tok.is(AsmToken::Integer)) {
3314 if (Parser.getTok().isNot(AsmToken::Integer))
3315 Parser.Lex(); // Eat the '#'.
3316 SMLoc Loc = Parser.getTok().getLoc();
3317
3318 const MCExpr *MemBarrierID;
3319 if (getParser().ParseExpression(MemBarrierID)) {
3320 Error(Loc, "illegal expression");
3321 return MatchOperand_ParseFail;
3322 }
3323
3324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3325 if (!CE) {
3326 Error(Loc, "constant expression expected");
3327 return MatchOperand_ParseFail;
3328 }
3329
3330 int Val = CE->getValue();
3331 if (Val & ~0xf) {
3332 Error(Loc, "immediate value out of range");
3333 return MatchOperand_ParseFail;
3334 }
3335
3336 Opt = ARM_MB::RESERVED_0 + Val;
3337 } else
3338 return MatchOperand_ParseFail;
3339
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003340 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003341 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003342}
3343
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003344/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003345ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003346parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003347 SMLoc S = Parser.getTok().getLoc();
3348 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003349 if (!Tok.is(AsmToken::Identifier))
3350 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003351 StringRef IFlagsStr = Tok.getString();
3352
Owen Anderson10c5b122011-10-05 17:16:40 +00003353 // An iflags string of "none" is interpreted to mean that none of the AIF
3354 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003355 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003356 if (IFlagsStr != "none") {
3357 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3358 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3359 .Case("a", ARM_PROC::A)
3360 .Case("i", ARM_PROC::I)
3361 .Case("f", ARM_PROC::F)
3362 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003363
Owen Anderson10c5b122011-10-05 17:16:40 +00003364 // If some specific iflag is already set, it means that some letter is
3365 // present more than once, this is not acceptable.
3366 if (Flag == ~0U || (IFlags & Flag))
3367 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003368
Owen Anderson10c5b122011-10-05 17:16:40 +00003369 IFlags |= Flag;
3370 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003371 }
3372
3373 Parser.Lex(); // Eat identifier token.
3374 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3375 return MatchOperand_Success;
3376}
3377
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003378/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003379ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003380parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003381 SMLoc S = Parser.getTok().getLoc();
3382 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003383 if (!Tok.is(AsmToken::Identifier))
3384 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003385 StringRef Mask = Tok.getString();
3386
James Molloy21efa7d2011-09-28 14:21:38 +00003387 if (isMClass()) {
3388 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003389 std::string Name = Mask.lower();
3390 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003391 // Note: in the documentation:
3392 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3393 // for MSR APSR_nzcvq.
3394 // but we do make it an alias here. This is so to get the "mask encoding"
3395 // bits correct on MSR APSR writes.
3396 //
3397 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3398 // should really only be allowed when writing a special register. Note
3399 // they get dropped in the MRS instruction reading a special register as
3400 // the SYSm field is only 8 bits.
3401 //
3402 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3403 // includes the DSP extension but that is not checked.
3404 .Case("apsr", 0x800)
3405 .Case("apsr_nzcvq", 0x800)
3406 .Case("apsr_g", 0x400)
3407 .Case("apsr_nzcvqg", 0xc00)
3408 .Case("iapsr", 0x801)
3409 .Case("iapsr_nzcvq", 0x801)
3410 .Case("iapsr_g", 0x401)
3411 .Case("iapsr_nzcvqg", 0xc01)
3412 .Case("eapsr", 0x802)
3413 .Case("eapsr_nzcvq", 0x802)
3414 .Case("eapsr_g", 0x402)
3415 .Case("eapsr_nzcvqg", 0xc02)
3416 .Case("xpsr", 0x803)
3417 .Case("xpsr_nzcvq", 0x803)
3418 .Case("xpsr_g", 0x403)
3419 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003420 .Case("ipsr", 0x805)
3421 .Case("epsr", 0x806)
3422 .Case("iepsr", 0x807)
3423 .Case("msp", 0x808)
3424 .Case("psp", 0x809)
3425 .Case("primask", 0x810)
3426 .Case("basepri", 0x811)
3427 .Case("basepri_max", 0x812)
3428 .Case("faultmask", 0x813)
3429 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003430 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003431
James Molloy21efa7d2011-09-28 14:21:38 +00003432 if (FlagsVal == ~0U)
3433 return MatchOperand_NoMatch;
3434
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003435 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003436 // basepri, basepri_max and faultmask only valid for V7m.
3437 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003438
James Molloy21efa7d2011-09-28 14:21:38 +00003439 Parser.Lex(); // Eat identifier token.
3440 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3441 return MatchOperand_Success;
3442 }
3443
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003444 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3445 size_t Start = 0, Next = Mask.find('_');
3446 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003447 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003448 if (Next != StringRef::npos)
3449 Flags = Mask.slice(Next+1, Mask.size());
3450
3451 // FlagsVal contains the complete mask:
3452 // 3-0: Mask
3453 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3454 unsigned FlagsVal = 0;
3455
3456 if (SpecReg == "apsr") {
3457 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003458 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003459 .Case("g", 0x4) // same as CPSR_s
3460 .Case("nzcvqg", 0xc) // same as CPSR_fs
3461 .Default(~0U);
3462
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003463 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003464 if (!Flags.empty())
3465 return MatchOperand_NoMatch;
3466 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003467 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003468 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003469 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003470 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3471 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003472 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003473 for (int i = 0, e = Flags.size(); i != e; ++i) {
3474 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3475 .Case("c", 1)
3476 .Case("x", 2)
3477 .Case("s", 4)
3478 .Case("f", 8)
3479 .Default(~0U);
3480
3481 // If some specific flag is already set, it means that some letter is
3482 // present more than once, this is not acceptable.
3483 if (FlagsVal == ~0U || (FlagsVal & Flag))
3484 return MatchOperand_NoMatch;
3485 FlagsVal |= Flag;
3486 }
3487 } else // No match for special register.
3488 return MatchOperand_NoMatch;
3489
Owen Anderson03a173e2011-10-21 18:43:28 +00003490 // Special register without flags is NOT equivalent to "fc" flags.
3491 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3492 // two lines would enable gas compatibility at the expense of breaking
3493 // round-tripping.
3494 //
3495 // if (!FlagsVal)
3496 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003497
3498 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3499 if (SpecReg == "spsr")
3500 FlagsVal |= 16;
3501
3502 Parser.Lex(); // Eat identifier token.
3503 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3504 return MatchOperand_Success;
3505}
3506
Jim Grosbach27c1e252011-07-21 17:23:04 +00003507ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3508parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3509 int Low, int High) {
3510 const AsmToken &Tok = Parser.getTok();
3511 if (Tok.isNot(AsmToken::Identifier)) {
3512 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3513 return MatchOperand_ParseFail;
3514 }
3515 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003516 std::string LowerOp = Op.lower();
3517 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003518 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3519 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3520 return MatchOperand_ParseFail;
3521 }
3522 Parser.Lex(); // Eat shift type token.
3523
3524 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003525 if (Parser.getTok().isNot(AsmToken::Hash) &&
3526 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003527 Error(Parser.getTok().getLoc(), "'#' expected");
3528 return MatchOperand_ParseFail;
3529 }
3530 Parser.Lex(); // Eat hash token.
3531
3532 const MCExpr *ShiftAmount;
3533 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003534 SMLoc EndLoc;
3535 if (getParser().ParseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003536 Error(Loc, "illegal expression");
3537 return MatchOperand_ParseFail;
3538 }
3539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3540 if (!CE) {
3541 Error(Loc, "constant expression expected");
3542 return MatchOperand_ParseFail;
3543 }
3544 int Val = CE->getValue();
3545 if (Val < Low || Val > High) {
3546 Error(Loc, "immediate value out of range");
3547 return MatchOperand_ParseFail;
3548 }
3549
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003550 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003551
3552 return MatchOperand_Success;
3553}
3554
Jim Grosbach0a547702011-07-22 17:44:50 +00003555ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3556parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3557 const AsmToken &Tok = Parser.getTok();
3558 SMLoc S = Tok.getLoc();
3559 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003560 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003561 return MatchOperand_ParseFail;
3562 }
3563 int Val = StringSwitch<int>(Tok.getString())
3564 .Case("be", 1)
3565 .Case("le", 0)
3566 .Default(-1);
3567 Parser.Lex(); // Eat the token.
3568
3569 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003570 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003571 return MatchOperand_ParseFail;
3572 }
3573 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3574 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003575 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003576 return MatchOperand_Success;
3577}
3578
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003579/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3580/// instructions. Legal values are:
3581/// lsl #n 'n' in [0,31]
3582/// asr #n 'n' in [1,32]
3583/// n == 32 encoded as n == 0.
3584ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3585parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3586 const AsmToken &Tok = Parser.getTok();
3587 SMLoc S = Tok.getLoc();
3588 if (Tok.isNot(AsmToken::Identifier)) {
3589 Error(S, "shift operator 'asr' or 'lsl' expected");
3590 return MatchOperand_ParseFail;
3591 }
3592 StringRef ShiftName = Tok.getString();
3593 bool isASR;
3594 if (ShiftName == "lsl" || ShiftName == "LSL")
3595 isASR = false;
3596 else if (ShiftName == "asr" || ShiftName == "ASR")
3597 isASR = true;
3598 else {
3599 Error(S, "shift operator 'asr' or 'lsl' expected");
3600 return MatchOperand_ParseFail;
3601 }
3602 Parser.Lex(); // Eat the operator.
3603
3604 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003605 if (Parser.getTok().isNot(AsmToken::Hash) &&
3606 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003607 Error(Parser.getTok().getLoc(), "'#' expected");
3608 return MatchOperand_ParseFail;
3609 }
3610 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003611 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003612
3613 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003614 SMLoc EndLoc;
3615 if (getParser().ParseExpression(ShiftAmount, EndLoc)) {
3616 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003617 return MatchOperand_ParseFail;
3618 }
3619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3620 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003621 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003622 return MatchOperand_ParseFail;
3623 }
3624
3625 int64_t Val = CE->getValue();
3626 if (isASR) {
3627 // Shift amount must be in [1,32]
3628 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003629 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003630 return MatchOperand_ParseFail;
3631 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003632 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3633 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003634 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003635 return MatchOperand_ParseFail;
3636 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003637 if (Val == 32) Val = 0;
3638 } else {
3639 // Shift amount must be in [1,32]
3640 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003641 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003642 return MatchOperand_ParseFail;
3643 }
3644 }
3645
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003646 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003647
3648 return MatchOperand_Success;
3649}
3650
Jim Grosbach833b9d32011-07-27 20:15:40 +00003651/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3652/// of instructions. Legal values are:
3653/// ror #n 'n' in {0, 8, 16, 24}
3654ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3655parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3656 const AsmToken &Tok = Parser.getTok();
3657 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003658 if (Tok.isNot(AsmToken::Identifier))
3659 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003660 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003661 if (ShiftName != "ror" && ShiftName != "ROR")
3662 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003663 Parser.Lex(); // Eat the operator.
3664
3665 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003666 if (Parser.getTok().isNot(AsmToken::Hash) &&
3667 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003668 Error(Parser.getTok().getLoc(), "'#' expected");
3669 return MatchOperand_ParseFail;
3670 }
3671 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003672 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003673
3674 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003675 SMLoc EndLoc;
3676 if (getParser().ParseExpression(ShiftAmount, EndLoc)) {
3677 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003678 return MatchOperand_ParseFail;
3679 }
3680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3681 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003682 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003683 return MatchOperand_ParseFail;
3684 }
3685
3686 int64_t Val = CE->getValue();
3687 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3688 // normally, zero is represented in asm by omitting the rotate operand
3689 // entirely.
3690 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003691 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003692 return MatchOperand_ParseFail;
3693 }
3694
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003695 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003696
3697 return MatchOperand_Success;
3698}
3699
Jim Grosbach864b6092011-07-28 21:34:26 +00003700ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3701parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3702 SMLoc S = Parser.getTok().getLoc();
3703 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003704 if (Parser.getTok().isNot(AsmToken::Hash) &&
3705 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003706 Error(Parser.getTok().getLoc(), "'#' expected");
3707 return MatchOperand_ParseFail;
3708 }
3709 Parser.Lex(); // Eat hash token.
3710
3711 const MCExpr *LSBExpr;
3712 SMLoc E = Parser.getTok().getLoc();
3713 if (getParser().ParseExpression(LSBExpr)) {
3714 Error(E, "malformed immediate expression");
3715 return MatchOperand_ParseFail;
3716 }
3717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3718 if (!CE) {
3719 Error(E, "'lsb' operand must be an immediate");
3720 return MatchOperand_ParseFail;
3721 }
3722
3723 int64_t LSB = CE->getValue();
3724 // The LSB must be in the range [0,31]
3725 if (LSB < 0 || LSB > 31) {
3726 Error(E, "'lsb' operand must be in the range [0,31]");
3727 return MatchOperand_ParseFail;
3728 }
3729 E = Parser.getTok().getLoc();
3730
3731 // Expect another immediate operand.
3732 if (Parser.getTok().isNot(AsmToken::Comma)) {
3733 Error(Parser.getTok().getLoc(), "too few operands");
3734 return MatchOperand_ParseFail;
3735 }
3736 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003737 if (Parser.getTok().isNot(AsmToken::Hash) &&
3738 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003739 Error(Parser.getTok().getLoc(), "'#' expected");
3740 return MatchOperand_ParseFail;
3741 }
3742 Parser.Lex(); // Eat hash token.
3743
3744 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003745 SMLoc EndLoc;
3746 if (getParser().ParseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003747 Error(E, "malformed immediate expression");
3748 return MatchOperand_ParseFail;
3749 }
3750 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3751 if (!CE) {
3752 Error(E, "'width' operand must be an immediate");
3753 return MatchOperand_ParseFail;
3754 }
3755
3756 int64_t Width = CE->getValue();
3757 // The LSB must be in the range [1,32-lsb]
3758 if (Width < 1 || Width > 32 - LSB) {
3759 Error(E, "'width' operand must be in the range [1,32-lsb]");
3760 return MatchOperand_ParseFail;
3761 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003762
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003763 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003764
3765 return MatchOperand_Success;
3766}
3767
Jim Grosbachd3595712011-08-03 23:50:40 +00003768ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3769parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3770 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003771 // postidx_reg := '+' register {, shift}
3772 // | '-' register {, shift}
3773 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003774
3775 // This method must return MatchOperand_NoMatch without consuming any tokens
3776 // in the case where there is no match, as other alternatives take other
3777 // parse methods.
3778 AsmToken Tok = Parser.getTok();
3779 SMLoc S = Tok.getLoc();
3780 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003781 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003782 if (Tok.is(AsmToken::Plus)) {
3783 Parser.Lex(); // Eat the '+' token.
3784 haveEaten = true;
3785 } else if (Tok.is(AsmToken::Minus)) {
3786 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003787 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003788 haveEaten = true;
3789 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003790
3791 SMLoc E = Parser.getTok().getEndLoc();
3792 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003793 if (Reg == -1) {
3794 if (!haveEaten)
3795 return MatchOperand_NoMatch;
3796 Error(Parser.getTok().getLoc(), "register expected");
3797 return MatchOperand_ParseFail;
3798 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003799
Jim Grosbachc320c852011-08-05 21:28:30 +00003800 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3801 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003802 if (Parser.getTok().is(AsmToken::Comma)) {
3803 Parser.Lex(); // Eat the ','.
3804 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3805 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003806
3807 // FIXME: Only approximates end...may include intervening whitespace.
3808 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003809 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003810
3811 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3812 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003813
3814 return MatchOperand_Success;
3815}
3816
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003817ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3818parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3819 // Check for a post-index addressing register operand. Specifically:
3820 // am3offset := '+' register
3821 // | '-' register
3822 // | register
3823 // | # imm
3824 // | # + imm
3825 // | # - imm
3826
3827 // This method must return MatchOperand_NoMatch without consuming any tokens
3828 // in the case where there is no match, as other alternatives take other
3829 // parse methods.
3830 AsmToken Tok = Parser.getTok();
3831 SMLoc S = Tok.getLoc();
3832
3833 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003834 if (Parser.getTok().is(AsmToken::Hash) ||
3835 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003836 Parser.Lex(); // Eat the '#'.
3837 // Explicitly look for a '-', as we need to encode negative zero
3838 // differently.
3839 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3840 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003841 SMLoc E;
3842 if (getParser().ParseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003843 return MatchOperand_ParseFail;
3844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3845 if (!CE) {
3846 Error(S, "constant expression expected");
3847 return MatchOperand_ParseFail;
3848 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003849 // Negative zero is encoded as the flag value INT32_MIN.
3850 int32_t Val = CE->getValue();
3851 if (isNegative && Val == 0)
3852 Val = INT32_MIN;
3853
3854 Operands.push_back(
3855 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3856
3857 return MatchOperand_Success;
3858 }
3859
3860
3861 bool haveEaten = false;
3862 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003863 if (Tok.is(AsmToken::Plus)) {
3864 Parser.Lex(); // Eat the '+' token.
3865 haveEaten = true;
3866 } else if (Tok.is(AsmToken::Minus)) {
3867 Parser.Lex(); // Eat the '-' token.
3868 isAdd = false;
3869 haveEaten = true;
3870 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003871
3872 Tok = Parser.getTok();
3873 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003874 if (Reg == -1) {
3875 if (!haveEaten)
3876 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003877 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003878 return MatchOperand_ParseFail;
3879 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003880
3881 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003882 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003883
3884 return MatchOperand_Success;
3885}
3886
Jim Grosbach7db8d692011-09-08 22:07:06 +00003887/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3888/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3889/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003890void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003891cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003892 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3893 // Rt, Rt2
3894 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3895 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3896 // Create a writeback register dummy placeholder.
3897 Inst.addOperand(MCOperand::CreateReg(0));
3898 // addr
3899 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3900 // pred
3901 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003902}
3903
3904/// cvtT2StrdPre - Convert parsed operands to MCInst.
3905/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3906/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003907void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003908cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003909 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3910 // Create a writeback register dummy placeholder.
3911 Inst.addOperand(MCOperand::CreateReg(0));
3912 // Rt, Rt2
3913 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3914 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3915 // addr
3916 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3917 // pred
3918 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003919}
3920
Jim Grosbachc086f682011-09-08 00:39:19 +00003921/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3922/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3923/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003924void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003925cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00003926 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3927 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3928
3929 // Create a writeback register dummy placeholder.
3930 Inst.addOperand(MCOperand::CreateImm(0));
3931
3932 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3933 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00003934}
3935
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003936/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3937/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3938/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003939void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003940cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003941 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3942 // Create a writeback register dummy placeholder.
3943 Inst.addOperand(MCOperand::CreateImm(0));
3944 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3945 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3946 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003947}
3948
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003949/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003950/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3951/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003952void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003953cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003954 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3955 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3956
3957 // Create a writeback register dummy placeholder.
3958 Inst.addOperand(MCOperand::CreateImm(0));
3959
Jim Grosbachd3595712011-08-03 23:50:40 +00003960 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003961 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003962}
3963
Owen Anderson16d33f32011-08-26 20:43:14 +00003964/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3965/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3966/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003967void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003968cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00003969 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3970 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3971
3972 // Create a writeback register dummy placeholder.
3973 Inst.addOperand(MCOperand::CreateImm(0));
3974
3975 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3976 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00003977}
3978
3979
Jim Grosbachd564bf32011-08-11 19:22:40 +00003980/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3981/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3982/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003983void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003984cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00003985 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3986 // Create a writeback register dummy placeholder.
3987 Inst.addOperand(MCOperand::CreateImm(0));
3988 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3989 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3990 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00003991}
3992
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003993/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003994/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3995/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003996void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003997cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003998 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3999 // Create a writeback register dummy placeholder.
4000 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00004001 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4002 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4003 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004004}
4005
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004006/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4007/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4008/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004009void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004010cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004011 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4012 // Create a writeback register dummy placeholder.
4013 Inst.addOperand(MCOperand::CreateImm(0));
4014 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4015 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4016 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004017}
4018
Jim Grosbachd3595712011-08-03 23:50:40 +00004019/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4020/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4021/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004022void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004023cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004024 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4025 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004026 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004027 // Create a writeback register dummy placeholder.
4028 Inst.addOperand(MCOperand::CreateImm(0));
4029 // addr
4030 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4031 // offset
4032 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4033 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004034 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004035}
4036
Jim Grosbachd3595712011-08-03 23:50:40 +00004037/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004038/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4039/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004040void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004041cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004042 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4043 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004044 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004045 // Create a writeback register dummy placeholder.
4046 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004047 // addr
4048 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4049 // offset
4050 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4051 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004052 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004053}
4054
Jim Grosbachd3595712011-08-03 23:50:40 +00004055/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004056/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4057/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004058void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004059cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004060 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004061 // Create a writeback register dummy placeholder.
4062 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004063 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004064 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004065 // addr
4066 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4067 // offset
4068 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4069 // pred
4070 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004071}
4072
4073/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4074/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4075/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004076void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004077cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004078 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4079 // Create a writeback register dummy placeholder.
4080 Inst.addOperand(MCOperand::CreateImm(0));
4081 // Rt
4082 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4083 // addr
4084 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4085 // offset
4086 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4087 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004088 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004089}
4090
Jim Grosbach5b96b802011-08-10 20:29:19 +00004091/// cvtLdrdPre - Convert parsed operands to MCInst.
4092/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4093/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004094void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004095cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004096 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4097 // Rt, Rt2
4098 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4099 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4100 // Create a writeback register dummy placeholder.
4101 Inst.addOperand(MCOperand::CreateImm(0));
4102 // addr
4103 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4104 // pred
4105 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004106}
4107
Jim Grosbacheb09f492011-08-11 20:28:23 +00004108/// cvtStrdPre - Convert parsed operands to MCInst.
4109/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4110/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004111void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004112cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004113 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4114 // Create a writeback register dummy placeholder.
4115 Inst.addOperand(MCOperand::CreateImm(0));
4116 // Rt, Rt2
4117 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4118 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4119 // addr
4120 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4121 // pred
4122 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004123}
4124
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004125/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4126/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4127/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004128void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004129cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004130 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4131 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4132 // Create a writeback register dummy placeholder.
4133 Inst.addOperand(MCOperand::CreateImm(0));
4134 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4135 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004136}
4137
Chad Rosier5eec49f2012-08-30 23:00:00 +00004138/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004139/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4140/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004141void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004142cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004143 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004144 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4145 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004146 // If we have a three-operand form, make sure to set Rn to be the operand
4147 // that isn't the same as Rd.
4148 unsigned RegOp = 4;
4149 if (Operands.size() == 6 &&
4150 ((ARMOperand*)Operands[4])->getReg() ==
4151 ((ARMOperand*)Operands[3])->getReg())
4152 RegOp = 5;
4153 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4154 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004155 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004156}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004157
Chad Rosier98cfa102012-08-31 00:03:31 +00004158void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004159cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004160 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4161 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004162 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004163 // Create a writeback register dummy placeholder.
4164 Inst.addOperand(MCOperand::CreateImm(0));
4165 // Vn
4166 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4167 // pred
4168 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004169}
4170
Chad Rosier98cfa102012-08-31 00:03:31 +00004171void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004172cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004173 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4174 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004175 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004176 // Create a writeback register dummy placeholder.
4177 Inst.addOperand(MCOperand::CreateImm(0));
4178 // Vn
4179 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4180 // Vm
4181 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4182 // pred
4183 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004184}
4185
Chad Rosier98cfa102012-08-31 00:03:31 +00004186void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004187cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004188 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4189 // Create a writeback register dummy placeholder.
4190 Inst.addOperand(MCOperand::CreateImm(0));
4191 // Vn
4192 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4193 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004194 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004195 // pred
4196 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004197}
4198
Chad Rosier98cfa102012-08-31 00:03:31 +00004199void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004200cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004201 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4202 // Create a writeback register dummy placeholder.
4203 Inst.addOperand(MCOperand::CreateImm(0));
4204 // Vn
4205 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4206 // Vm
4207 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4208 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004209 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004210 // pred
4211 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004212}
4213
Bill Wendlinge18980a2010-11-06 22:36:58 +00004214/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004215/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004216bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004217parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004218 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004219 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004220 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004221 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004222 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004223
Sean Callanan936b0d32010-01-19 21:44:56 +00004224 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004225 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004226 if (BaseRegNum == -1)
4227 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004228
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004229 // The next token must either be a comma or a closing bracket.
4230 const AsmToken &Tok = Parser.getTok();
4231 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004232 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004233
Jim Grosbachd3595712011-08-03 23:50:40 +00004234 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004235 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004236 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004237
Jim Grosbachd3595712011-08-03 23:50:40 +00004238 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004239 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004240
Jim Grosbach40700e02011-09-19 18:42:21 +00004241 // If there's a pre-indexing writeback marker, '!', just add it as a token
4242 // operand. It's rather odd, but syntactically valid.
4243 if (Parser.getTok().is(AsmToken::Exclaim)) {
4244 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4245 Parser.Lex(); // Eat the '!'.
4246 }
4247
Jim Grosbachd3595712011-08-03 23:50:40 +00004248 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004249 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004250
Jim Grosbachd3595712011-08-03 23:50:40 +00004251 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4252 Parser.Lex(); // Eat the comma.
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004253
Jim Grosbacha95ec992011-10-11 17:29:55 +00004254 // If we have a ':', it's an alignment specifier.
4255 if (Parser.getTok().is(AsmToken::Colon)) {
4256 Parser.Lex(); // Eat the ':'.
4257 E = Parser.getTok().getLoc();
4258
4259 const MCExpr *Expr;
4260 if (getParser().ParseExpression(Expr))
4261 return true;
4262
4263 // The expression has to be a constant. Memory references with relocations
4264 // don't come through here, as they use the <label> forms of the relevant
4265 // instructions.
4266 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4267 if (!CE)
4268 return Error (E, "constant expression expected");
4269
4270 unsigned Align = 0;
4271 switch (CE->getValue()) {
4272 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004273 return Error(E,
4274 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4275 case 16: Align = 2; break;
4276 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004277 case 64: Align = 8; break;
4278 case 128: Align = 16; break;
4279 case 256: Align = 32; break;
4280 }
4281
4282 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004283 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004284 return Error(Parser.getTok().getLoc(), "']' expected");
4285 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004286 Parser.Lex(); // Eat right bracket token.
4287
4288 // Don't worry about range checking the value here. That's handled by
4289 // the is*() predicates.
4290 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4291 ARM_AM::no_shift, 0, Align,
4292 false, S, E));
4293
4294 // If there's a pre-indexing writeback marker, '!', just add it as a token
4295 // operand.
4296 if (Parser.getTok().is(AsmToken::Exclaim)) {
4297 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4298 Parser.Lex(); // Eat the '!'.
4299 }
4300
4301 return false;
4302 }
4303
4304 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004305 // offset. Be friendly and also accept a plain integer (without a leading
4306 // hash) for gas compatibility.
4307 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004308 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004309 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004310 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach8279c182011-11-15 22:14:41 +00004311 Parser.Lex(); // Eat the '#'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004312 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004313
Owen Anderson967674d2011-08-29 19:36:44 +00004314 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004315 const MCExpr *Offset;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004316 if (getParser().ParseExpression(Offset))
4317 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004318
4319 // The expression has to be a constant. Memory references with relocations
4320 // don't come through here, as they use the <label> forms of the relevant
4321 // instructions.
4322 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4323 if (!CE)
4324 return Error (E, "constant expression expected");
4325
Owen Anderson967674d2011-08-29 19:36:44 +00004326 // If the constant was #-0, represent it as INT32_MIN.
4327 int32_t Val = CE->getValue();
4328 if (isNegative && Val == 0)
4329 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4330
Jim Grosbachd3595712011-08-03 23:50:40 +00004331 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004332 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004333 return Error(Parser.getTok().getLoc(), "']' expected");
4334 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004335 Parser.Lex(); // Eat right bracket token.
4336
4337 // Don't worry about range checking the value here. That's handled by
4338 // the is*() predicates.
4339 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004340 ARM_AM::no_shift, 0, 0,
4341 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004342
4343 // If there's a pre-indexing writeback marker, '!', just add it as a token
4344 // operand.
4345 if (Parser.getTok().is(AsmToken::Exclaim)) {
4346 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4347 Parser.Lex(); // Eat the '!'.
4348 }
4349
4350 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004351 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004352
4353 // The register offset is optionally preceded by a '+' or '-'
4354 bool isNegative = false;
4355 if (Parser.getTok().is(AsmToken::Minus)) {
4356 isNegative = true;
4357 Parser.Lex(); // Eat the '-'.
4358 } else if (Parser.getTok().is(AsmToken::Plus)) {
4359 // Nothing to do.
4360 Parser.Lex(); // Eat the '+'.
4361 }
4362
4363 E = Parser.getTok().getLoc();
4364 int OffsetRegNum = tryParseRegister();
4365 if (OffsetRegNum == -1)
4366 return Error(E, "register expected");
4367
4368 // If there's a shift operator, handle it.
4369 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004370 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004371 if (Parser.getTok().is(AsmToken::Comma)) {
4372 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004373 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004374 return true;
4375 }
4376
4377 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004378 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004379 return Error(Parser.getTok().getLoc(), "']' expected");
4380 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004381 Parser.Lex(); // Eat right bracket token.
4382
4383 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004384 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004385 S, E));
4386
Jim Grosbachc320c852011-08-05 21:28:30 +00004387 // If there's a pre-indexing writeback marker, '!', just add it as a token
4388 // operand.
4389 if (Parser.getTok().is(AsmToken::Exclaim)) {
4390 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4391 Parser.Lex(); // Eat the '!'.
4392 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004393
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004394 return false;
4395}
4396
Jim Grosbachd3595712011-08-03 23:50:40 +00004397/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004398/// ( lsl | lsr | asr | ror ) , # shift_amount
4399/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004400/// return true if it parses a shift otherwise it returns false.
4401bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4402 unsigned &Amount) {
4403 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004404 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 if (Tok.isNot(AsmToken::Identifier))
4406 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004407 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004408 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4409 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004410 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004411 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004412 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004413 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004414 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004415 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004416 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004417 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004418 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004419 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004420 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004421 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004422
Jim Grosbachd3595712011-08-03 23:50:40 +00004423 // rrx stands alone.
4424 Amount = 0;
4425 if (St != ARM_AM::rrx) {
4426 Loc = Parser.getTok().getLoc();
4427 // A '#' and a shift amount.
4428 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004429 if (HashTok.isNot(AsmToken::Hash) &&
4430 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004431 return Error(HashTok.getLoc(), "'#' expected");
4432 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004433
Jim Grosbachd3595712011-08-03 23:50:40 +00004434 const MCExpr *Expr;
4435 if (getParser().ParseExpression(Expr))
4436 return true;
4437 // Range check the immediate.
4438 // lsl, ror: 0 <= imm <= 31
4439 // lsr, asr: 0 <= imm <= 32
4440 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4441 if (!CE)
4442 return Error(Loc, "shift amount must be an immediate");
4443 int64_t Imm = CE->getValue();
4444 if (Imm < 0 ||
4445 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4446 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4447 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004448 // If <ShiftTy> #0, turn it into a no_shift.
4449 if (Imm == 0)
4450 St = ARM_AM::lsl;
4451 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4452 if (Imm == 32)
4453 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004454 Amount = Imm;
4455 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004456
4457 return false;
4458}
4459
Jim Grosbache7fbce72011-10-03 23:38:36 +00004460/// parseFPImm - A floating point immediate expression operand.
4461ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4462parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004463 // Anything that can accept a floating point constant as an operand
4464 // needs to go through here, as the regular ParseExpression is
4465 // integer only.
4466 //
4467 // This routine still creates a generic Immediate operand, containing
4468 // a bitcast of the 64-bit floating point value. The various operands
4469 // that accept floats can check whether the value is valid for them
4470 // via the standard is*() predicates.
4471
Jim Grosbache7fbce72011-10-03 23:38:36 +00004472 SMLoc S = Parser.getTok().getLoc();
4473
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004474 if (Parser.getTok().isNot(AsmToken::Hash) &&
4475 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004476 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004477
4478 // Disambiguate the VMOV forms that can accept an FP immediate.
4479 // vmov.f32 <sreg>, #imm
4480 // vmov.f64 <dreg>, #imm
4481 // vmov.f32 <dreg>, #imm @ vector f32x2
4482 // vmov.f32 <qreg>, #imm @ vector f32x4
4483 //
4484 // There are also the NEON VMOV instructions which expect an
4485 // integer constant. Make sure we don't try to parse an FPImm
4486 // for these:
4487 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4488 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4489 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4490 TyOp->getToken() != ".f64"))
4491 return MatchOperand_NoMatch;
4492
Jim Grosbache7fbce72011-10-03 23:38:36 +00004493 Parser.Lex(); // Eat the '#'.
4494
4495 // Handle negation, as that still comes through as a separate token.
4496 bool isNegative = false;
4497 if (Parser.getTok().is(AsmToken::Minus)) {
4498 isNegative = true;
4499 Parser.Lex();
4500 }
4501 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004502 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004503 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004504 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004505 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4506 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004507 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004508 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004509 Operands.push_back(ARMOperand::CreateImm(
4510 MCConstantExpr::Create(IntVal, getContext()),
4511 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004512 return MatchOperand_Success;
4513 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004514 // Also handle plain integers. Instructions which allow floating point
4515 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004516 if (Tok.is(AsmToken::Integer)) {
4517 int64_t Val = Tok.getIntVal();
4518 Parser.Lex(); // Eat the token.
4519 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004520 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004521 return MatchOperand_ParseFail;
4522 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004523 double RealVal = ARM_AM::getFPImmFloat(Val);
4524 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4525 Operands.push_back(ARMOperand::CreateImm(
4526 MCConstantExpr::Create(Val, getContext()), S,
4527 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004528 return MatchOperand_Success;
4529 }
4530
Jim Grosbach235c8d22012-01-19 02:47:30 +00004531 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004532 return MatchOperand_ParseFail;
4533}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004534
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004535/// Parse a arm instruction operand. For now this parses the operand regardless
4536/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004537bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004538 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004539 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004540
4541 // Check if the current operand has a custom associated parser, if so, try to
4542 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004543 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4544 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004545 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004546 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4547 // there was a match, but an error occurred, in which case, just return that
4548 // the operand parsing failed.
4549 if (ResTy == MatchOperand_ParseFail)
4550 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004551
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004552 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004553 default:
4554 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004555 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004556 case AsmToken::Identifier: {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004557 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling2063b842010-11-18 23:43:05 +00004558 return false;
Jim Grosbach0d6022d2011-07-26 20:41:24 +00004559 int Res = tryParseShiftRegister(Operands);
Jim Grosbachbb24c592011-07-13 18:49:30 +00004560 if (Res == 0) // success
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004561 return false;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004562 else if (Res == -1) // irrecoverable error
4563 return true;
Jim Grosbach4eda1452011-12-20 22:26:38 +00004564 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachd28888d2012-03-15 21:34:14 +00004565 if (Mnemonic == "vmrs" &&
4566 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004567 S = Parser.getTok().getLoc();
4568 Parser.Lex();
Jim Grosbachd28888d2012-03-15 21:34:14 +00004569 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004570 return false;
4571 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004572
4573 // Fall though for the Identifier case that is not a register or a
4574 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004575 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004576 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004577 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004578 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004579 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004580 // This was not a register so parse other operands that start with an
4581 // identifier (like labels) as expressions and create them as immediates.
4582 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004583 S = Parser.getTok().getLoc();
Kevin Enderby146dcf22009-10-15 20:48:48 +00004584 if (getParser().ParseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004585 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004586 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004587 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4588 return false;
4589 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004590 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004591 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004592 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004593 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004594 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004595 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004596 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004597 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004598 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004599
4600 if (Parser.getTok().isNot(AsmToken::Colon)) {
4601 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4602 const MCExpr *ImmVal;
4603 if (getParser().ParseExpression(ImmVal))
4604 return true;
4605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4606 if (CE) {
4607 int32_t Val = CE->getValue();
4608 if (isNegative && Val == 0)
4609 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4610 }
4611 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4612 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4613 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004614 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004615 // w/ a ':' after the '#', it's just like a plain ':'.
4616 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004617 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004618 case AsmToken::Colon: {
4619 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004620 // FIXME: Check it's an expression prefix,
4621 // e.g. (FOO - :lower16:BAR) isn't legal.
4622 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004623 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004624 return true;
4625
Evan Cheng965b3c72011-01-13 07:58:56 +00004626 const MCExpr *SubExprVal;
4627 if (getParser().ParseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004628 return true;
4629
Evan Cheng965b3c72011-01-13 07:58:56 +00004630 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004631 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004632 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004633 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004634 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004635 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004636 }
4637}
4638
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004639// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004640// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004641bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004642 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004643
4644 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004645 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004646 Parser.Lex(); // Eat ':'
4647
4648 if (getLexer().isNot(AsmToken::Identifier)) {
4649 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4650 return true;
4651 }
4652
4653 StringRef IDVal = Parser.getTok().getIdentifier();
4654 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004655 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004656 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004657 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004658 } else {
4659 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4660 return true;
4661 }
4662 Parser.Lex();
4663
4664 if (getLexer().isNot(AsmToken::Colon)) {
4665 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4666 return true;
4667 }
4668 Parser.Lex(); // Eat the last ':'
4669 return false;
4670}
4671
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004672/// \brief Given a mnemonic, split out possible predication code and carry
4673/// setting letters to form a canonical mnemonic and flags.
4674//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004675// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004676// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004677StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004678 unsigned &PredicationCode,
4679 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004680 unsigned &ProcessorIMod,
4681 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004682 PredicationCode = ARMCC::AL;
4683 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004684 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004685
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004686 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004687 //
4688 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004689 if ((Mnemonic == "movs" && isThumb()) ||
4690 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4691 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4692 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4693 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4694 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4695 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004696 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4697 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004698 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004699
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004700 // First, split out any predication code. Ignore mnemonics we know aren't
4701 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004702 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004703 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004704 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004705 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004706 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4707 .Case("eq", ARMCC::EQ)
4708 .Case("ne", ARMCC::NE)
4709 .Case("hs", ARMCC::HS)
4710 .Case("cs", ARMCC::HS)
4711 .Case("lo", ARMCC::LO)
4712 .Case("cc", ARMCC::LO)
4713 .Case("mi", ARMCC::MI)
4714 .Case("pl", ARMCC::PL)
4715 .Case("vs", ARMCC::VS)
4716 .Case("vc", ARMCC::VC)
4717 .Case("hi", ARMCC::HI)
4718 .Case("ls", ARMCC::LS)
4719 .Case("ge", ARMCC::GE)
4720 .Case("lt", ARMCC::LT)
4721 .Case("gt", ARMCC::GT)
4722 .Case("le", ARMCC::LE)
4723 .Case("al", ARMCC::AL)
4724 .Default(~0U);
4725 if (CC != ~0U) {
4726 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4727 PredicationCode = CC;
4728 }
Bill Wendling193961b2010-10-29 23:50:21 +00004729 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004730
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004731 // Next, determine if we have a carry setting bit. We explicitly ignore all
4732 // the instructions we know end in 's'.
4733 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004734 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004735 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4736 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4737 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004738 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004739 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004740 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004741 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004742 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004743 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004744 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4745 CarrySetting = true;
4746 }
4747
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004748 // The "cps" instruction can have a interrupt mode operand which is glued into
4749 // the mnemonic. Check if this is the case, split it and parse the imod op
4750 if (Mnemonic.startswith("cps")) {
4751 // Split out any imod code.
4752 unsigned IMod =
4753 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4754 .Case("ie", ARM_PROC::IE)
4755 .Case("id", ARM_PROC::ID)
4756 .Default(~0U);
4757 if (IMod != ~0U) {
4758 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4759 ProcessorIMod = IMod;
4760 }
4761 }
4762
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004763 // The "it" instruction has the condition mask on the end of the mnemonic.
4764 if (Mnemonic.startswith("it")) {
4765 ITMask = Mnemonic.slice(2, Mnemonic.size());
4766 Mnemonic = Mnemonic.slice(0, 2);
4767 }
4768
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004769 return Mnemonic;
4770}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004771
4772/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4773/// inclusion of carry set or predication code operands.
4774//
4775// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004776void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004777getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004778 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004779 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4780 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004781 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004782 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004783 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004784 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004785 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004786 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004787 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004788 Mnemonic == "mla" || Mnemonic == "smlal" ||
4789 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004790 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004791 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004792 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004793
Daniel Dunbar09264122011-01-11 19:06:29 +00004794 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4795 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4796 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4797 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004798 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4799 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004800 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004801 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4802 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4803 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004804 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4805 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004806 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004807 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004808 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004809 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004810
Jim Grosbach6c45b752011-09-16 16:39:25 +00004811 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004812 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004813 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004814 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004815 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004816}
4817
Jim Grosbach7283da92011-08-16 21:12:37 +00004818bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4819 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004820 // FIXME: This is all horribly hacky. We really need a better way to deal
4821 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004822
4823 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4824 // another does not. Specifically, the MOVW instruction does not. So we
4825 // special case it here and remove the defaulted (non-setting) cc_out
4826 // operand if that's the instruction we're trying to match.
4827 //
4828 // We do this as post-processing of the explicit operands rather than just
4829 // conditionally adding the cc_out in the first place because we need
4830 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004831 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004832 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4833 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4834 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4835 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004836
4837 // Register-register 'add' for thumb does not have a cc_out operand
4838 // when there are only two register operands.
4839 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4840 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4841 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4842 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4843 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004844 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004845 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4846 // have to check the immediate range here since Thumb2 has a variant
4847 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004848 if (((isThumb() && Mnemonic == "add") ||
4849 (isThumbTwo() && Mnemonic == "sub")) &&
4850 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004851 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4852 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4853 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004854 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004855 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004856 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004857 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004858 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4859 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004860 // selecting via the generic "add" mnemonic, so to know that we
4861 // should remove the cc_out operand, we have to explicitly check that
4862 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004863 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4864 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004865 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4866 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4867 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4868 // Nest conditions rather than one big 'if' statement for readability.
4869 //
4870 // If either register is a high reg, it's either one of the SP
4871 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004872 // check against T3. If the second register is the PC, this is an
4873 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004874 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4875 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004876 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004877 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4878 return false;
4879 // If both registers are low, we're in an IT block, and the immediate is
4880 // in range, we should use encoding T1 instead, which has a cc_out.
4881 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004882 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004883 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4884 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4885 return false;
4886
4887 // Otherwise, we use encoding T4, which does not have a cc_out
4888 // operand.
4889 return true;
4890 }
4891
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004892 // The thumb2 multiply instruction doesn't have a CCOut register, so
4893 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4894 // use the 16-bit encoding or not.
4895 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4896 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4897 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4898 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4899 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4900 // If the registers aren't low regs, the destination reg isn't the
4901 // same as one of the source regs, or the cc_out operand is zero
4902 // outside of an IT block, we have to use the 32-bit encoding, so
4903 // remove the cc_out operand.
4904 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4905 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004906 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004907 !inITBlock() ||
4908 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4909 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4910 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4911 static_cast<ARMOperand*>(Operands[4])->getReg())))
4912 return true;
4913
Jim Grosbachefa7e952011-11-15 19:55:16 +00004914 // Also check the 'mul' syntax variant that doesn't specify an explicit
4915 // destination register.
4916 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4917 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4918 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4919 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4920 // If the registers aren't low regs or the cc_out operand is zero
4921 // outside of an IT block, we have to use the 32-bit encoding, so
4922 // remove the cc_out operand.
4923 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4924 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4925 !inITBlock()))
4926 return true;
4927
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004928
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004929
Jim Grosbach4b701af2011-08-24 21:42:27 +00004930 // Register-register 'add/sub' for thumb does not have a cc_out operand
4931 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4932 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4933 // right, this will result in better diagnostics (which operand is off)
4934 // anyway.
4935 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4936 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004937 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4938 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004939 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4940 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4941 (Operands.size() == 6 &&
4942 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004943 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004944
Jim Grosbach7283da92011-08-16 21:12:37 +00004945 return false;
4946}
4947
Jim Grosbach12952fe2011-11-11 23:08:10 +00004948static bool isDataTypeToken(StringRef Tok) {
4949 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4950 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4951 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4952 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4953 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4954 Tok == ".f" || Tok == ".d";
4955}
4956
4957// FIXME: This bit should probably be handled via an explicit match class
4958// in the .td files that matches the suffix instead of having it be
4959// a literal string token the way it is now.
4960static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4961 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4962}
4963
Jim Grosbach8be2f652011-12-09 23:34:09 +00004964static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004965/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004966bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4967 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004968 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004969 // Apply mnemonic aliases before doing anything else, as the destination
4970 // mnemnonic may include suffices and we want to handle them normally.
4971 // The generic tblgen'erated code does this later, at the start of
4972 // MatchInstructionImpl(), but that's too late for aliases that include
4973 // any sort of suffix.
4974 unsigned AvailableFeatures = getAvailableFeatures();
4975 applyMnemonicAliases(Name, AvailableFeatures);
4976
Jim Grosbachab5830e2011-12-14 02:16:11 +00004977 // First check for the ARM-specific .req directive.
4978 if (Parser.getTok().is(AsmToken::Identifier) &&
4979 Parser.getTok().getIdentifier() == ".req") {
4980 parseDirectiveReq(Name, NameLoc);
4981 // We always return 'error' for this, as we're done with this
4982 // statement and don't need to match the 'instruction."
4983 return true;
4984 }
4985
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004986 // Create the leading tokens for the mnemonic, split by '.' characters.
4987 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004988 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004989
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004990 // Split out the predication code and carry setting flag from the mnemonic.
4991 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004992 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004993 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004994 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004995 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004996 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004997
Jim Grosbach1c171b12011-08-25 17:23:55 +00004998 // In Thumb1, only the branch (B) instruction can be predicated.
4999 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5000 Parser.EatToEndOfStatement();
5001 return Error(NameLoc, "conditional execution not supported in Thumb1");
5002 }
5003
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005004 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5005
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005006 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5007 // is the mask as it will be for the IT encoding if the conditional
5008 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5009 // where the conditional bit0 is zero, the instruction post-processing
5010 // will adjust the mask accordingly.
5011 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005012 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5013 if (ITMask.size() > 3) {
5014 Parser.EatToEndOfStatement();
5015 return Error(Loc, "too many conditions on IT instruction");
5016 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005017 unsigned Mask = 8;
5018 for (unsigned i = ITMask.size(); i != 0; --i) {
5019 char pos = ITMask[i - 1];
5020 if (pos != 't' && pos != 'e') {
5021 Parser.EatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005022 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005023 }
5024 Mask >>= 1;
5025 if (ITMask[i - 1] == 't')
5026 Mask |= 8;
5027 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005028 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005029 }
5030
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005031 // FIXME: This is all a pretty gross hack. We should automatically handle
5032 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005033
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005034 // Next, add the CCOut and ConditionCode operands, if needed.
5035 //
5036 // For mnemonics which can ever incorporate a carry setting bit or predication
5037 // code, our matching model involves us always generating CCOut and
5038 // ConditionCode operands to match the mnemonic "as written" and then we let
5039 // the matcher deal with finding the right instruction or generating an
5040 // appropriate error.
5041 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005042 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005043
Jim Grosbach03a8a162011-07-14 22:04:21 +00005044 // If we had a carry-set on an instruction that can't do that, issue an
5045 // error.
5046 if (!CanAcceptCarrySet && CarrySetting) {
5047 Parser.EatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005048 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005049 "' can not set flags, but 's' suffix specified");
5050 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005051 // If we had a predication code on an instruction that can't do that, issue an
5052 // error.
5053 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5054 Parser.EatToEndOfStatement();
5055 return Error(NameLoc, "instruction '" + Mnemonic +
5056 "' is not predicable, but condition code specified");
5057 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005058
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005059 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005060 if (CanAcceptCarrySet) {
5061 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005062 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005063 Loc));
5064 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005065
5066 // Add the predication code operand, if necessary.
5067 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005068 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5069 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005070 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005071 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005072 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005073
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005074 // Add the processor imod operand, if necessary.
5075 if (ProcessorIMod) {
5076 Operands.push_back(ARMOperand::CreateImm(
5077 MCConstantExpr::Create(ProcessorIMod, getContext()),
5078 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005079 }
5080
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005081 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005082 while (Next != StringRef::npos) {
5083 Start = Next;
5084 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005085 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005086
Jim Grosbach12952fe2011-11-11 23:08:10 +00005087 // Some NEON instructions have an optional datatype suffix that is
5088 // completely ignored. Check for that.
5089 if (isDataTypeToken(ExtraToken) &&
5090 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5091 continue;
5092
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005093 if (ExtraToken != ".n") {
5094 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5095 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5096 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005097 }
5098
5099 // Read the remaining operands.
5100 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005101 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005102 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005103 Parser.EatToEndOfStatement();
5104 return true;
5105 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005106
5107 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005108 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005109
5110 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005111 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005112 Parser.EatToEndOfStatement();
5113 return true;
5114 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005115 }
5116 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005117
Chris Lattnera2a9d162010-09-11 16:18:25 +00005118 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005119 SMLoc Loc = getLexer().getLoc();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005120 Parser.EatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005121 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005122 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005123
Chris Lattner91689c12010-09-08 05:10:46 +00005124 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005125
Jim Grosbach7283da92011-08-16 21:12:37 +00005126 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5127 // do and don't have a cc_out optional-def operand. With some spot-checks
5128 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005129 // parse and adjust accordingly before actually matching. We shouldn't ever
5130 // try to remove a cc_out operand that was explicitly set on the the
5131 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5132 // table driven matcher doesn't fit well with the ARM instruction set.
5133 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005134 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5135 Operands.erase(Operands.begin() + 1);
5136 delete Op;
5137 }
5138
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005139 // ARM mode 'blx' need special handling, as the register operand version
5140 // is predicable, but the label operand version is not. So, we can't rely
5141 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005142 // a k_CondCode operand in the list. If we're trying to match the label
5143 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005144 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5145 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5146 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5147 Operands.erase(Operands.begin() + 1);
5148 delete Op;
5149 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005150
5151 // The vector-compare-to-zero instructions have a literal token "#0" at
5152 // the end that comes to here as an immediate operand. Convert it to a
5153 // token to play nicely with the matcher.
5154 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5155 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5156 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5157 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5159 if (CE && CE->getValue() == 0) {
5160 Operands.erase(Operands.begin() + 5);
5161 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5162 delete Op;
5163 }
5164 }
Jim Grosbach46b66462011-10-03 22:30:24 +00005165 // VCMP{E} does the same thing, but with a different operand count.
5166 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5167 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5168 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5169 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5170 if (CE && CE->getValue() == 0) {
5171 Operands.erase(Operands.begin() + 4);
5172 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5173 delete Op;
5174 }
5175 }
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005176 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005177 // end. Convert it to a token here. Take care not to convert those
5178 // that should hit the Thumb2 encoding.
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005179 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005180 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5181 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005182 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5183 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005185 if (CE && CE->getValue() == 0 &&
5186 (isThumbOne() ||
Jim Grosbach5ac89672011-12-13 21:06:41 +00005187 // The cc_out operand matches the IT block.
5188 ((inITBlock() != CarrySetting) &&
5189 // Neither register operand is a high register.
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005190 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach5ac89672011-12-13 21:06:41 +00005191 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005192 Operands.erase(Operands.begin() + 5);
5193 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5194 delete Op;
5195 }
5196 }
5197
Weiming Zhao8f56f882012-11-16 21:55:34 +00005198 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5199 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5200 // a single GPRPair reg operand is used in the .td file to replace the two
5201 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5202 // expressed as a GPRPair, so we have to manually merge them.
5203 // FIXME: We would really like to be able to tablegen'erate this.
5204 if (!isThumb() && Operands.size() > 4 &&
5205 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5206 bool isLoad = (Mnemonic == "ldrexd");
5207 unsigned Idx = isLoad ? 2 : 3;
5208 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5209 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5210
5211 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5212 // Adjust only if Op1 and Op2 are GPRs.
5213 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5214 MRC.contains(Op2->getReg())) {
5215 unsigned Reg1 = Op1->getReg();
5216 unsigned Reg2 = Op2->getReg();
5217 unsigned Rt = MRI->getEncodingValue(Reg1);
5218 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5219
5220 // Rt2 must be Rt + 1 and Rt must be even.
5221 if (Rt + 1 != Rt2 || (Rt & 1)) {
5222 Error(Op2->getStartLoc(), isLoad ?
5223 "destination operands must be sequential" :
5224 "source operands must be sequential");
5225 return true;
5226 }
5227 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5228 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5229 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5230 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5231 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5232 delete Op1;
5233 delete Op2;
5234 }
5235 }
5236
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005237 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005238}
5239
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005240// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005241
5242// return 'true' if register list contains non-low GPR registers,
5243// 'false' otherwise. If Reg is in the register list or is HiReg, set
5244// 'containsReg' to true.
5245static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5246 unsigned HiReg, bool &containsReg) {
5247 containsReg = false;
5248 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5249 unsigned OpReg = Inst.getOperand(i).getReg();
5250 if (OpReg == Reg)
5251 containsReg = true;
5252 // Anything other than a low register isn't legal here.
5253 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5254 return true;
5255 }
5256 return false;
5257}
5258
Jim Grosbacha31f2232011-09-07 18:05:34 +00005259// Check if the specified regisgter is in the register list of the inst,
5260// starting at the indicated operand number.
5261static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5262 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5263 unsigned OpReg = Inst.getOperand(i).getReg();
5264 if (OpReg == Reg)
5265 return true;
5266 }
5267 return false;
5268}
5269
Jim Grosbached16ec42011-08-29 22:24:09 +00005270// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5271// the ARMInsts array) instead. Getting that here requires awkward
5272// API changes, though. Better way?
5273namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005274extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005275}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005276static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005277 return ARMInsts[Opcode];
5278}
5279
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005280// FIXME: We would really like to be able to tablegen'erate this.
5281bool ARMAsmParser::
5282validateInstruction(MCInst &Inst,
5283 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005284 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005285 SMLoc Loc = Operands[0]->getStartLoc();
5286 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005287 // NOTE: BKPT instruction has the interesting property of being
5288 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005289 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005290 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5291 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005292 unsigned bit = 1;
5293 if (ITState.FirstCond)
5294 ITState.FirstCond = false;
5295 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005296 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005297 // The instruction must be predicable.
5298 if (!MCID.isPredicable())
5299 return Error(Loc, "instructions in IT block must be predicable");
5300 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5301 unsigned ITCond = bit ? ITState.Cond :
5302 ARMCC::getOppositeCondition(ITState.Cond);
5303 if (Cond != ITCond) {
5304 // Find the condition code Operand to get its SMLoc information.
5305 SMLoc CondLoc;
5306 for (unsigned i = 1; i < Operands.size(); ++i)
5307 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5308 CondLoc = Operands[i]->getStartLoc();
5309 return Error(CondLoc, "incorrect condition in IT block; got '" +
5310 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5311 "', but expected '" +
5312 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5313 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005314 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005315 } else if (isThumbTwo() && MCID.isPredicable() &&
5316 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005317 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5318 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005319 return Error(Loc, "predicated instructions must be in IT block");
5320
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005321 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005322 case ARM::LDRD:
5323 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005324 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005325 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005326 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5327 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005328 if (Rt2 != Rt + 1)
5329 return Error(Operands[3]->getStartLoc(),
5330 "destination operands must be sequential");
5331 return false;
5332 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005333 case ARM::STRD: {
5334 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005335 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5336 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005337 if (Rt2 != Rt + 1)
5338 return Error(Operands[3]->getStartLoc(),
5339 "source operands must be sequential");
5340 return false;
5341 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005342 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005343 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005344 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005345 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5346 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005347 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005348 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005349 "source operands must be sequential");
5350 return false;
5351 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005352 case ARM::SBFX:
5353 case ARM::UBFX: {
5354 // width must be in range [1, 32-lsb]
5355 unsigned lsb = Inst.getOperand(2).getImm();
5356 unsigned widthm1 = Inst.getOperand(3).getImm();
5357 if (widthm1 >= 32 - lsb)
5358 return Error(Operands[5]->getStartLoc(),
5359 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005360 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005361 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005362 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005363 // If we're parsing Thumb2, the .w variant is available and handles
5364 // most cases that are normally illegal for a Thumb1 LDM
5365 // instruction. We'll make the transformation in processInstruction()
5366 // if necessary.
5367 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005368 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005369 // in the register list.
5370 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005371 bool hasWritebackToken =
5372 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5373 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005374 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005375 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005376 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5377 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005378 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005379 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005380 return Error(Operands[2]->getStartLoc(),
5381 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005382 // If we should not have writeback, there must not be a '!'. This is
5383 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005384 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005385 return Error(Operands[3]->getStartLoc(),
5386 "writeback operator '!' not allowed when base register "
5387 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005388
5389 break;
5390 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005391 case ARM::t2LDMIA_UPD: {
5392 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5393 return Error(Operands[4]->getStartLoc(),
5394 "writeback operator '!' not allowed when base register "
5395 "in register list");
5396 break;
5397 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005398 case ARM::tMUL: {
5399 // The second source operand must be the same register as the destination
5400 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005401 //
5402 // In this case, we must directly check the parsed operands because the
5403 // cvtThumbMultiply() function is written in such a way that it guarantees
5404 // this first statement is always true for the new Inst. Essentially, the
5405 // destination is unconditionally copied into the second source operand
5406 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005407 if (Operands.size() == 6 &&
5408 (((ARMOperand*)Operands[3])->getReg() !=
5409 ((ARMOperand*)Operands[5])->getReg()) &&
5410 (((ARMOperand*)Operands[3])->getReg() !=
5411 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005412 return Error(Operands[3]->getStartLoc(),
5413 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005414 }
5415 break;
5416 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005417 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5418 // so only issue a diagnostic for thumb1. The instructions will be
5419 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005420 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005421 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005422 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5423 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005424 return Error(Operands[2]->getStartLoc(),
5425 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005426 break;
5427 }
5428 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005429 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005430 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5431 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005432 return Error(Operands[2]->getStartLoc(),
5433 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005434 break;
5435 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005436 case ARM::tSTMIA_UPD: {
5437 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005438 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005439 return Error(Operands[4]->getStartLoc(),
5440 "registers must be in range r0-r7");
5441 break;
5442 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005443 case ARM::tADDrSP: {
5444 // If the non-SP source operand and the destination operand are not the
5445 // same, we need thumb2 (for the wide encoding), or we have an error.
5446 if (!isThumbTwo() &&
5447 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5448 return Error(Operands[4]->getStartLoc(),
5449 "source register must be the same as destination");
5450 }
5451 break;
5452 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005453 }
5454
5455 return false;
5456}
5457
Jim Grosbach1a747242012-01-23 23:45:44 +00005458static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005459 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005460 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005461 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005462 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5463 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5464 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5465 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5466 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5467 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5468 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5469 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5470 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005471
5472 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005473 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5474 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5475 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5476 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5477 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005478
Jim Grosbach1e946a42012-01-24 00:43:12 +00005479 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5480 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5481 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5482 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5483 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005484
Jim Grosbach1e946a42012-01-24 00:43:12 +00005485 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5486 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5487 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5488 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5489 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005490
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005491 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005492 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5493 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5494 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5495 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5496 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5497 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5498 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5499 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5500 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5501 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5502 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5503 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5504 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5505 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5506 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005507
Jim Grosbach1a747242012-01-23 23:45:44 +00005508 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005509 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5510 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5511 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5512 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5513 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5514 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5515 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5516 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5517 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5518 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5519 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5520 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5521 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5522 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5523 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5524 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5525 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5526 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005527
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005528 // VST4LN
5529 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5530 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5531 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5532 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5533 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5534 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5535 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5536 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5537 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5538 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5539 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5540 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5541 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5542 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5543 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5544
Jim Grosbachda70eac2012-01-24 00:58:13 +00005545 // VST4
5546 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5547 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5548 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5549 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5550 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5551 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5552 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5553 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5554 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5555 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5556 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5557 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5558 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5559 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5560 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5561 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5562 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5563 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005564 }
5565}
5566
Jim Grosbach1a747242012-01-23 23:45:44 +00005567static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005568 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005569 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005570 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005571 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5572 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5573 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5574 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5575 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5576 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5577 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5578 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5579 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005580
5581 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005582 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5583 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5584 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5585 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5586 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5587 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5588 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5589 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5590 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5591 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5592 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5593 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5594 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5595 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5596 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005597
Jim Grosbachb78403c2012-01-24 23:47:04 +00005598 // VLD3DUP
5599 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5600 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5601 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5602 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5603 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5604 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5605 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5606 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5607 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5608 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5609 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5610 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5611 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5612 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5613 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5614 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5615 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5616 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5617
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005618 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005619 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5620 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5621 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5622 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5623 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5624 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5625 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5626 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5627 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5628 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5629 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5630 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5631 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5632 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5633 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005634
5635 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005636 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5637 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5638 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5639 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5640 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5641 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5642 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5643 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5644 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5645 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5646 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5647 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5648 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5649 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5650 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5651 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5652 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5653 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005654
Jim Grosbach14952a02012-01-24 18:37:25 +00005655 // VLD4LN
5656 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5657 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5658 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5659 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5660 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5661 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5662 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5663 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5664 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5665 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5666 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5667 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5668 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5669 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5670 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5671
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005672 // VLD4DUP
5673 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5674 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5675 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5676 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5677 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5678 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5679 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5680 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5681 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5682 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5683 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5684 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5685 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5686 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5687 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5688 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5689 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5690 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5691
Jim Grosbached561fc2012-01-24 00:43:17 +00005692 // VLD4
5693 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5694 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5695 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5696 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5697 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5698 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5699 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5700 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5701 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5702 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5703 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5704 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5705 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5706 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5707 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5708 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5709 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5710 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005711 }
5712}
5713
Jim Grosbachafad0532011-11-10 23:42:14 +00005714bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005715processInstruction(MCInst &Inst,
5716 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5717 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005718 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5719 case ARM::ADDri: {
5720 if (Inst.getOperand(1).getReg() != ARM::PC ||
5721 Inst.getOperand(5).getReg() != 0)
5722 return false;
5723 MCInst TmpInst;
5724 TmpInst.setOpcode(ARM::ADR);
5725 TmpInst.addOperand(Inst.getOperand(0));
5726 TmpInst.addOperand(Inst.getOperand(2));
5727 TmpInst.addOperand(Inst.getOperand(3));
5728 TmpInst.addOperand(Inst.getOperand(4));
5729 Inst = TmpInst;
5730 return true;
5731 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005732 // Aliases for alternate PC+imm syntax of LDR instructions.
5733 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005734 // Select the narrow version if the immediate will fit.
5735 if (Inst.getOperand(1).getImm() > 0 &&
5736 Inst.getOperand(1).getImm() <= 0xff)
5737 Inst.setOpcode(ARM::tLDRpci);
5738 else
5739 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005740 return true;
5741 case ARM::t2LDRBpcrel:
5742 Inst.setOpcode(ARM::t2LDRBpci);
5743 return true;
5744 case ARM::t2LDRHpcrel:
5745 Inst.setOpcode(ARM::t2LDRHpci);
5746 return true;
5747 case ARM::t2LDRSBpcrel:
5748 Inst.setOpcode(ARM::t2LDRSBpci);
5749 return true;
5750 case ARM::t2LDRSHpcrel:
5751 Inst.setOpcode(ARM::t2LDRSHpci);
5752 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005753 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005754 case ARM::VST1LNdWB_register_Asm_8:
5755 case ARM::VST1LNdWB_register_Asm_16:
5756 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005757 MCInst TmpInst;
5758 // Shuffle the operands around so the lane index operand is in the
5759 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005760 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005761 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005762 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5763 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5764 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5765 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5766 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5767 TmpInst.addOperand(Inst.getOperand(1)); // lane
5768 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5769 TmpInst.addOperand(Inst.getOperand(6));
5770 Inst = TmpInst;
5771 return true;
5772 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005773
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005774 case ARM::VST2LNdWB_register_Asm_8:
5775 case ARM::VST2LNdWB_register_Asm_16:
5776 case ARM::VST2LNdWB_register_Asm_32:
5777 case ARM::VST2LNqWB_register_Asm_16:
5778 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005779 MCInst TmpInst;
5780 // Shuffle the operands around so the lane index operand is in the
5781 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005782 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005783 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005784 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5785 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5786 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5787 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5788 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5790 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005791 TmpInst.addOperand(Inst.getOperand(1)); // lane
5792 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5793 TmpInst.addOperand(Inst.getOperand(6));
5794 Inst = TmpInst;
5795 return true;
5796 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005797
5798 case ARM::VST3LNdWB_register_Asm_8:
5799 case ARM::VST3LNdWB_register_Asm_16:
5800 case ARM::VST3LNdWB_register_Asm_32:
5801 case ARM::VST3LNqWB_register_Asm_16:
5802 case ARM::VST3LNqWB_register_Asm_32: {
5803 MCInst TmpInst;
5804 // Shuffle the operands around so the lane index operand is in the
5805 // right place.
5806 unsigned Spacing;
5807 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5808 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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5814 Spacing));
5815 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5816 Spacing * 2));
5817 TmpInst.addOperand(Inst.getOperand(1)); // lane
5818 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5819 TmpInst.addOperand(Inst.getOperand(6));
5820 Inst = TmpInst;
5821 return true;
5822 }
5823
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005824 case ARM::VST4LNdWB_register_Asm_8:
5825 case ARM::VST4LNdWB_register_Asm_16:
5826 case ARM::VST4LNdWB_register_Asm_32:
5827 case ARM::VST4LNqWB_register_Asm_16:
5828 case ARM::VST4LNqWB_register_Asm_32: {
5829 MCInst TmpInst;
5830 // Shuffle the operands around so the lane index operand is in the
5831 // right place.
5832 unsigned Spacing;
5833 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5834 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5835 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5836 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5837 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5838 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5839 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5840 Spacing));
5841 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5842 Spacing * 2));
5843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5844 Spacing * 3));
5845 TmpInst.addOperand(Inst.getOperand(1)); // lane
5846 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5847 TmpInst.addOperand(Inst.getOperand(6));
5848 Inst = TmpInst;
5849 return true;
5850 }
5851
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005852 case ARM::VST1LNdWB_fixed_Asm_8:
5853 case ARM::VST1LNdWB_fixed_Asm_16:
5854 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005855 MCInst TmpInst;
5856 // Shuffle the operands around so the lane index operand is in the
5857 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005858 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005859 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005860 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5861 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5862 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5863 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5864 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5865 TmpInst.addOperand(Inst.getOperand(1)); // lane
5866 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5867 TmpInst.addOperand(Inst.getOperand(5));
5868 Inst = TmpInst;
5869 return true;
5870 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005871
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005872 case ARM::VST2LNdWB_fixed_Asm_8:
5873 case ARM::VST2LNdWB_fixed_Asm_16:
5874 case ARM::VST2LNdWB_fixed_Asm_32:
5875 case ARM::VST2LNqWB_fixed_Asm_16:
5876 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005877 MCInst TmpInst;
5878 // Shuffle the operands around so the lane index operand is in the
5879 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005880 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005881 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005882 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5883 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5884 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5885 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5886 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5888 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005889 TmpInst.addOperand(Inst.getOperand(1)); // lane
5890 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5891 TmpInst.addOperand(Inst.getOperand(5));
5892 Inst = TmpInst;
5893 return true;
5894 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005895
5896 case ARM::VST3LNdWB_fixed_Asm_8:
5897 case ARM::VST3LNdWB_fixed_Asm_16:
5898 case ARM::VST3LNdWB_fixed_Asm_32:
5899 case ARM::VST3LNqWB_fixed_Asm_16:
5900 case ARM::VST3LNqWB_fixed_Asm_32: {
5901 MCInst TmpInst;
5902 // Shuffle the operands around so the lane index operand is in the
5903 // right place.
5904 unsigned Spacing;
5905 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5906 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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5912 Spacing));
5913 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5914 Spacing * 2));
5915 TmpInst.addOperand(Inst.getOperand(1)); // lane
5916 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5917 TmpInst.addOperand(Inst.getOperand(5));
5918 Inst = TmpInst;
5919 return true;
5920 }
5921
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005922 case ARM::VST4LNdWB_fixed_Asm_8:
5923 case ARM::VST4LNdWB_fixed_Asm_16:
5924 case ARM::VST4LNdWB_fixed_Asm_32:
5925 case ARM::VST4LNqWB_fixed_Asm_16:
5926 case ARM::VST4LNqWB_fixed_Asm_32: {
5927 MCInst TmpInst;
5928 // Shuffle the operands around so the lane index operand is in the
5929 // right place.
5930 unsigned Spacing;
5931 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5932 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5933 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5934 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5935 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5936 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5937 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5938 Spacing));
5939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5940 Spacing * 2));
5941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5942 Spacing * 3));
5943 TmpInst.addOperand(Inst.getOperand(1)); // lane
5944 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5945 TmpInst.addOperand(Inst.getOperand(5));
5946 Inst = TmpInst;
5947 return true;
5948 }
5949
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005950 case ARM::VST1LNdAsm_8:
5951 case ARM::VST1LNdAsm_16:
5952 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005953 MCInst TmpInst;
5954 // Shuffle the operands around so the lane index operand is in the
5955 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005956 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005957 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005958 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5959 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5960 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005967
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005968 case ARM::VST2LNdAsm_8:
5969 case ARM::VST2LNdAsm_16:
5970 case ARM::VST2LNdAsm_32:
5971 case ARM::VST2LNqAsm_16:
5972 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005973 MCInst TmpInst;
5974 // Shuffle the operands around so the lane index operand is in the
5975 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005976 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005977 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005978 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5979 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5980 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5982 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005983 TmpInst.addOperand(Inst.getOperand(1)); // lane
5984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5985 TmpInst.addOperand(Inst.getOperand(5));
5986 Inst = TmpInst;
5987 return true;
5988 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005989
5990 case ARM::VST3LNdAsm_8:
5991 case ARM::VST3LNdAsm_16:
5992 case ARM::VST3LNdAsm_32:
5993 case ARM::VST3LNqAsm_16:
5994 case ARM::VST3LNqAsm_32: {
5995 MCInst TmpInst;
5996 // Shuffle the operands around so the lane index operand is in the
5997 // right place.
5998 unsigned Spacing;
5999 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6000 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6001 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6002 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6003 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6004 Spacing));
6005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6006 Spacing * 2));
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 }
6013
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006014 case ARM::VST4LNdAsm_8:
6015 case ARM::VST4LNdAsm_16:
6016 case ARM::VST4LNdAsm_32:
6017 case ARM::VST4LNqAsm_16:
6018 case ARM::VST4LNqAsm_32: {
6019 MCInst TmpInst;
6020 // Shuffle the operands around so the lane index operand is in the
6021 // right place.
6022 unsigned Spacing;
6023 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6024 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6025 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6026 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6028 Spacing));
6029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6030 Spacing * 2));
6031 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6032 Spacing * 3));
6033 TmpInst.addOperand(Inst.getOperand(1)); // lane
6034 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6035 TmpInst.addOperand(Inst.getOperand(5));
6036 Inst = TmpInst;
6037 return true;
6038 }
6039
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006040 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006041 case ARM::VLD1LNdWB_register_Asm_8:
6042 case ARM::VLD1LNdWB_register_Asm_16:
6043 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006044 MCInst TmpInst;
6045 // Shuffle the operands around so the lane index operand is in the
6046 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006047 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006048 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006049 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6050 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6051 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6052 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6053 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6054 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6055 TmpInst.addOperand(Inst.getOperand(1)); // lane
6056 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6057 TmpInst.addOperand(Inst.getOperand(6));
6058 Inst = TmpInst;
6059 return true;
6060 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006061
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006062 case ARM::VLD2LNdWB_register_Asm_8:
6063 case ARM::VLD2LNdWB_register_Asm_16:
6064 case ARM::VLD2LNdWB_register_Asm_32:
6065 case ARM::VLD2LNqWB_register_Asm_16:
6066 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006067 MCInst TmpInst;
6068 // Shuffle the operands around so the lane index operand is in the
6069 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006070 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006071 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006072 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006075 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6076 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6077 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6078 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6079 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006082 TmpInst.addOperand(Inst.getOperand(1)); // lane
6083 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6084 TmpInst.addOperand(Inst.getOperand(6));
6085 Inst = TmpInst;
6086 return true;
6087 }
6088
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006089 case ARM::VLD3LNdWB_register_Asm_8:
6090 case ARM::VLD3LNdWB_register_Asm_16:
6091 case ARM::VLD3LNdWB_register_Asm_32:
6092 case ARM::VLD3LNqWB_register_Asm_16:
6093 case ARM::VLD3LNqWB_register_Asm_32: {
6094 MCInst TmpInst;
6095 // Shuffle the operands around so the lane index operand is in the
6096 // right place.
6097 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006098 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006099 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 Spacing));
6102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006103 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006104 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6105 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6106 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6107 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6108 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6109 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6110 Spacing));
6111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006112 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006113 TmpInst.addOperand(Inst.getOperand(1)); // lane
6114 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6115 TmpInst.addOperand(Inst.getOperand(6));
6116 Inst = TmpInst;
6117 return true;
6118 }
6119
Jim Grosbach14952a02012-01-24 18:37:25 +00006120 case ARM::VLD4LNdWB_register_Asm_8:
6121 case ARM::VLD4LNdWB_register_Asm_16:
6122 case ARM::VLD4LNdWB_register_Asm_32:
6123 case ARM::VLD4LNqWB_register_Asm_16:
6124 case ARM::VLD4LNqWB_register_Asm_32: {
6125 MCInst TmpInst;
6126 // Shuffle the operands around so the lane index operand is in the
6127 // right place.
6128 unsigned Spacing;
6129 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6130 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6132 Spacing));
6133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6134 Spacing * 2));
6135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6136 Spacing * 3));
6137 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6140 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6141 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 Spacing));
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6145 Spacing * 2));
6146 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 Spacing * 3));
6148 TmpInst.addOperand(Inst.getOperand(1)); // lane
6149 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6150 TmpInst.addOperand(Inst.getOperand(6));
6151 Inst = TmpInst;
6152 return true;
6153 }
6154
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006155 case ARM::VLD1LNdWB_fixed_Asm_8:
6156 case ARM::VLD1LNdWB_fixed_Asm_16:
6157 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006158 MCInst TmpInst;
6159 // Shuffle the operands around so the lane index operand is in the
6160 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006161 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006162 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006163 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6164 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6165 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6166 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6167 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6168 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6169 TmpInst.addOperand(Inst.getOperand(1)); // lane
6170 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6171 TmpInst.addOperand(Inst.getOperand(5));
6172 Inst = TmpInst;
6173 return true;
6174 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006175
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006176 case ARM::VLD2LNdWB_fixed_Asm_8:
6177 case ARM::VLD2LNdWB_fixed_Asm_16:
6178 case ARM::VLD2LNdWB_fixed_Asm_32:
6179 case ARM::VLD2LNqWB_fixed_Asm_16:
6180 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006181 MCInst TmpInst;
6182 // Shuffle the operands around so the lane index operand is in the
6183 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006184 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006185 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006189 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6190 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6191 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6192 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6193 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006194 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6195 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006196 TmpInst.addOperand(Inst.getOperand(1)); // lane
6197 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6198 TmpInst.addOperand(Inst.getOperand(5));
6199 Inst = TmpInst;
6200 return true;
6201 }
6202
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006203 case ARM::VLD3LNdWB_fixed_Asm_8:
6204 case ARM::VLD3LNdWB_fixed_Asm_16:
6205 case ARM::VLD3LNdWB_fixed_Asm_32:
6206 case ARM::VLD3LNqWB_fixed_Asm_16:
6207 case ARM::VLD3LNqWB_fixed_Asm_32: {
6208 MCInst TmpInst;
6209 // Shuffle the operands around so the lane index operand is in the
6210 // right place.
6211 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006212 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006213 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6214 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6215 Spacing));
6216 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006217 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006218 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6219 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6220 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6221 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6222 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6224 Spacing));
6225 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006226 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006227 TmpInst.addOperand(Inst.getOperand(1)); // lane
6228 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6229 TmpInst.addOperand(Inst.getOperand(5));
6230 Inst = TmpInst;
6231 return true;
6232 }
6233
Jim Grosbach14952a02012-01-24 18:37:25 +00006234 case ARM::VLD4LNdWB_fixed_Asm_8:
6235 case ARM::VLD4LNdWB_fixed_Asm_16:
6236 case ARM::VLD4LNdWB_fixed_Asm_32:
6237 case ARM::VLD4LNqWB_fixed_Asm_16:
6238 case ARM::VLD4LNqWB_fixed_Asm_32: {
6239 MCInst TmpInst;
6240 // Shuffle the operands around so the lane index operand is in the
6241 // right place.
6242 unsigned Spacing;
6243 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6244 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6245 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6246 Spacing));
6247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 Spacing * 2));
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6250 Spacing * 3));
6251 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6252 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6253 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6254 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6255 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 Spacing));
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6259 Spacing * 2));
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 Spacing * 3));
6262 TmpInst.addOperand(Inst.getOperand(1)); // lane
6263 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6264 TmpInst.addOperand(Inst.getOperand(5));
6265 Inst = TmpInst;
6266 return true;
6267 }
6268
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006269 case ARM::VLD1LNdAsm_8:
6270 case ARM::VLD1LNdAsm_16:
6271 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006272 MCInst TmpInst;
6273 // Shuffle the operands around so the lane index operand is in the
6274 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006275 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006276 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006277 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6278 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6279 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6280 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6281 TmpInst.addOperand(Inst.getOperand(1)); // lane
6282 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6283 TmpInst.addOperand(Inst.getOperand(5));
6284 Inst = TmpInst;
6285 return true;
6286 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006287
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006288 case ARM::VLD2LNdAsm_8:
6289 case ARM::VLD2LNdAsm_16:
6290 case ARM::VLD2LNdAsm_32:
6291 case ARM::VLD2LNqAsm_16:
6292 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006293 MCInst TmpInst;
6294 // Shuffle the operands around so the lane index operand is in the
6295 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006296 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006297 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006298 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006299 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6300 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006301 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6302 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6303 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006306 TmpInst.addOperand(Inst.getOperand(1)); // lane
6307 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6308 TmpInst.addOperand(Inst.getOperand(5));
6309 Inst = TmpInst;
6310 return true;
6311 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006312
6313 case ARM::VLD3LNdAsm_8:
6314 case ARM::VLD3LNdAsm_16:
6315 case ARM::VLD3LNdAsm_32:
6316 case ARM::VLD3LNqAsm_16:
6317 case ARM::VLD3LNqAsm_32: {
6318 MCInst TmpInst;
6319 // Shuffle the operands around so the lane index operand is in the
6320 // right place.
6321 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006322 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006323 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 Spacing));
6326 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006327 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006328 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6329 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6330 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 Spacing));
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006334 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006335 TmpInst.addOperand(Inst.getOperand(1)); // lane
6336 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6337 TmpInst.addOperand(Inst.getOperand(5));
6338 Inst = TmpInst;
6339 return true;
6340 }
6341
Jim Grosbach14952a02012-01-24 18:37:25 +00006342 case ARM::VLD4LNdAsm_8:
6343 case ARM::VLD4LNdAsm_16:
6344 case ARM::VLD4LNdAsm_32:
6345 case ARM::VLD4LNqAsm_16:
6346 case ARM::VLD4LNqAsm_32: {
6347 MCInst TmpInst;
6348 // Shuffle the operands around so the lane index operand is in the
6349 // right place.
6350 unsigned Spacing;
6351 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6352 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6353 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6354 Spacing));
6355 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6356 Spacing * 2));
6357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 Spacing * 3));
6359 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6360 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6361 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing));
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 Spacing * 2));
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 Spacing * 3));
6368 TmpInst.addOperand(Inst.getOperand(1)); // lane
6369 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6370 TmpInst.addOperand(Inst.getOperand(5));
6371 Inst = TmpInst;
6372 return true;
6373 }
6374
Jim Grosbachb78403c2012-01-24 23:47:04 +00006375 // VLD3DUP single 3-element structure to all lanes instructions.
6376 case ARM::VLD3DUPdAsm_8:
6377 case ARM::VLD3DUPdAsm_16:
6378 case ARM::VLD3DUPdAsm_32:
6379 case ARM::VLD3DUPqAsm_8:
6380 case ARM::VLD3DUPqAsm_16:
6381 case ARM::VLD3DUPqAsm_32: {
6382 MCInst TmpInst;
6383 unsigned Spacing;
6384 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6385 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6386 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6387 Spacing));
6388 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6389 Spacing * 2));
6390 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6391 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6392 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6393 TmpInst.addOperand(Inst.getOperand(4));
6394 Inst = TmpInst;
6395 return true;
6396 }
6397
6398 case ARM::VLD3DUPdWB_fixed_Asm_8:
6399 case ARM::VLD3DUPdWB_fixed_Asm_16:
6400 case ARM::VLD3DUPdWB_fixed_Asm_32:
6401 case ARM::VLD3DUPqWB_fixed_Asm_8:
6402 case ARM::VLD3DUPqWB_fixed_Asm_16:
6403 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6404 MCInst TmpInst;
6405 unsigned Spacing;
6406 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6407 TmpInst.addOperand(Inst.getOperand(0)); // 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(Inst.getOperand(1)); // Rn
6413 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6414 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6415 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6416 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6417 TmpInst.addOperand(Inst.getOperand(4));
6418 Inst = TmpInst;
6419 return true;
6420 }
6421
6422 case ARM::VLD3DUPdWB_register_Asm_8:
6423 case ARM::VLD3DUPdWB_register_Asm_16:
6424 case ARM::VLD3DUPdWB_register_Asm_32:
6425 case ARM::VLD3DUPqWB_register_Asm_8:
6426 case ARM::VLD3DUPqWB_register_Asm_16:
6427 case ARM::VLD3DUPqWB_register_Asm_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(1)); // Rn_wb == tied Rn
6438 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6439 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6440 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6441 TmpInst.addOperand(Inst.getOperand(5));
6442 Inst = TmpInst;
6443 return true;
6444 }
6445
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006446 // VLD3 multiple 3-element structure instructions.
6447 case ARM::VLD3dAsm_8:
6448 case ARM::VLD3dAsm_16:
6449 case ARM::VLD3dAsm_32:
6450 case ARM::VLD3qAsm_8:
6451 case ARM::VLD3qAsm_16:
6452 case ARM::VLD3qAsm_32: {
6453 MCInst TmpInst;
6454 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006455 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006456 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 Spacing));
6459 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6460 Spacing * 2));
6461 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6462 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6463 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6464 TmpInst.addOperand(Inst.getOperand(4));
6465 Inst = TmpInst;
6466 return true;
6467 }
6468
6469 case ARM::VLD3dWB_fixed_Asm_8:
6470 case ARM::VLD3dWB_fixed_Asm_16:
6471 case ARM::VLD3dWB_fixed_Asm_32:
6472 case ARM::VLD3qWB_fixed_Asm_8:
6473 case ARM::VLD3qWB_fixed_Asm_16:
6474 case ARM::VLD3qWB_fixed_Asm_32: {
6475 MCInst TmpInst;
6476 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006477 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006478 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 Spacing));
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 Spacing * 2));
6483 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6486 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6487 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6488 TmpInst.addOperand(Inst.getOperand(4));
6489 Inst = TmpInst;
6490 return true;
6491 }
6492
6493 case ARM::VLD3dWB_register_Asm_8:
6494 case ARM::VLD3dWB_register_Asm_16:
6495 case ARM::VLD3dWB_register_Asm_32:
6496 case ARM::VLD3qWB_register_Asm_8:
6497 case ARM::VLD3qWB_register_Asm_16:
6498 case ARM::VLD3qWB_register_Asm_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(1)); // Rn_wb == tied Rn
6509 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6510 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6511 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6512 TmpInst.addOperand(Inst.getOperand(5));
6513 Inst = TmpInst;
6514 return true;
6515 }
6516
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006517 // VLD4DUP single 3-element structure to all lanes instructions.
6518 case ARM::VLD4DUPdAsm_8:
6519 case ARM::VLD4DUPdAsm_16:
6520 case ARM::VLD4DUPdAsm_32:
6521 case ARM::VLD4DUPqAsm_8:
6522 case ARM::VLD4DUPqAsm_16:
6523 case ARM::VLD4DUPqAsm_32: {
6524 MCInst TmpInst;
6525 unsigned Spacing;
6526 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6527 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing));
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing * 2));
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 Spacing * 3));
6534 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6535 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6536 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6537 TmpInst.addOperand(Inst.getOperand(4));
6538 Inst = TmpInst;
6539 return true;
6540 }
6541
6542 case ARM::VLD4DUPdWB_fixed_Asm_8:
6543 case ARM::VLD4DUPdWB_fixed_Asm_16:
6544 case ARM::VLD4DUPdWB_fixed_Asm_32:
6545 case ARM::VLD4DUPqWB_fixed_Asm_8:
6546 case ARM::VLD4DUPqWB_fixed_Asm_16:
6547 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6548 MCInst TmpInst;
6549 unsigned Spacing;
6550 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6551 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 Spacing));
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing * 2));
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 Spacing * 3));
6558 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6559 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6560 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6561 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6562 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6563 TmpInst.addOperand(Inst.getOperand(4));
6564 Inst = TmpInst;
6565 return true;
6566 }
6567
6568 case ARM::VLD4DUPdWB_register_Asm_8:
6569 case ARM::VLD4DUPdWB_register_Asm_16:
6570 case ARM::VLD4DUPdWB_register_Asm_32:
6571 case ARM::VLD4DUPqWB_register_Asm_8:
6572 case ARM::VLD4DUPqWB_register_Asm_16:
6573 case ARM::VLD4DUPqWB_register_Asm_32: {
6574 MCInst TmpInst;
6575 unsigned Spacing;
6576 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6577 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 Spacing));
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 Spacing * 2));
6582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6583 Spacing * 3));
6584 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6585 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6586 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6587 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6588 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6589 TmpInst.addOperand(Inst.getOperand(5));
6590 Inst = TmpInst;
6591 return true;
6592 }
6593
6594 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006595 case ARM::VLD4dAsm_8:
6596 case ARM::VLD4dAsm_16:
6597 case ARM::VLD4dAsm_32:
6598 case ARM::VLD4qAsm_8:
6599 case ARM::VLD4qAsm_16:
6600 case ARM::VLD4qAsm_32: {
6601 MCInst TmpInst;
6602 unsigned Spacing;
6603 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6604 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing));
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 Spacing * 2));
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6610 Spacing * 3));
6611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6612 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6613 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(4));
6615 Inst = TmpInst;
6616 return true;
6617 }
6618
6619 case ARM::VLD4dWB_fixed_Asm_8:
6620 case ARM::VLD4dWB_fixed_Asm_16:
6621 case ARM::VLD4dWB_fixed_Asm_32:
6622 case ARM::VLD4qWB_fixed_Asm_8:
6623 case ARM::VLD4qWB_fixed_Asm_16:
6624 case ARM::VLD4qWB_fixed_Asm_32: {
6625 MCInst TmpInst;
6626 unsigned Spacing;
6627 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6630 Spacing));
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6632 Spacing * 2));
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6634 Spacing * 3));
6635 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6636 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6637 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6638 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6639 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6640 TmpInst.addOperand(Inst.getOperand(4));
6641 Inst = TmpInst;
6642 return true;
6643 }
6644
6645 case ARM::VLD4dWB_register_Asm_8:
6646 case ARM::VLD4dWB_register_Asm_16:
6647 case ARM::VLD4dWB_register_Asm_32:
6648 case ARM::VLD4qWB_register_Asm_8:
6649 case ARM::VLD4qWB_register_Asm_16:
6650 case ARM::VLD4qWB_register_Asm_32: {
6651 MCInst TmpInst;
6652 unsigned Spacing;
6653 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 Spacing));
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6658 Spacing * 2));
6659 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6660 Spacing * 3));
6661 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6662 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6663 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6664 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6665 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6666 TmpInst.addOperand(Inst.getOperand(5));
6667 Inst = TmpInst;
6668 return true;
6669 }
6670
Jim Grosbach1a747242012-01-23 23:45:44 +00006671 // VST3 multiple 3-element structure instructions.
6672 case ARM::VST3dAsm_8:
6673 case ARM::VST3dAsm_16:
6674 case ARM::VST3dAsm_32:
6675 case ARM::VST3qAsm_8:
6676 case ARM::VST3qAsm_16:
6677 case ARM::VST3qAsm_32: {
6678 MCInst TmpInst;
6679 unsigned Spacing;
6680 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6681 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6682 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6683 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6685 Spacing));
6686 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6687 Spacing * 2));
6688 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6689 TmpInst.addOperand(Inst.getOperand(4));
6690 Inst = TmpInst;
6691 return true;
6692 }
6693
6694 case ARM::VST3dWB_fixed_Asm_8:
6695 case ARM::VST3dWB_fixed_Asm_16:
6696 case ARM::VST3dWB_fixed_Asm_32:
6697 case ARM::VST3qWB_fixed_Asm_8:
6698 case ARM::VST3qWB_fixed_Asm_16:
6699 case ARM::VST3qWB_fixed_Asm_32: {
6700 MCInst TmpInst;
6701 unsigned Spacing;
6702 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6703 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6704 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6705 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6706 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6707 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6709 Spacing));
6710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6711 Spacing * 2));
6712 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6713 TmpInst.addOperand(Inst.getOperand(4));
6714 Inst = TmpInst;
6715 return true;
6716 }
6717
6718 case ARM::VST3dWB_register_Asm_8:
6719 case ARM::VST3dWB_register_Asm_16:
6720 case ARM::VST3dWB_register_Asm_32:
6721 case ARM::VST3qWB_register_Asm_8:
6722 case ARM::VST3qWB_register_Asm_16:
6723 case ARM::VST3qWB_register_Asm_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(1)); // Rn_wb == tied Rn
6729 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6730 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6731 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 Spacing));
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 Spacing * 2));
6736 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6737 TmpInst.addOperand(Inst.getOperand(5));
6738 Inst = TmpInst;
6739 return true;
6740 }
6741
Jim Grosbachda70eac2012-01-24 00:58:13 +00006742 // VST4 multiple 3-element structure instructions.
6743 case ARM::VST4dAsm_8:
6744 case ARM::VST4dAsm_16:
6745 case ARM::VST4dAsm_32:
6746 case ARM::VST4qAsm_8:
6747 case ARM::VST4qAsm_16:
6748 case ARM::VST4qAsm_32: {
6749 MCInst TmpInst;
6750 unsigned Spacing;
6751 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6752 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6753 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6754 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 Spacing));
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6758 Spacing * 2));
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6760 Spacing * 3));
6761 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6762 TmpInst.addOperand(Inst.getOperand(4));
6763 Inst = TmpInst;
6764 return true;
6765 }
6766
6767 case ARM::VST4dWB_fixed_Asm_8:
6768 case ARM::VST4dWB_fixed_Asm_16:
6769 case ARM::VST4dWB_fixed_Asm_32:
6770 case ARM::VST4qWB_fixed_Asm_8:
6771 case ARM::VST4qWB_fixed_Asm_16:
6772 case ARM::VST4qWB_fixed_Asm_32: {
6773 MCInst TmpInst;
6774 unsigned Spacing;
6775 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6776 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6777 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6778 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6779 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6780 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6782 Spacing));
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6784 Spacing * 2));
6785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6786 Spacing * 3));
6787 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6788 TmpInst.addOperand(Inst.getOperand(4));
6789 Inst = TmpInst;
6790 return true;
6791 }
6792
6793 case ARM::VST4dWB_register_Asm_8:
6794 case ARM::VST4dWB_register_Asm_16:
6795 case ARM::VST4dWB_register_Asm_32:
6796 case ARM::VST4qWB_register_Asm_8:
6797 case ARM::VST4qWB_register_Asm_16:
6798 case ARM::VST4qWB_register_Asm_32: {
6799 MCInst TmpInst;
6800 unsigned Spacing;
6801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6802 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6803 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6804 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6805 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6808 Spacing));
6809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6810 Spacing * 2));
6811 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6812 Spacing * 3));
6813 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6814 TmpInst.addOperand(Inst.getOperand(5));
6815 Inst = TmpInst;
6816 return true;
6817 }
6818
Jim Grosbachad66de12012-04-11 00:15:16 +00006819 // Handle encoding choice for the shift-immediate instructions.
6820 case ARM::t2LSLri:
6821 case ARM::t2LSRri:
6822 case ARM::t2ASRri: {
6823 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6824 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6825 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6826 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6827 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6828 unsigned NewOpc;
6829 switch (Inst.getOpcode()) {
6830 default: llvm_unreachable("unexpected opcode");
6831 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6832 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6833 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6834 }
6835 // The Thumb1 operands aren't in the same order. Awesome, eh?
6836 MCInst TmpInst;
6837 TmpInst.setOpcode(NewOpc);
6838 TmpInst.addOperand(Inst.getOperand(0));
6839 TmpInst.addOperand(Inst.getOperand(5));
6840 TmpInst.addOperand(Inst.getOperand(1));
6841 TmpInst.addOperand(Inst.getOperand(2));
6842 TmpInst.addOperand(Inst.getOperand(3));
6843 TmpInst.addOperand(Inst.getOperand(4));
6844 Inst = TmpInst;
6845 return true;
6846 }
6847 return false;
6848 }
6849
Jim Grosbach485e5622011-12-13 22:45:11 +00006850 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006851 case ARM::t2MOVsr:
6852 case ARM::t2MOVSsr: {
6853 // Which instruction to expand to depends on the CCOut operand and
6854 // whether we're in an IT block if the register operands are low
6855 // registers.
6856 bool isNarrow = false;
6857 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6858 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6859 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6860 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6861 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6862 isNarrow = true;
6863 MCInst TmpInst;
6864 unsigned newOpc;
6865 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6866 default: llvm_unreachable("unexpected opcode!");
6867 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6868 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6869 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6870 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6871 }
6872 TmpInst.setOpcode(newOpc);
6873 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6874 if (isNarrow)
6875 TmpInst.addOperand(MCOperand::CreateReg(
6876 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6877 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6878 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6879 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6880 TmpInst.addOperand(Inst.getOperand(5));
6881 if (!isNarrow)
6882 TmpInst.addOperand(MCOperand::CreateReg(
6883 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6884 Inst = TmpInst;
6885 return true;
6886 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006887 case ARM::t2MOVsi:
6888 case ARM::t2MOVSsi: {
6889 // Which instruction to expand to depends on the CCOut operand and
6890 // whether we're in an IT block if the register operands are low
6891 // registers.
6892 bool isNarrow = false;
6893 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6894 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6895 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6896 isNarrow = true;
6897 MCInst TmpInst;
6898 unsigned newOpc;
6899 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6900 default: llvm_unreachable("unexpected opcode!");
6901 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6902 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6903 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6904 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006905 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006906 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006907 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6908 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006909 TmpInst.setOpcode(newOpc);
6910 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6911 if (isNarrow)
6912 TmpInst.addOperand(MCOperand::CreateReg(
6913 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6914 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006915 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006916 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006917 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6918 TmpInst.addOperand(Inst.getOperand(4));
6919 if (!isNarrow)
6920 TmpInst.addOperand(MCOperand::CreateReg(
6921 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6922 Inst = TmpInst;
6923 return true;
6924 }
6925 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006926 case ARM::ASRr:
6927 case ARM::LSRr:
6928 case ARM::LSLr:
6929 case ARM::RORr: {
6930 ARM_AM::ShiftOpc ShiftTy;
6931 switch(Inst.getOpcode()) {
6932 default: llvm_unreachable("unexpected opcode!");
6933 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6934 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6935 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6936 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6937 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006938 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6939 MCInst TmpInst;
6940 TmpInst.setOpcode(ARM::MOVsr);
6941 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6942 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6943 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6944 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6945 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6946 TmpInst.addOperand(Inst.getOperand(4));
6947 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6948 Inst = TmpInst;
6949 return true;
6950 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006951 case ARM::ASRi:
6952 case ARM::LSRi:
6953 case ARM::LSLi:
6954 case ARM::RORi: {
6955 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006956 switch(Inst.getOpcode()) {
6957 default: llvm_unreachable("unexpected opcode!");
6958 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6959 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6960 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6961 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6962 }
6963 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006964 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006965 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006966 // A shift by 32 should be encoded as 0 when permitted
6967 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6968 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006969 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006970 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006971 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006972 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6973 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006974 if (Opc == ARM::MOVsi)
6975 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006976 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6977 TmpInst.addOperand(Inst.getOperand(4));
6978 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6979 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006980 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006981 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006982 case ARM::RRXi: {
6983 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6984 MCInst TmpInst;
6985 TmpInst.setOpcode(ARM::MOVsi);
6986 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6987 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6988 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6989 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6990 TmpInst.addOperand(Inst.getOperand(3));
6991 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6992 Inst = TmpInst;
6993 return true;
6994 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006995 case ARM::t2LDMIA_UPD: {
6996 // If this is a load of a single register, then we should use
6997 // a post-indexed LDR instruction instead, per the ARM ARM.
6998 if (Inst.getNumOperands() != 5)
6999 return false;
7000 MCInst TmpInst;
7001 TmpInst.setOpcode(ARM::t2LDR_POST);
7002 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7003 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7004 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7005 TmpInst.addOperand(MCOperand::CreateImm(4));
7006 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7007 TmpInst.addOperand(Inst.getOperand(3));
7008 Inst = TmpInst;
7009 return true;
7010 }
7011 case ARM::t2STMDB_UPD: {
7012 // If this is a store of a single register, then we should use
7013 // a pre-indexed STR instruction instead, per the ARM ARM.
7014 if (Inst.getNumOperands() != 5)
7015 return false;
7016 MCInst TmpInst;
7017 TmpInst.setOpcode(ARM::t2STR_PRE);
7018 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7019 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7020 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7021 TmpInst.addOperand(MCOperand::CreateImm(-4));
7022 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7023 TmpInst.addOperand(Inst.getOperand(3));
7024 Inst = TmpInst;
7025 return true;
7026 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007027 case ARM::LDMIA_UPD:
7028 // If this is a load of a single register via a 'pop', then we should use
7029 // a post-indexed LDR instruction instead, per the ARM ARM.
7030 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7031 Inst.getNumOperands() == 5) {
7032 MCInst TmpInst;
7033 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7034 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7035 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7036 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7037 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7038 TmpInst.addOperand(MCOperand::CreateImm(4));
7039 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7040 TmpInst.addOperand(Inst.getOperand(3));
7041 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007042 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007043 }
7044 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007045 case ARM::STMDB_UPD:
7046 // If this is a store of a single register via a 'push', then we should use
7047 // a pre-indexed STR instruction instead, per the ARM ARM.
7048 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7049 Inst.getNumOperands() == 5) {
7050 MCInst TmpInst;
7051 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7052 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7053 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7054 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7055 TmpInst.addOperand(MCOperand::CreateImm(-4));
7056 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7057 TmpInst.addOperand(Inst.getOperand(3));
7058 Inst = TmpInst;
7059 }
7060 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007061 case ARM::t2ADDri12:
7062 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7063 // mnemonic was used (not "addw"), encoding T3 is preferred.
7064 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7065 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7066 break;
7067 Inst.setOpcode(ARM::t2ADDri);
7068 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7069 break;
7070 case ARM::t2SUBri12:
7071 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7072 // mnemonic was used (not "subw"), encoding T3 is preferred.
7073 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7074 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7075 break;
7076 Inst.setOpcode(ARM::t2SUBri);
7077 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7078 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007079 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007080 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007081 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7082 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7083 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007084 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007085 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007086 return true;
7087 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007088 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007089 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007090 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007091 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7092 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7093 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007094 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007095 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007096 return true;
7097 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007098 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007099 case ARM::t2ADDri:
7100 case ARM::t2SUBri: {
7101 // If the destination and first source operand are the same, and
7102 // the flags are compatible with the current IT status, use encoding T2
7103 // instead of T3. For compatibility with the system 'as'. Make sure the
7104 // wide encoding wasn't explicit.
7105 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007106 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007107 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7108 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7109 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7110 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7111 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7112 break;
7113 MCInst TmpInst;
7114 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7115 ARM::tADDi8 : ARM::tSUBi8);
7116 TmpInst.addOperand(Inst.getOperand(0));
7117 TmpInst.addOperand(Inst.getOperand(5));
7118 TmpInst.addOperand(Inst.getOperand(0));
7119 TmpInst.addOperand(Inst.getOperand(2));
7120 TmpInst.addOperand(Inst.getOperand(3));
7121 TmpInst.addOperand(Inst.getOperand(4));
7122 Inst = TmpInst;
7123 return true;
7124 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007125 case ARM::t2ADDrr: {
7126 // If the destination and first source operand are the same, and
7127 // there's no setting of the flags, use encoding T2 instead of T3.
7128 // Note that this is only for ADD, not SUB. This mirrors the system
7129 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7130 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7131 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007132 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7133 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007134 break;
7135 MCInst TmpInst;
7136 TmpInst.setOpcode(ARM::tADDhirr);
7137 TmpInst.addOperand(Inst.getOperand(0));
7138 TmpInst.addOperand(Inst.getOperand(0));
7139 TmpInst.addOperand(Inst.getOperand(2));
7140 TmpInst.addOperand(Inst.getOperand(3));
7141 TmpInst.addOperand(Inst.getOperand(4));
7142 Inst = TmpInst;
7143 return true;
7144 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007145 case ARM::tADDrSP: {
7146 // If the non-SP source operand and the destination operand are not the
7147 // same, we need to use the 32-bit encoding if it's available.
7148 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7149 Inst.setOpcode(ARM::t2ADDrr);
7150 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7151 return true;
7152 }
7153 break;
7154 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007155 case ARM::tB:
7156 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007157 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007158 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007159 return true;
7160 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007161 break;
7162 case ARM::t2B:
7163 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007164 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007165 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007166 return true;
7167 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007168 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007169 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007170 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007171 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007172 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007173 return true;
7174 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007175 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007176 case ARM::tBcc:
7177 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007178 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007179 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007180 return true;
7181 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007182 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007183 case ARM::tLDMIA: {
7184 // If the register list contains any high registers, or if the writeback
7185 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7186 // instead if we're in Thumb2. Otherwise, this should have generated
7187 // an error in validateInstruction().
7188 unsigned Rn = Inst.getOperand(0).getReg();
7189 bool hasWritebackToken =
7190 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7191 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7192 bool listContainsBase;
7193 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7194 (!listContainsBase && !hasWritebackToken) ||
7195 (listContainsBase && hasWritebackToken)) {
7196 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7197 assert (isThumbTwo());
7198 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7199 // If we're switching to the updating version, we need to insert
7200 // the writeback tied operand.
7201 if (hasWritebackToken)
7202 Inst.insert(Inst.begin(),
7203 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007204 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007205 }
7206 break;
7207 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007208 case ARM::tSTMIA_UPD: {
7209 // If the register list contains any high registers, we need to use
7210 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7211 // should have generated an error in validateInstruction().
7212 unsigned Rn = Inst.getOperand(0).getReg();
7213 bool listContainsBase;
7214 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7215 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7216 assert (isThumbTwo());
7217 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007218 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007219 }
7220 break;
7221 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007222 case ARM::tPOP: {
7223 bool listContainsBase;
7224 // If the register list contains any high registers, we need to use
7225 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7226 // should have generated an error in validateInstruction().
7227 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007228 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007229 assert (isThumbTwo());
7230 Inst.setOpcode(ARM::t2LDMIA_UPD);
7231 // Add the base register and writeback operands.
7232 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7233 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007234 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007235 }
7236 case ARM::tPUSH: {
7237 bool listContainsBase;
7238 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007239 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007240 assert (isThumbTwo());
7241 Inst.setOpcode(ARM::t2STMDB_UPD);
7242 // Add the base register and writeback operands.
7243 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7244 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007245 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007246 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007247 case ARM::t2MOVi: {
7248 // If we can use the 16-bit encoding and the user didn't explicitly
7249 // request the 32-bit variant, transform it here.
7250 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007251 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007252 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7253 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7254 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007255 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7256 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7257 // The operands aren't in the same order for tMOVi8...
7258 MCInst TmpInst;
7259 TmpInst.setOpcode(ARM::tMOVi8);
7260 TmpInst.addOperand(Inst.getOperand(0));
7261 TmpInst.addOperand(Inst.getOperand(4));
7262 TmpInst.addOperand(Inst.getOperand(1));
7263 TmpInst.addOperand(Inst.getOperand(2));
7264 TmpInst.addOperand(Inst.getOperand(3));
7265 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007266 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007267 }
7268 break;
7269 }
7270 case ARM::t2MOVr: {
7271 // If we can use the 16-bit encoding and the user didn't explicitly
7272 // request the 32-bit variant, transform it here.
7273 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7274 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7275 Inst.getOperand(2).getImm() == ARMCC::AL &&
7276 Inst.getOperand(4).getReg() == ARM::CPSR &&
7277 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7278 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7279 // The operands aren't the same for tMOV[S]r... (no cc_out)
7280 MCInst TmpInst;
7281 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7282 TmpInst.addOperand(Inst.getOperand(0));
7283 TmpInst.addOperand(Inst.getOperand(1));
7284 TmpInst.addOperand(Inst.getOperand(2));
7285 TmpInst.addOperand(Inst.getOperand(3));
7286 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007287 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007288 }
7289 break;
7290 }
Jim Grosbach82213192011-09-19 20:29:33 +00007291 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007292 case ARM::t2SXTB:
7293 case ARM::t2UXTH:
7294 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007295 // If we can use the 16-bit encoding and the user didn't explicitly
7296 // request the 32-bit variant, transform it here.
7297 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7298 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7299 Inst.getOperand(2).getImm() == 0 &&
7300 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7301 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007302 unsigned NewOpc;
7303 switch (Inst.getOpcode()) {
7304 default: llvm_unreachable("Illegal opcode!");
7305 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7306 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7307 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7308 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7309 }
Jim Grosbach82213192011-09-19 20:29:33 +00007310 // The operands aren't the same for thumb1 (no rotate operand).
7311 MCInst TmpInst;
7312 TmpInst.setOpcode(NewOpc);
7313 TmpInst.addOperand(Inst.getOperand(0));
7314 TmpInst.addOperand(Inst.getOperand(1));
7315 TmpInst.addOperand(Inst.getOperand(3));
7316 TmpInst.addOperand(Inst.getOperand(4));
7317 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007318 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007319 }
7320 break;
7321 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007322 case ARM::MOVsi: {
7323 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007324 // rrx shifts and asr/lsr of #32 is encoded as 0
7325 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7326 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007327 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7328 // Shifting by zero is accepted as a vanilla 'MOVr'
7329 MCInst TmpInst;
7330 TmpInst.setOpcode(ARM::MOVr);
7331 TmpInst.addOperand(Inst.getOperand(0));
7332 TmpInst.addOperand(Inst.getOperand(1));
7333 TmpInst.addOperand(Inst.getOperand(3));
7334 TmpInst.addOperand(Inst.getOperand(4));
7335 TmpInst.addOperand(Inst.getOperand(5));
7336 Inst = TmpInst;
7337 return true;
7338 }
7339 return false;
7340 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007341 case ARM::ANDrsi:
7342 case ARM::ORRrsi:
7343 case ARM::EORrsi:
7344 case ARM::BICrsi:
7345 case ARM::SUBrsi:
7346 case ARM::ADDrsi: {
7347 unsigned newOpc;
7348 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7349 if (SOpc == ARM_AM::rrx) return false;
7350 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007351 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007352 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7353 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7354 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7355 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7356 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7357 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7358 }
7359 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007360 // The exception is for right shifts, where 0 == 32
7361 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7362 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007363 MCInst TmpInst;
7364 TmpInst.setOpcode(newOpc);
7365 TmpInst.addOperand(Inst.getOperand(0));
7366 TmpInst.addOperand(Inst.getOperand(1));
7367 TmpInst.addOperand(Inst.getOperand(2));
7368 TmpInst.addOperand(Inst.getOperand(4));
7369 TmpInst.addOperand(Inst.getOperand(5));
7370 TmpInst.addOperand(Inst.getOperand(6));
7371 Inst = TmpInst;
7372 return true;
7373 }
7374 return false;
7375 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007376 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007377 case ARM::t2IT: {
7378 // The mask bits for all but the first condition are represented as
7379 // the low bit of the condition code value implies 't'. We currently
7380 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007381 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007382 MCOperand &MO = Inst.getOperand(1);
7383 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007384 unsigned OrigMask = Mask;
7385 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007386 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007387 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7388 for (unsigned i = 3; i != TZ; --i)
7389 Mask ^= 1 << i;
Richard Bartonf435b092012-04-27 08:42:59 +00007390 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007391 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007392
7393 // Set up the IT block state according to the IT instruction we just
7394 // matched.
7395 assert(!inITBlock() && "nested IT blocks?!");
7396 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7397 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7398 ITState.CurPosition = 0;
7399 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007400 break;
7401 }
Richard Bartona39625e2012-07-09 16:12:24 +00007402 case ARM::t2LSLrr:
7403 case ARM::t2LSRrr:
7404 case ARM::t2ASRrr:
7405 case ARM::t2SBCrr:
7406 case ARM::t2RORrr:
7407 case ARM::t2BICrr:
7408 {
Richard Bartond5660372012-07-09 16:14:28 +00007409 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007410 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7411 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7412 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007413 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7414 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007415 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7416 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7417 unsigned NewOpc;
7418 switch (Inst.getOpcode()) {
7419 default: llvm_unreachable("unexpected opcode");
7420 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7421 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7422 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7423 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7424 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7425 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7426 }
7427 MCInst TmpInst;
7428 TmpInst.setOpcode(NewOpc);
7429 TmpInst.addOperand(Inst.getOperand(0));
7430 TmpInst.addOperand(Inst.getOperand(5));
7431 TmpInst.addOperand(Inst.getOperand(1));
7432 TmpInst.addOperand(Inst.getOperand(2));
7433 TmpInst.addOperand(Inst.getOperand(3));
7434 TmpInst.addOperand(Inst.getOperand(4));
7435 Inst = TmpInst;
7436 return true;
7437 }
7438 return false;
7439 }
7440 case ARM::t2ANDrr:
7441 case ARM::t2EORrr:
7442 case ARM::t2ADCrr:
7443 case ARM::t2ORRrr:
7444 {
Richard Bartond5660372012-07-09 16:14:28 +00007445 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007446 // These instructions are special in that they are commutable, so shorter encodings
7447 // are available more often.
7448 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7449 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7450 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7451 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007452 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7453 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007454 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7455 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7456 unsigned NewOpc;
7457 switch (Inst.getOpcode()) {
7458 default: llvm_unreachable("unexpected opcode");
7459 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7460 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7461 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7462 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7463 }
7464 MCInst TmpInst;
7465 TmpInst.setOpcode(NewOpc);
7466 TmpInst.addOperand(Inst.getOperand(0));
7467 TmpInst.addOperand(Inst.getOperand(5));
7468 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7469 TmpInst.addOperand(Inst.getOperand(1));
7470 TmpInst.addOperand(Inst.getOperand(2));
7471 } else {
7472 TmpInst.addOperand(Inst.getOperand(2));
7473 TmpInst.addOperand(Inst.getOperand(1));
7474 }
7475 TmpInst.addOperand(Inst.getOperand(3));
7476 TmpInst.addOperand(Inst.getOperand(4));
7477 Inst = TmpInst;
7478 return true;
7479 }
7480 return false;
7481 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007482 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007483 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007484}
7485
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007486unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7487 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7488 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007489 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007490 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007491 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7492 assert(MCID.hasOptionalDef() &&
7493 "optionally flag setting instruction missing optional def operand");
7494 assert(MCID.NumOperands == Inst.getNumOperands() &&
7495 "operand count mismatch!");
7496 // Find the optional-def operand (cc_out).
7497 unsigned OpNo;
7498 for (OpNo = 0;
7499 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7500 ++OpNo)
7501 ;
7502 // If we're parsing Thumb1, reject it completely.
7503 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7504 return Match_MnemonicFail;
7505 // If we're parsing Thumb2, which form is legal depends on whether we're
7506 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007507 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7508 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007509 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007510 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7511 inITBlock())
7512 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007513 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007514 // Some high-register supporting Thumb1 encodings only allow both registers
7515 // to be from r0-r7 when in Thumb2.
7516 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7517 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7518 isARMLowRegister(Inst.getOperand(2).getReg()))
7519 return Match_RequiresThumb2;
7520 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007521 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007522 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7523 isARMLowRegister(Inst.getOperand(1).getReg()))
7524 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007525 return Match_Success;
7526}
7527
Jim Grosbach5117ef72012-04-24 22:40:08 +00007528static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007529bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007530MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007531 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007532 MCStreamer &Out, unsigned &ErrorInfo,
7533 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007534 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007535 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007536
Chad Rosier2f480a82012-10-12 22:53:36 +00007537 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007538 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007539 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007540 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007541 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007542 // Context sensitive operand constraints aren't handled by the matcher,
7543 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007544 if (validateInstruction(Inst, Operands)) {
7545 // Still progress the IT block, otherwise one wrong condition causes
7546 // nasty cascading errors.
7547 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007548 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007549 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007550
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007551 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007552 // encoding is selected. Loop on it while changes happen so the
7553 // individual transformations can chain off each other. E.g.,
7554 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7555 while (processInstruction(Inst, Operands))
7556 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007557
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007558 // Only move forward at the very end so that everything in validate
7559 // and process gets a consistent answer about whether we're in an IT
7560 // block.
7561 forwardITPosition();
7562
Jim Grosbach82f76d12012-01-25 19:52:01 +00007563 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7564 // doesn't actually encode.
7565 if (Inst.getOpcode() == ARM::ITasm)
7566 return false;
7567
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007568 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007569 Out.EmitInstruction(Inst);
7570 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007571 case Match_MissingFeature: {
7572 assert(ErrorInfo && "Unknown missing feature!");
7573 // Special case the error message for the very common case where only
7574 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7575 std::string Msg = "instruction requires:";
7576 unsigned Mask = 1;
7577 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7578 if (ErrorInfo & Mask) {
7579 Msg += " ";
7580 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7581 }
7582 Mask <<= 1;
7583 }
7584 return Error(IDLoc, Msg);
7585 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007586 case Match_InvalidOperand: {
7587 SMLoc ErrorLoc = IDLoc;
7588 if (ErrorInfo != ~0U) {
7589 if (ErrorInfo >= Operands.size())
7590 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007591
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007592 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7593 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7594 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007595
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007596 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007597 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007598 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007599 return Error(IDLoc, "invalid instruction",
7600 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007601 case Match_RequiresNotITBlock:
7602 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007603 case Match_RequiresITBlock:
7604 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007605 case Match_RequiresV6:
7606 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7607 case Match_RequiresThumb2:
7608 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007609 case Match_ImmRange0_15: {
7610 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7611 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7612 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7613 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007614 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007615
Eric Christopher91d7b902010-10-29 09:26:59 +00007616 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007617}
7618
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007619/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007620bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7621 StringRef IDVal = DirectiveID.getIdentifier();
7622 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007623 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007624 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007625 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007626 else if (IDVal == ".arm")
7627 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007628 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007629 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007630 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007631 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007632 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007633 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007634 else if (IDVal == ".unreq")
7635 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007636 else if (IDVal == ".arch")
7637 return parseDirectiveArch(DirectiveID.getLoc());
7638 else if (IDVal == ".eabi_attribute")
7639 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007640 return true;
7641}
7642
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007643/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007644/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007645bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007646 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7647 for (;;) {
7648 const MCExpr *Value;
7649 if (getParser().ParseExpression(Value))
7650 return true;
7651
Eric Christopherbf7bc492013-01-09 03:52:05 +00007652 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007653
7654 if (getLexer().is(AsmToken::EndOfStatement))
7655 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007656
Kevin Enderbyccab3172009-09-15 00:27:25 +00007657 // FIXME: Improve diagnostic.
7658 if (getLexer().isNot(AsmToken::Comma))
7659 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007660 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007661 }
7662 }
7663
Sean Callanana83fd7d2010-01-19 20:27:46 +00007664 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007665 return false;
7666}
7667
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007668/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007669/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007670bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007671 if (getLexer().isNot(AsmToken::EndOfStatement))
7672 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007673 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007674
Jim Grosbach7f882392011-12-07 18:04:19 +00007675 if (!isThumb())
7676 SwitchMode();
7677 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7678 return false;
7679}
7680
7681/// parseDirectiveARM
7682/// ::= .arm
7683bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7684 if (getLexer().isNot(AsmToken::EndOfStatement))
7685 return Error(L, "unexpected token in directive");
7686 Parser.Lex();
7687
7688 if (isThumb())
7689 SwitchMode();
7690 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007691 return false;
7692}
7693
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007694/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007695/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007696bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007697 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7698 bool isMachO = MAI.hasSubsectionsViaSymbols();
7699 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007700 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007701
Jim Grosbach1152cc02011-12-21 22:30:16 +00007702 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007703 // ELF doesn't
7704 if (isMachO) {
7705 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007706 if (Tok.isNot(AsmToken::EndOfStatement)) {
7707 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7708 return Error(L, "unexpected token in .thumb_func directive");
7709 Name = Tok.getIdentifier();
7710 Parser.Lex(); // Consume the identifier token.
7711 needFuncName = false;
7712 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007713 }
7714
Jim Grosbach1152cc02011-12-21 22:30:16 +00007715 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007716 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007717
7718 // Eat the end of statement and any blank lines that follow.
7719 while (getLexer().is(AsmToken::EndOfStatement))
7720 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007721
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007722 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007723 // We really should be checking the next symbol definition even if there's
7724 // stuff in between.
7725 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007726 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007727 }
7728
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007729 // Mark symbol as a thumb symbol.
7730 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7731 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007732 return false;
7733}
7734
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007735/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007736/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007737bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007738 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007739 if (Tok.isNot(AsmToken::Identifier))
7740 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007741 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007742 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007743 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007744 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007745 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007746 else
7747 return Error(L, "unrecognized syntax mode in .syntax directive");
7748
7749 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007750 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007751 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007752
7753 // TODO tell the MC streamer the mode
7754 // getParser().getStreamer().Emit???();
7755 return false;
7756}
7757
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007758/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007759/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007760bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007761 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007762 if (Tok.isNot(AsmToken::Integer))
7763 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007764 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007765 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007766 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007767 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007768 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007769 else
7770 return Error(L, "invalid operand to .code directive");
7771
7772 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007773 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007774 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007775
Evan Cheng284b4672011-07-08 22:36:29 +00007776 if (Val == 16) {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007777 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007778 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007779 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007780 } else {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007781 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007782 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007783 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007784 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007785
Kevin Enderby146dcf22009-10-15 20:48:48 +00007786 return false;
7787}
7788
Jim Grosbachab5830e2011-12-14 02:16:11 +00007789/// parseDirectiveReq
7790/// ::= name .req registername
7791bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7792 Parser.Lex(); // Eat the '.req' token.
7793 unsigned Reg;
7794 SMLoc SRegLoc, ERegLoc;
7795 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7796 Parser.EatToEndOfStatement();
7797 return Error(SRegLoc, "register name expected");
7798 }
7799
7800 // Shouldn't be anything else.
7801 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7802 Parser.EatToEndOfStatement();
7803 return Error(Parser.getTok().getLoc(),
7804 "unexpected input in .req directive.");
7805 }
7806
7807 Parser.Lex(); // Consume the EndOfStatement
7808
7809 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7810 return Error(SRegLoc, "redefinition of '" + Name +
7811 "' does not match original.");
7812
7813 return false;
7814}
7815
7816/// parseDirectiveUneq
7817/// ::= .unreq registername
7818bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7819 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7820 Parser.EatToEndOfStatement();
7821 return Error(L, "unexpected input in .unreq directive.");
7822 }
7823 RegisterReqs.erase(Parser.getTok().getIdentifier());
7824 Parser.Lex(); // Eat the identifier.
7825 return false;
7826}
7827
Jason W Kim135d2442011-12-20 17:38:12 +00007828/// parseDirectiveArch
7829/// ::= .arch token
7830bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7831 return true;
7832}
7833
7834/// parseDirectiveEabiAttr
7835/// ::= .eabi_attribute int, int
7836bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7837 return true;
7838}
7839
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007840/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007841extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007842 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7843 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007844}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007845
Chris Lattner3e4582a2010-09-06 19:11:01 +00007846#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00007847#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00007848#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007849#include "ARMGenAsmMatcher.inc"