blob: 3174e9ae46e3e4145ab3ed42b9ce5a07e1b9720c [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Jim Grosbachab5830e2011-12-14 02:16:11 +000052 // Map of register aliases registers via the .req directive.
53 StringMap<unsigned> RegisterReqs;
54
Jim Grosbached16ec42011-08-29 22:24:09 +000055 struct {
56 ARMCC::CondCodes Cond; // Condition for IT block.
57 unsigned Mask:4; // Condition mask for instructions.
58 // Starting at first 1 (from lsb).
59 // '1' condition as indicated in IT.
60 // '0' inverse of condition (else).
61 // Count of instructions in IT block is
62 // 4 - trailingzeroes(mask)
63
64 bool FirstCond; // Explicit flag for when we're parsing the
65 // First instruction in the IT block. It's
66 // implied in the mask, so needs special
67 // handling.
68
69 unsigned CurPosition; // Current position in parsing of IT
70 // block. In range [0,3]. Initialized
71 // according to count of instructions in block.
72 // ~0U if no active IT block.
73 } ITState;
74 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000075 void forwardITPosition() {
76 if (!inITBlock()) return;
77 // Move to the next instruction in the IT block, if there is one. If not,
78 // mark the block as done.
79 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
80 if (++ITState.CurPosition == 5 - TZ)
81 ITState.CurPosition = ~0U; // Done with the IT block after this.
82 }
Jim Grosbached16ec42011-08-29 22:24:09 +000083
84
Kevin Enderbyccab3172009-09-15 00:27:25 +000085 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +000086 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
87
Benjamin Kramer673824b2012-04-15 17:04:27 +000088 bool Warning(SMLoc L, const Twine &Msg,
89 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
90 return Parser.Warning(L, Msg, Ranges);
91 }
92 bool Error(SMLoc L, const Twine &Msg,
93 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
94 return Parser.Error(L, Msg, Ranges);
95 }
Kevin Enderbyccab3172009-09-15 00:27:25 +000096
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000097 int tryParseRegister();
98 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +000099 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000100 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000101 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000102 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
103 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000104 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
105 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000106 bool parseDirectiveWord(unsigned Size, SMLoc L);
107 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000108 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000109 bool parseDirectiveThumbFunc(SMLoc L);
110 bool parseDirectiveCode(SMLoc L);
111 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000112 bool parseDirectiveReq(StringRef Name, SMLoc L);
113 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000114 bool parseDirectiveArch(SMLoc L);
115 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000116
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000117 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000118 bool &CarrySetting, unsigned &ProcessorIMod,
119 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000121 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000122
Evan Cheng4d1ca962011-07-08 01:53:10 +0000123 bool isThumb() const {
124 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000125 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000126 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000127 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000129 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000130 bool isThumbTwo() const {
131 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
132 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000133 bool hasV6Ops() const {
134 return STI.getFeatureBits() & ARM::HasV6Ops;
135 }
James Molloy21efa7d2011-09-28 14:21:38 +0000136 bool hasV7Ops() const {
137 return STI.getFeatureBits() & ARM::HasV7Ops;
138 }
Evan Cheng284b4672011-07-08 22:36:29 +0000139 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000140 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
141 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000142 }
James Molloy21efa7d2011-09-28 14:21:38 +0000143 bool isMClass() const {
144 return STI.getFeatureBits() & ARM::FeatureMClass;
145 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000146
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000147 /// @name Auto-generated Match Functions
148 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000149
Chris Lattner3e4582a2010-09-06 19:11:01 +0000150#define GET_ASSEMBLER_HEADER
151#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000152
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000153 /// }
154
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000155 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000156 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000157 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000158 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000159 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000160 OperandMatchResultTy parseCoprocOptionOperand(
161 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000162 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000163 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000164 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000165 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000166 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000167 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000168 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
169 StringRef Op, int Low, int High);
170 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "lsl", 0, 31);
172 }
173 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
174 return parsePKHImm(O, "asr", 1, 32);
175 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000176 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000177 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000178 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000179 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000180 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000181 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000182 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000183 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000184 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
185 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000186
187 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000188 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
189 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
190 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000192 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000194 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000196 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000198 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000200 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000202 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000203 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000204 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000205 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000206 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000207 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000208 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000209 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000210 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000212 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
213 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
214 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000216 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000218 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000220 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000224 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000226 bool validateInstruction(MCInst &Inst,
227 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000228 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000229 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000230 bool shouldOmitCCOutOperand(StringRef Mnemonic,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000232
Kevin Enderbyccab3172009-09-15 00:27:25 +0000233public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000234 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000235 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000236 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000237 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000238 Match_RequiresThumb2,
239#define GET_OPERAND_DIAGNOSTIC_TYPES
240#include "ARMGenAsmMatcher.inc"
241
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000242 };
243
Evan Cheng91111d22011-07-09 05:47:46 +0000244 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng11424442011-07-26 00:24:13 +0000245 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000247
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000248 // Cache the MCRegisterInfo.
249 MRI = &getContext().getRegisterInfo();
250
Evan Cheng4d1ca962011-07-08 01:53:10 +0000251 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000252 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000253
254 // Not in an ITBlock to start with.
255 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000256
257 // Set ELF header flags.
258 // FIXME: This should eventually end up somewhere else where more
259 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000260 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
261 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
262 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000263 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000264
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000265 // Implementation of the MCTargetAsmParser interface:
266 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000267 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
268 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000269 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000270 bool ParseDirective(AsmToken DirectiveID);
271
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000272 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000273 unsigned checkTargetMatchPredicate(MCInst &Inst);
274
Chad Rosier49963552012-10-13 00:26:04 +0000275 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000276 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000277 MCStreamer &Out, unsigned &ErrorInfo,
278 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000279};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000280} // end anonymous namespace
281
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000282namespace {
283
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000284/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000285/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000286class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000287 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000288 k_CondCode,
289 k_CCOut,
290 k_ITCondMask,
291 k_CoprocNum,
292 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000293 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000294 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000295 k_MemBarrierOpt,
296 k_Memory,
297 k_PostIndexRegister,
298 k_MSRMask,
299 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000300 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000301 k_Register,
302 k_RegisterList,
303 k_DPRRegisterList,
304 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000305 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000306 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000307 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000308 k_ShiftedRegister,
309 k_ShiftedImmediate,
310 k_ShifterImmediate,
311 k_RotateImmediate,
312 k_BitfieldDescriptor,
313 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000314 } Kind;
315
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000316 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000317 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000318
319 union {
320 struct {
Daniel Dunbard8042b72010-08-11 06:36:53 +0000321 ARMCC::CondCodes Val;
322 } CC;
323
324 struct {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000325 unsigned Val;
326 } Cop;
327
328 struct {
Jim Grosbach48399582011-10-12 17:34:41 +0000329 unsigned Val;
330 } CoprocOption;
331
332 struct {
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000333 unsigned Mask:4;
334 } ITMask;
335
336 struct {
337 ARM_MB::MemBOpt Val;
338 } MBOpt;
339
340 struct {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000341 ARM_PROC::IFlags Val;
342 } IFlags;
343
344 struct {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000345 unsigned Val;
346 } MMask;
347
348 struct {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000349 const char *Data;
350 unsigned Length;
351 } Tok;
352
353 struct {
354 unsigned RegNum;
355 } Reg;
356
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000357 // A vector register list is a sequential list of 1 to 4 registers.
358 struct {
359 unsigned RegNum;
360 unsigned Count;
Jim Grosbach04945c42011-12-02 00:35:16 +0000361 unsigned LaneIndex;
Jim Grosbach2f50e922011-12-15 21:44:33 +0000362 bool isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000363 } VectorList;
364
Bill Wendlingb884a8e2010-11-06 22:19:43 +0000365 struct {
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000366 unsigned Val;
367 } VectorIndex;
368
369 struct {
Kevin Enderbyf5079942009-10-13 22:19:02 +0000370 const MCExpr *Val;
371 } Imm;
Jim Grosbach624bcc72010-10-29 14:46:02 +0000372
Daniel Dunbar2be732a2011-01-10 15:26:21 +0000373 /// Combined record for all forms of ARM address expressions.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000374 struct {
375 unsigned BaseRegNum;
Jim Grosbachd3595712011-08-03 23:50:40 +0000376 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
377 // was specified.
378 const MCConstantExpr *OffsetImm; // Offset immediate value
379 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
380 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbacha95ec992011-10-11 17:29:55 +0000381 unsigned ShiftImm; // shift for OffsetReg.
382 unsigned Alignment; // 0 = no alignment specified
Jim Grosbachcef98cd2011-12-19 18:31:43 +0000383 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbachd3595712011-08-03 23:50:40 +0000384 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbach871dff72011-10-11 15:59:20 +0000385 } Memory;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000386
387 struct {
Jim Grosbachd3595712011-08-03 23:50:40 +0000388 unsigned RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +0000389 bool isAdd;
390 ARM_AM::ShiftOpc ShiftTy;
391 unsigned ShiftImm;
Jim Grosbachd3595712011-08-03 23:50:40 +0000392 } PostIdxReg;
393
394 struct {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000395 bool isASR;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000396 unsigned Imm;
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000397 } ShifterImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000398 struct {
399 ARM_AM::ShiftOpc ShiftTy;
400 unsigned SrcReg;
401 unsigned ShiftReg;
402 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000403 } RegShiftedReg;
Owen Andersonb595ed02011-07-21 18:54:16 +0000404 struct {
405 ARM_AM::ShiftOpc ShiftTy;
406 unsigned SrcReg;
407 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000408 } RegShiftedImm;
Jim Grosbach833b9d32011-07-27 20:15:40 +0000409 struct {
410 unsigned Imm;
411 } RotImm;
Jim Grosbach864b6092011-07-28 21:34:26 +0000412 struct {
413 unsigned LSB;
414 unsigned Width;
415 } Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000416 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000417
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000418 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
419public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000420 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
421 Kind = o.Kind;
422 StartLoc = o.StartLoc;
423 EndLoc = o.EndLoc;
424 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000425 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000426 CC = o.CC;
427 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000428 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000429 ITMask = o.ITMask;
430 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000431 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000432 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000433 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000434 case k_CCOut:
435 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000436 Reg = o.Reg;
437 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000438 case k_RegisterList:
439 case k_DPRRegisterList:
440 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000441 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000442 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000443 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000444 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000445 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000446 VectorList = o.VectorList;
447 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000448 case k_CoprocNum:
449 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000450 Cop = o.Cop;
451 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000452 case k_CoprocOption:
453 CoprocOption = o.CoprocOption;
454 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000455 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000456 Imm = o.Imm;
457 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000458 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000459 MBOpt = o.MBOpt;
460 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000462 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000465 PostIdxReg = o.PostIdxReg;
466 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000467 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000468 MMask = o.MMask;
469 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000470 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000471 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000472 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000473 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000474 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000475 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000476 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000477 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000478 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000479 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000480 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000481 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000482 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000483 RotImm = o.RotImm;
484 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000485 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000486 Bitfield = o.Bitfield;
487 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000488 case k_VectorIndex:
489 VectorIndex = o.VectorIndex;
490 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000491 }
492 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000493
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000494 /// getStartLoc - Get the location of the first token of this operand.
495 SMLoc getStartLoc() const { return StartLoc; }
496 /// getEndLoc - Get the location of the last token of this operand.
497 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000498 /// getLocRange - Get the range between the first and last token of this
499 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000500 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
501
Daniel Dunbard8042b72010-08-11 06:36:53 +0000502 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000503 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000504 return CC.Val;
505 }
506
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000507 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000508 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000509 return Cop.Val;
510 }
511
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000512 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000513 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000514 return StringRef(Tok.Data, Tok.Length);
515 }
516
517 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000518 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000519 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000520 }
521
Bill Wendlingbed94652010-11-09 23:28:44 +0000522 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000523 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
524 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000525 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000526 }
527
Kevin Enderbyf5079942009-10-13 22:19:02 +0000528 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000529 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000530 return Imm.Val;
531 }
532
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000533 unsigned getVectorIndex() const {
534 assert(Kind == k_VectorIndex && "Invalid access!");
535 return VectorIndex.Val;
536 }
537
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000538 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000540 return MBOpt.Val;
541 }
542
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000543 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000544 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000545 return IFlags.Val;
546 }
547
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000548 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000549 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000550 return MMask.Val;
551 }
552
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000553 bool isCoprocNum() const { return Kind == k_CoprocNum; }
554 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000555 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 bool isCondCode() const { return Kind == k_CondCode; }
557 bool isCCOut() const { return Kind == k_CCOut; }
558 bool isITMask() const { return Kind == k_ITCondMask; }
559 bool isITCondCode() const { return Kind == k_CondCode; }
560 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000561 bool isFPImm() const {
562 if (!isImm()) return false;
563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
564 if (!CE) return false;
565 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
566 return Val != -1;
567 }
Jim Grosbachea231912011-12-22 22:19:05 +0000568 bool isFBits16() const {
569 if (!isImm()) return false;
570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
571 if (!CE) return false;
572 int64_t Value = CE->getValue();
573 return Value >= 0 && Value <= 16;
574 }
575 bool isFBits32() const {
576 if (!isImm()) return false;
577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
578 if (!CE) return false;
579 int64_t Value = CE->getValue();
580 return Value >= 1 && Value <= 32;
581 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000582 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000583 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
585 if (!CE) return false;
586 int64_t Value = CE->getValue();
587 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
588 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000589 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000590 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
592 if (!CE) return false;
593 int64_t Value = CE->getValue();
594 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
595 }
596 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000597 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
599 if (!CE) return false;
600 int64_t Value = CE->getValue();
601 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
602 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000603 bool isImm0_508s4Neg() const {
604 if (!isImm()) return false;
605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
606 if (!CE) return false;
607 int64_t Value = -CE->getValue();
608 // explicitly exclude zero. we want that to use the normal 0_508 version.
609 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
610 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000611 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000612 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000613 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
614 if (!CE) return false;
615 int64_t Value = CE->getValue();
616 return Value >= 0 && Value < 256;
617 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000618 bool isImm0_4095() const {
619 if (!isImm()) return false;
620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
621 if (!CE) return false;
622 int64_t Value = CE->getValue();
623 return Value >= 0 && Value < 4096;
624 }
625 bool isImm0_4095Neg() const {
626 if (!isImm()) return false;
627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
628 if (!CE) return false;
629 int64_t Value = -CE->getValue();
630 return Value > 0 && Value < 4096;
631 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000632 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000633 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
635 if (!CE) return false;
636 int64_t Value = CE->getValue();
637 return Value >= 0 && Value < 2;
638 }
639 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000640 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
642 if (!CE) return false;
643 int64_t Value = CE->getValue();
644 return Value >= 0 && Value < 4;
645 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000646 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000647 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int64_t Value = CE->getValue();
651 return Value >= 0 && Value < 8;
652 }
653 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000654 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return Value >= 0 && Value < 16;
659 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000660 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000661 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value >= 0 && Value < 32;
666 }
Jim Grosbach00326402011-12-08 01:30:04 +0000667 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000668 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
672 return Value >= 0 && Value < 64;
673 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000674 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000675 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return Value == 8;
680 }
681 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000682 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = CE->getValue();
686 return Value == 16;
687 }
688 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000689 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
691 if (!CE) return false;
692 int64_t Value = CE->getValue();
693 return Value == 32;
694 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000695 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000696 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
698 if (!CE) return false;
699 int64_t Value = CE->getValue();
700 return Value > 0 && Value <= 8;
701 }
702 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000703 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
705 if (!CE) return false;
706 int64_t Value = CE->getValue();
707 return Value > 0 && Value <= 16;
708 }
709 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000710 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
712 if (!CE) return false;
713 int64_t Value = CE->getValue();
714 return Value > 0 && Value <= 32;
715 }
716 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000717 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
719 if (!CE) return false;
720 int64_t Value = CE->getValue();
721 return Value > 0 && Value <= 64;
722 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000723 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000724 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
726 if (!CE) return false;
727 int64_t Value = CE->getValue();
728 return Value > 0 && Value < 8;
729 }
730 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000731 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
733 if (!CE) return false;
734 int64_t Value = CE->getValue();
735 return Value > 0 && Value < 16;
736 }
737 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000738 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
740 if (!CE) return false;
741 int64_t Value = CE->getValue();
742 return Value > 0 && Value < 32;
743 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000744 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000745 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int64_t Value = CE->getValue();
749 return Value > 0 && Value < 17;
750 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000751 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000752 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value > 0 && Value < 33;
757 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000758 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000759 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int64_t Value = CE->getValue();
763 return Value >= 0 && Value < 33;
764 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000765 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000766 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return Value >= 0 && Value < 65536;
771 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000772 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000773 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 // If it's not a constant expression, it'll generate a fixup and be
776 // handled later.
777 if (!CE) return true;
778 int64_t Value = CE->getValue();
779 return Value >= 0 && Value < 65536;
780 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000781 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value >= 0 && Value <= 0xffffff;
787 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000788 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value < 33;
794 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000795 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000796 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value >= 0 && Value < 32;
801 }
802 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value <= 32;
808 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000809 bool isAdrLabel() const {
810 // If we have an immediate that's not a constant, treat it as a label
811 // reference needing a fixup. If it is a constant, but it can't fit
812 // into shift immediate encoding, we reject it.
813 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
814 else return (isARMSOImm() || isARMSOImmNeg());
815 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000816 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return ARM_AM::getSOImmVal(Value) != -1;
822 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000823 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000824 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return ARM_AM::getSOImmVal(~Value) != -1;
829 }
Jim Grosbach30506252011-12-08 00:31:07 +0000830 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000831 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 if (!CE) return false;
834 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000835 // Only use this when not representable as a plain so_imm.
836 return ARM_AM::getSOImmVal(Value) == -1 &&
837 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000838 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000839 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000840 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return ARM_AM::getT2SOImmVal(Value) != -1;
845 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000846 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return ARM_AM::getT2SOImmVal(~Value) != -1;
852 }
Jim Grosbach30506252011-12-08 00:31:07 +0000853 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000858 // Only use this when not representable as a plain so_imm.
859 return ARM_AM::getT2SOImmVal(Value) == -1 &&
860 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000861 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000862 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000863 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 if (!CE) return false;
866 int64_t Value = CE->getValue();
867 return Value == 1 || Value == 0;
868 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000869 bool isReg() const { return Kind == k_Register; }
870 bool isRegList() const { return Kind == k_RegisterList; }
871 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
872 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
873 bool isToken() const { return Kind == k_Token; }
874 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000875 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000876 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
877 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
878 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
879 bool isRotImm() const { return Kind == k_RotateImmediate; }
880 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
881 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000882 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000883 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000884 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000885 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000886 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000887 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000888 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000889 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
890 (alignOK || Memory.Alignment == 0);
891 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000892 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000893 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000894 return false;
895 // Base register must be PC.
896 if (Memory.BaseRegNum != ARM::PC)
897 return false;
898 // Immediate offset in range [-4095, 4095].
899 if (!Memory.OffsetImm) return true;
900 int64_t Val = Memory.OffsetImm->getValue();
901 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
902 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000903 bool isAlignedMemory() const {
904 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000905 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000906 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000907 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000908 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000909 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000910 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000911 if (!Memory.OffsetImm) return true;
912 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000913 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000914 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000915 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000917 // Immediate offset in range [-4095, 4095].
918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
919 if (!CE) return false;
920 int64_t Val = CE->getValue();
921 return Val > -4096 && Val < 4096;
922 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000923 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000924 // If we have an immediate that's not a constant, treat it as a label
925 // reference needing a fixup. If it is a constant, it's something else
926 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000927 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000928 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000929 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000930 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000931 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000932 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000933 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000934 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000935 if (!Memory.OffsetImm) return true;
936 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000937 // The #-0 offset is encoded as INT32_MIN, and we have to check
938 // for this too.
939 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000940 }
941 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000942 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000943 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000944 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000945 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
946 // Immediate offset in range [-255, 255].
947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000950 // Special case, #-0 is INT32_MIN.
951 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000952 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000953 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000954 // If we have an immediate that's not a constant, treat it as a label
955 // reference needing a fixup. If it is a constant, it's something else
956 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000957 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000958 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000959 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000960 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000961 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000962 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +0000963 if (!Memory.OffsetImm) return true;
964 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +0000965 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000966 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +0000967 }
Jim Grosbach05541f42011-09-19 22:21:13 +0000968 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +0000969 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000970 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +0000971 return false;
972 return true;
973 }
974 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +0000975 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000976 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
977 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +0000978 return false;
979 return true;
980 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000981 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000982 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +0000983 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +0000984 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000985 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000986 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000987 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000988 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000989 return false;
990 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +0000991 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000992 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +0000993 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000994 return false;
995 return true;
996 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000997 bool isMemThumbRR() const {
998 // Thumb reg+reg addressing is simple. Just two registers, a base and
999 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001000 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001001 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001002 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001003 return isARMLowRegister(Memory.BaseRegNum) &&
1004 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001005 }
1006 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001007 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001008 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001009 return false;
1010 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001011 if (!Memory.OffsetImm) return true;
1012 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001013 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1014 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001015 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001016 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001017 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001018 return false;
1019 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001020 if (!Memory.OffsetImm) return true;
1021 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001022 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1023 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001024 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001025 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001026 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001027 return false;
1028 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001029 if (!Memory.OffsetImm) return true;
1030 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001031 return Val >= 0 && Val <= 31;
1032 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001033 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001034 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001035 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001036 return false;
1037 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001038 if (!Memory.OffsetImm) return true;
1039 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001040 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001041 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001042 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001043 // If we have an immediate that's not a constant, treat it as a label
1044 // reference needing a fixup. If it is a constant, it's something else
1045 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001046 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001047 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001048 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001049 return false;
1050 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001051 if (!Memory.OffsetImm) return true;
1052 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001053 // Special case, #-0 is INT32_MIN.
1054 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001055 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001056 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001057 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001058 return false;
1059 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001060 if (!Memory.OffsetImm) return true;
1061 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001062 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1063 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001064 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001065 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001066 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001067 // Base reg of PC isn't allowed for these encodings.
1068 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001069 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001070 if (!Memory.OffsetImm) return true;
1071 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001072 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001073 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001074 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001075 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001076 return false;
1077 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001078 if (!Memory.OffsetImm) return true;
1079 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001080 return Val >= 0 && Val < 256;
1081 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001082 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001083 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001084 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001085 // Base reg of PC isn't allowed for these encodings.
1086 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001087 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001088 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001089 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001090 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001091 }
1092 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001094 return false;
1095 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001096 if (!Memory.OffsetImm) return true;
1097 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001098 return (Val >= 0 && Val < 4096);
1099 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001100 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001101 // If we have an immediate that's not a constant, treat it as a label
1102 // reference needing a fixup. If it is a constant, it's something else
1103 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001104 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001105 return true;
1106
Chad Rosier41099832012-09-11 23:02:35 +00001107 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001108 return false;
1109 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001110 if (!Memory.OffsetImm) return true;
1111 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001112 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001113 }
1114 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001115 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001116 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1117 if (!CE) return false;
1118 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001119 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001120 }
Jim Grosbach93981412011-10-11 21:55:36 +00001121 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001122 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001123 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1124 if (!CE) return false;
1125 int64_t Val = CE->getValue();
1126 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1127 (Val == INT32_MIN);
1128 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001129
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001130 bool isMSRMask() const { return Kind == k_MSRMask; }
1131 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001132
Jim Grosbach741cd732011-10-17 22:26:03 +00001133 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001134 bool isSingleSpacedVectorList() const {
1135 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1136 }
1137 bool isDoubleSpacedVectorList() const {
1138 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1139 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001140 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001141 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001142 return VectorList.Count == 1;
1143 }
1144
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001145 bool isVecListDPair() const {
1146 if (!isSingleSpacedVectorList()) return false;
1147 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1148 .contains(VectorList.RegNum));
1149 }
1150
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001151 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001152 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001153 return VectorList.Count == 3;
1154 }
1155
Jim Grosbach846bcff2011-10-21 20:35:01 +00001156 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001157 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001158 return VectorList.Count == 4;
1159 }
1160
Jim Grosbache5307f92012-03-05 21:43:40 +00001161 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001162 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001163 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1164 .contains(VectorList.RegNum));
1165 }
1166
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001167 bool isVecListThreeQ() const {
1168 if (!isDoubleSpacedVectorList()) return false;
1169 return VectorList.Count == 3;
1170 }
1171
Jim Grosbach1e946a42012-01-24 00:43:12 +00001172 bool isVecListFourQ() const {
1173 if (!isDoubleSpacedVectorList()) return false;
1174 return VectorList.Count == 4;
1175 }
1176
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001177 bool isSingleSpacedVectorAllLanes() const {
1178 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1179 }
1180 bool isDoubleSpacedVectorAllLanes() const {
1181 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1182 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001183 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001184 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001185 return VectorList.Count == 1;
1186 }
1187
Jim Grosbach13a292c2012-03-06 22:01:44 +00001188 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001189 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001190 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1191 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001192 }
1193
Jim Grosbached428bc2012-03-06 23:10:38 +00001194 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001195 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001196 return VectorList.Count == 2;
1197 }
1198
Jim Grosbachb78403c2012-01-24 23:47:04 +00001199 bool isVecListThreeDAllLanes() const {
1200 if (!isSingleSpacedVectorAllLanes()) return false;
1201 return VectorList.Count == 3;
1202 }
1203
1204 bool isVecListThreeQAllLanes() const {
1205 if (!isDoubleSpacedVectorAllLanes()) return false;
1206 return VectorList.Count == 3;
1207 }
1208
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001209 bool isVecListFourDAllLanes() const {
1210 if (!isSingleSpacedVectorAllLanes()) return false;
1211 return VectorList.Count == 4;
1212 }
1213
1214 bool isVecListFourQAllLanes() const {
1215 if (!isDoubleSpacedVectorAllLanes()) return false;
1216 return VectorList.Count == 4;
1217 }
1218
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001219 bool isSingleSpacedVectorIndexed() const {
1220 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1221 }
1222 bool isDoubleSpacedVectorIndexed() const {
1223 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1224 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001225 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001226 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001227 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1228 }
1229
Jim Grosbachda511042011-12-14 23:35:06 +00001230 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001231 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001232 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1233 }
1234
1235 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001236 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001237 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1238 }
1239
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001240 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001241 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001242 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1243 }
1244
Jim Grosbachda511042011-12-14 23:35:06 +00001245 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001246 if (!isSingleSpacedVectorIndexed()) return false;
1247 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1248 }
1249
1250 bool isVecListTwoQWordIndexed() const {
1251 if (!isDoubleSpacedVectorIndexed()) return false;
1252 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1253 }
1254
1255 bool isVecListTwoQHWordIndexed() const {
1256 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001257 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1258 }
1259
1260 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001261 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001262 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1263 }
1264
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001265 bool isVecListThreeDByteIndexed() const {
1266 if (!isSingleSpacedVectorIndexed()) return false;
1267 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1268 }
1269
1270 bool isVecListThreeDHWordIndexed() const {
1271 if (!isSingleSpacedVectorIndexed()) return false;
1272 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1273 }
1274
1275 bool isVecListThreeQWordIndexed() const {
1276 if (!isDoubleSpacedVectorIndexed()) return false;
1277 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1278 }
1279
1280 bool isVecListThreeQHWordIndexed() const {
1281 if (!isDoubleSpacedVectorIndexed()) return false;
1282 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1283 }
1284
1285 bool isVecListThreeDWordIndexed() const {
1286 if (!isSingleSpacedVectorIndexed()) return false;
1287 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1288 }
1289
Jim Grosbach14952a02012-01-24 18:37:25 +00001290 bool isVecListFourDByteIndexed() const {
1291 if (!isSingleSpacedVectorIndexed()) return false;
1292 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1293 }
1294
1295 bool isVecListFourDHWordIndexed() const {
1296 if (!isSingleSpacedVectorIndexed()) return false;
1297 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1298 }
1299
1300 bool isVecListFourQWordIndexed() const {
1301 if (!isDoubleSpacedVectorIndexed()) return false;
1302 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1303 }
1304
1305 bool isVecListFourQHWordIndexed() const {
1306 if (!isDoubleSpacedVectorIndexed()) return false;
1307 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1308 }
1309
1310 bool isVecListFourDWordIndexed() const {
1311 if (!isSingleSpacedVectorIndexed()) return false;
1312 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1313 }
1314
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001315 bool isVectorIndex8() const {
1316 if (Kind != k_VectorIndex) return false;
1317 return VectorIndex.Val < 8;
1318 }
1319 bool isVectorIndex16() const {
1320 if (Kind != k_VectorIndex) return false;
1321 return VectorIndex.Val < 4;
1322 }
1323 bool isVectorIndex32() const {
1324 if (Kind != k_VectorIndex) return false;
1325 return VectorIndex.Val < 2;
1326 }
1327
Jim Grosbach741cd732011-10-17 22:26:03 +00001328 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001329 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +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 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1335 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001336 return Value >= 0 && Value < 256;
1337 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001338
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001339 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001340 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001341 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1342 // Must be a constant.
1343 if (!CE) return false;
1344 int64_t Value = CE->getValue();
1345 // i16 value in the range [0,255] or [0x0100, 0xff00]
1346 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1347 }
1348
Jim Grosbach8211c052011-10-18 00:22:00 +00001349 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001350 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001351 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1352 // Must be a constant.
1353 if (!CE) return false;
1354 int64_t Value = CE->getValue();
1355 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1356 return (Value >= 0 && Value < 256) ||
1357 (Value >= 0x0100 && Value <= 0xff00) ||
1358 (Value >= 0x010000 && Value <= 0xff0000) ||
1359 (Value >= 0x01000000 && Value <= 0xff000000);
1360 }
1361
1362 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001363 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1365 // Must be a constant.
1366 if (!CE) return false;
1367 int64_t Value = CE->getValue();
1368 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1369 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1370 return (Value >= 0 && Value < 256) ||
1371 (Value >= 0x0100 && Value <= 0xff00) ||
1372 (Value >= 0x010000 && Value <= 0xff0000) ||
1373 (Value >= 0x01000000 && Value <= 0xff000000) ||
1374 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1375 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1376 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001377 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001378 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001379 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1380 // Must be a constant.
1381 if (!CE) return false;
1382 int64_t Value = ~CE->getValue();
1383 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1384 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1385 return (Value >= 0 && Value < 256) ||
1386 (Value >= 0x0100 && Value <= 0xff00) ||
1387 (Value >= 0x010000 && Value <= 0xff0000) ||
1388 (Value >= 0x01000000 && Value <= 0xff000000) ||
1389 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1390 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1391 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001392
Jim Grosbache4454e02011-10-18 16:18:11 +00001393 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001394 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001395 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1396 // Must be a constant.
1397 if (!CE) return false;
1398 uint64_t Value = CE->getValue();
1399 // i64 value with each byte being either 0 or 0xff.
1400 for (unsigned i = 0; i < 8; ++i)
1401 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1402 return true;
1403 }
1404
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001405 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001406 // Add as immediates when possible. Null MCExpr = 0.
1407 if (Expr == 0)
1408 Inst.addOperand(MCOperand::CreateImm(0));
1409 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001410 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1411 else
1412 Inst.addOperand(MCOperand::CreateExpr(Expr));
1413 }
1414
Daniel Dunbard8042b72010-08-11 06:36:53 +00001415 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001416 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001417 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001418 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1419 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001420 }
1421
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001422 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1423 assert(N == 1 && "Invalid number of operands!");
1424 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1425 }
1426
Jim Grosbach48399582011-10-12 17:34:41 +00001427 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1428 assert(N == 1 && "Invalid number of operands!");
1429 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1430 }
1431
1432 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1433 assert(N == 1 && "Invalid number of operands!");
1434 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1435 }
1436
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001437 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1438 assert(N == 1 && "Invalid number of operands!");
1439 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1440 }
1441
1442 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1443 assert(N == 1 && "Invalid number of operands!");
1444 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1445 }
1446
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001447 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1448 assert(N == 1 && "Invalid number of operands!");
1449 Inst.addOperand(MCOperand::CreateReg(getReg()));
1450 }
1451
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001452 void addRegOperands(MCInst &Inst, unsigned N) const {
1453 assert(N == 1 && "Invalid number of operands!");
1454 Inst.addOperand(MCOperand::CreateReg(getReg()));
1455 }
1456
Jim Grosbachac798e12011-07-25 20:49:51 +00001457 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001458 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001459 assert(isRegShiftedReg() &&
1460 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001461 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1462 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001463 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001464 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001465 }
1466
Jim Grosbachac798e12011-07-25 20:49:51 +00001467 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001468 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001469 assert(isRegShiftedImm() &&
1470 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001471 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001472 // Shift of #32 is encoded as 0 where permitted
1473 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001474 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001475 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001476 }
1477
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001478 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001479 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001480 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1481 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001482 }
1483
Bill Wendling8d2aa032010-11-08 23:49:57 +00001484 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001485 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001486 const SmallVectorImpl<unsigned> &RegList = getRegList();
1487 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001488 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1489 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001490 }
1491
Bill Wendling9898ac92010-11-17 04:32:08 +00001492 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1493 addRegListOperands(Inst, N);
1494 }
1495
1496 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1497 addRegListOperands(Inst, N);
1498 }
1499
Jim Grosbach833b9d32011-07-27 20:15:40 +00001500 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1501 assert(N == 1 && "Invalid number of operands!");
1502 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1503 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1504 }
1505
Jim Grosbach864b6092011-07-28 21:34:26 +00001506 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 // Munge the lsb/width into a bitfield mask.
1509 unsigned lsb = Bitfield.LSB;
1510 unsigned width = Bitfield.Width;
1511 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1512 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1513 (32 - (lsb + width)));
1514 Inst.addOperand(MCOperand::CreateImm(Mask));
1515 }
1516
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001517 void addImmOperands(MCInst &Inst, unsigned N) const {
1518 assert(N == 1 && "Invalid number of operands!");
1519 addExpr(Inst, getImm());
1520 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001521
Jim Grosbachea231912011-12-22 22:19:05 +00001522 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1525 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1526 }
1527
1528 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1531 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1532 }
1533
Jim Grosbache7fbce72011-10-03 23:38:36 +00001534 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1535 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001536 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1537 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1538 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001539 }
1540
Jim Grosbach7db8d692011-09-08 22:07:06 +00001541 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1542 assert(N == 1 && "Invalid number of operands!");
1543 // FIXME: We really want to scale the value here, but the LDRD/STRD
1544 // instruction don't encode operands that way yet.
1545 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1546 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1547 }
1548
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001549 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1550 assert(N == 1 && "Invalid number of operands!");
1551 // The immediate is scaled by four in the encoding and is stored
1552 // in the MCInst as such. Lop off the low two bits here.
1553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1554 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1555 }
1556
Jim Grosbach930f2f62012-04-05 20:57:13 +00001557 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1558 assert(N == 1 && "Invalid number of operands!");
1559 // The immediate is scaled by four in the encoding and is stored
1560 // in the MCInst as such. Lop off the low two bits here.
1561 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1562 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1563 }
1564
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001565 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 // The immediate is scaled by four in the encoding and is stored
1568 // in the MCInst as such. Lop off the low two bits here.
1569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1570 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1571 }
1572
Jim Grosbach475c6db2011-07-25 23:09:14 +00001573 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1574 assert(N == 1 && "Invalid number of operands!");
1575 // The constant encodes as the immediate-1, and we store in the instruction
1576 // the bits as encoded, so subtract off one here.
1577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1578 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1579 }
1580
Jim Grosbach801e0a32011-07-22 23:16:18 +00001581 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1582 assert(N == 1 && "Invalid number of operands!");
1583 // The constant encodes as the immediate-1, and we store in the instruction
1584 // the bits as encoded, so subtract off one here.
1585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1586 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1587 }
1588
Jim Grosbach46dd4132011-08-17 21:51:27 +00001589 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1590 assert(N == 1 && "Invalid number of operands!");
1591 // The constant encodes as the immediate, except for 32, which encodes as
1592 // zero.
1593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1594 unsigned Imm = CE->getValue();
1595 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1596 }
1597
Jim Grosbach27c1e252011-07-21 17:23:04 +00001598 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1599 assert(N == 1 && "Invalid number of operands!");
1600 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1601 // the instruction as well.
1602 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1603 int Val = CE->getValue();
1604 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1605 }
1606
Jim Grosbachb009a872011-10-28 22:36:30 +00001607 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 // The operand is actually a t2_so_imm, but we have its bitwise
1610 // negation in the assembly source, so twiddle it here.
1611 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1612 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1613 }
1614
Jim Grosbach30506252011-12-08 00:31:07 +00001615 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1616 assert(N == 1 && "Invalid number of operands!");
1617 // The operand is actually a t2_so_imm, but we have its
1618 // negation in the assembly source, so twiddle it here.
1619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1620 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1621 }
1622
Jim Grosbach930f2f62012-04-05 20:57:13 +00001623 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 // The operand is actually an imm0_4095, but we have its
1626 // negation in the assembly source, so twiddle it here.
1627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1628 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1629 }
1630
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001631 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1632 assert(N == 1 && "Invalid number of operands!");
1633 // The operand is actually a so_imm, but we have its bitwise
1634 // negation in the assembly source, so twiddle it here.
1635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1636 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1637 }
1638
Jim Grosbach30506252011-12-08 00:31:07 +00001639 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1640 assert(N == 1 && "Invalid number of operands!");
1641 // The operand is actually a so_imm, but we have its
1642 // negation in the assembly source, so twiddle it here.
1643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1644 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1645 }
1646
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001647 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1648 assert(N == 1 && "Invalid number of operands!");
1649 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1650 }
1651
Jim Grosbachd3595712011-08-03 23:50:40 +00001652 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001654 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001655 }
1656
Jim Grosbach94298a92012-01-18 22:46:46 +00001657 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 int32_t Imm = Memory.OffsetImm->getValue();
1660 // FIXME: Handle #-0
1661 if (Imm == INT32_MIN) Imm = 0;
1662 Inst.addOperand(MCOperand::CreateImm(Imm));
1663 }
1664
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001665 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1666 assert(N == 1 && "Invalid number of operands!");
1667 assert(isImm() && "Not an immediate!");
1668
1669 // If we have an immediate that's not a constant, treat it as a label
1670 // reference needing a fixup.
1671 if (!isa<MCConstantExpr>(getImm())) {
1672 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1673 return;
1674 }
1675
1676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1677 int Val = CE->getValue();
1678 Inst.addOperand(MCOperand::CreateImm(Val));
1679 }
1680
Jim Grosbacha95ec992011-10-11 17:29:55 +00001681 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1682 assert(N == 2 && "Invalid number of operands!");
1683 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1684 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1685 }
1686
Jim Grosbachd3595712011-08-03 23:50:40 +00001687 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1688 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001689 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1690 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001691 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1692 // Special case for #-0
1693 if (Val == INT32_MIN) Val = 0;
1694 if (Val < 0) Val = -Val;
1695 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1696 } else {
1697 // For register offset, we encode the shift type and negation flag
1698 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001699 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1700 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001701 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001702 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1703 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001704 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001705 }
1706
Jim Grosbachcd17c122011-08-04 23:01:30 +00001707 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 2 && "Invalid number of operands!");
1709 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1710 assert(CE && "non-constant AM2OffsetImm operand!");
1711 int32_t Val = CE->getValue();
1712 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1713 // Special case for #-0
1714 if (Val == INT32_MIN) Val = 0;
1715 if (Val < 0) Val = -Val;
1716 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1717 Inst.addOperand(MCOperand::CreateReg(0));
1718 Inst.addOperand(MCOperand::CreateImm(Val));
1719 }
1720
Jim Grosbach5b96b802011-08-10 20:29:19 +00001721 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1722 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001723 // If we have an immediate that's not a constant, treat it as a label
1724 // reference needing a fixup. If it is a constant, it's something else
1725 // and we reject it.
1726 if (isImm()) {
1727 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1728 Inst.addOperand(MCOperand::CreateReg(0));
1729 Inst.addOperand(MCOperand::CreateImm(0));
1730 return;
1731 }
1732
Jim Grosbach871dff72011-10-11 15:59:20 +00001733 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1734 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001735 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1736 // Special case for #-0
1737 if (Val == INT32_MIN) Val = 0;
1738 if (Val < 0) Val = -Val;
1739 Val = ARM_AM::getAM3Opc(AddSub, Val);
1740 } else {
1741 // For register offset, we encode the shift type and negation flag
1742 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001743 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001744 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001745 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1746 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001747 Inst.addOperand(MCOperand::CreateImm(Val));
1748 }
1749
1750 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1751 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001752 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001753 int32_t Val =
1754 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1755 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1756 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001757 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001758 }
1759
1760 // Constant offset.
1761 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1762 int32_t Val = CE->getValue();
1763 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1764 // Special case for #-0
1765 if (Val == INT32_MIN) Val = 0;
1766 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001767 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001768 Inst.addOperand(MCOperand::CreateReg(0));
1769 Inst.addOperand(MCOperand::CreateImm(Val));
1770 }
1771
Jim Grosbachd3595712011-08-03 23:50:40 +00001772 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1773 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001774 // If we have an immediate that's not a constant, treat it as a label
1775 // reference needing a fixup. If it is a constant, it's something else
1776 // and we reject it.
1777 if (isImm()) {
1778 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1779 Inst.addOperand(MCOperand::CreateImm(0));
1780 return;
1781 }
1782
Jim Grosbachd3595712011-08-03 23:50:40 +00001783 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001784 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001785 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1786 // Special case for #-0
1787 if (Val == INT32_MIN) Val = 0;
1788 if (Val < 0) Val = -Val;
1789 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001790 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001791 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001792 }
1793
Jim Grosbach7db8d692011-09-08 22:07:06 +00001794 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001796 // If we have an immediate that's not a constant, treat it as a label
1797 // reference needing a fixup. If it is a constant, it's something else
1798 // and we reject it.
1799 if (isImm()) {
1800 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1801 Inst.addOperand(MCOperand::CreateImm(0));
1802 return;
1803 }
1804
Jim Grosbach871dff72011-10-11 15:59:20 +00001805 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1806 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001807 Inst.addOperand(MCOperand::CreateImm(Val));
1808 }
1809
Jim Grosbacha05627e2011-09-09 18:37:27 +00001810 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 2 && "Invalid number of operands!");
1812 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001813 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1814 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001815 Inst.addOperand(MCOperand::CreateImm(Val));
1816 }
1817
Jim Grosbachd3595712011-08-03 23:50:40 +00001818 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1819 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001820 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1821 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001822 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001823 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001824
Jim Grosbach2392c532011-09-07 23:39:14 +00001825 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1826 addMemImm8OffsetOperands(Inst, N);
1827 }
1828
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001829 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001830 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001831 }
1832
1833 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1834 assert(N == 2 && "Invalid number of operands!");
1835 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001836 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001837 addExpr(Inst, getImm());
1838 Inst.addOperand(MCOperand::CreateImm(0));
1839 return;
1840 }
1841
1842 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001843 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1844 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001845 Inst.addOperand(MCOperand::CreateImm(Val));
1846 }
1847
Jim Grosbachd3595712011-08-03 23:50:40 +00001848 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1849 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001850 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001851 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001852 addExpr(Inst, getImm());
1853 Inst.addOperand(MCOperand::CreateImm(0));
1854 return;
1855 }
1856
1857 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001858 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1859 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001860 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001861 }
Bill Wendling811c9362010-11-30 07:44:32 +00001862
Jim Grosbach05541f42011-09-19 22:21:13 +00001863 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001865 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1866 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001867 }
1868
1869 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1870 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001871 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1872 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001873 }
1874
Jim Grosbachd3595712011-08-03 23:50:40 +00001875 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001877 unsigned Val =
1878 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1879 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001882 Inst.addOperand(MCOperand::CreateImm(Val));
1883 }
1884
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001885 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001887 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1888 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1889 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001890 }
1891
Jim Grosbachd3595712011-08-03 23:50:40 +00001892 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1893 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001894 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1895 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001896 }
1897
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001898 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1899 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001900 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1901 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001902 Inst.addOperand(MCOperand::CreateImm(Val));
1903 }
1904
Jim Grosbach26d35872011-08-19 18:55:51 +00001905 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1906 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001907 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1908 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001909 Inst.addOperand(MCOperand::CreateImm(Val));
1910 }
1911
Jim Grosbacha32c7532011-08-19 18:49:59 +00001912 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1913 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001914 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1915 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001916 Inst.addOperand(MCOperand::CreateImm(Val));
1917 }
1918
Jim Grosbach23983d62011-08-19 18:13:48 +00001919 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1920 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001921 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1922 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001923 Inst.addOperand(MCOperand::CreateImm(Val));
1924 }
1925
Jim Grosbachd3595712011-08-03 23:50:40 +00001926 void addPostIdxImm8Operands(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-imm8 operand!");
1930 int Imm = CE->getValue();
1931 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00001932 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001933 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1934 Inst.addOperand(MCOperand::CreateImm(Imm));
1935 }
1936
Jim Grosbach93981412011-10-11 21:55:36 +00001937 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1938 assert(N == 1 && "Invalid number of operands!");
1939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1940 assert(CE && "non-constant post-idx-imm8s4 operand!");
1941 int Imm = CE->getValue();
1942 bool isAdd = Imm >= 0;
1943 if (Imm == INT32_MIN) Imm = 0;
1944 // Immediate is scaled by 4.
1945 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1946 Inst.addOperand(MCOperand::CreateImm(Imm));
1947 }
1948
Jim Grosbachd3595712011-08-03 23:50:40 +00001949 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 2 && "Invalid number of operands!");
1951 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00001952 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1953 }
1954
1955 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 2 && "Invalid number of operands!");
1957 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1958 // The sign, shift type, and shift amount are encoded in a single operand
1959 // using the AM2 encoding helpers.
1960 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1961 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1962 PostIdxReg.ShiftTy);
1963 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00001964 }
1965
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00001966 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 1 && "Invalid number of operands!");
1968 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1969 }
1970
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00001971 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1972 assert(N == 1 && "Invalid number of operands!");
1973 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1974 }
1975
Jim Grosbach182b6a02011-11-29 23:51:09 +00001976 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001977 assert(N == 1 && "Invalid number of operands!");
1978 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1979 }
1980
Jim Grosbach04945c42011-12-02 00:35:16 +00001981 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1982 assert(N == 2 && "Invalid number of operands!");
1983 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1984 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1985 }
1986
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001987 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1988 assert(N == 1 && "Invalid number of operands!");
1989 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1990 }
1991
1992 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1993 assert(N == 1 && "Invalid number of operands!");
1994 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1995 }
1996
1997 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1998 assert(N == 1 && "Invalid number of operands!");
1999 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2000 }
2001
Jim Grosbach741cd732011-10-17 22:26:03 +00002002 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2003 assert(N == 1 && "Invalid number of operands!");
2004 // The immediate encodes the type of constant as well as the value.
2005 // Mask in that this is an i8 splat.
2006 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2007 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2008 }
2009
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002010 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 1 && "Invalid number of operands!");
2012 // The immediate encodes the type of constant as well as the value.
2013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2014 unsigned Value = CE->getValue();
2015 if (Value >= 256)
2016 Value = (Value >> 8) | 0xa00;
2017 else
2018 Value |= 0x800;
2019 Inst.addOperand(MCOperand::CreateImm(Value));
2020 }
2021
Jim Grosbach8211c052011-10-18 00:22:00 +00002022 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 1 && "Invalid number of operands!");
2024 // The immediate encodes the type of constant as well as the value.
2025 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2026 unsigned Value = CE->getValue();
2027 if (Value >= 256 && Value <= 0xff00)
2028 Value = (Value >> 8) | 0x200;
2029 else if (Value > 0xffff && Value <= 0xff0000)
2030 Value = (Value >> 16) | 0x400;
2031 else if (Value > 0xffffff)
2032 Value = (Value >> 24) | 0x600;
2033 Inst.addOperand(MCOperand::CreateImm(Value));
2034 }
2035
2036 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 1 && "Invalid number of operands!");
2038 // The immediate encodes the type of constant as well as the value.
2039 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2040 unsigned Value = CE->getValue();
2041 if (Value >= 256 && Value <= 0xffff)
2042 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2043 else if (Value > 0xffff && Value <= 0xffffff)
2044 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2045 else if (Value > 0xffffff)
2046 Value = (Value >> 24) | 0x600;
2047 Inst.addOperand(MCOperand::CreateImm(Value));
2048 }
2049
Jim Grosbach045b6c72011-12-19 23:51:07 +00002050 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2051 assert(N == 1 && "Invalid number of operands!");
2052 // The immediate encodes the type of constant as well as the value.
2053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2054 unsigned Value = ~CE->getValue();
2055 if (Value >= 256 && Value <= 0xffff)
2056 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2057 else if (Value > 0xffff && Value <= 0xffffff)
2058 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2059 else if (Value > 0xffffff)
2060 Value = (Value >> 24) | 0x600;
2061 Inst.addOperand(MCOperand::CreateImm(Value));
2062 }
2063
Jim Grosbache4454e02011-10-18 16:18:11 +00002064 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 1 && "Invalid number of operands!");
2066 // The immediate encodes the type of constant as well as the value.
2067 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2068 uint64_t Value = CE->getValue();
2069 unsigned Imm = 0;
2070 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2071 Imm |= (Value & 1) << i;
2072 }
2073 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2074 }
2075
Jim Grosbach602aa902011-07-13 15:34:57 +00002076 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002077
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002078 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002079 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002080 Op->ITMask.Mask = Mask;
2081 Op->StartLoc = S;
2082 Op->EndLoc = S;
2083 return Op;
2084 }
2085
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002086 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002087 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002088 Op->CC.Val = CC;
2089 Op->StartLoc = S;
2090 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002091 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002092 }
2093
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002094 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002095 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002096 Op->Cop.Val = CopVal;
2097 Op->StartLoc = S;
2098 Op->EndLoc = S;
2099 return Op;
2100 }
2101
2102 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002103 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002104 Op->Cop.Val = CopVal;
2105 Op->StartLoc = S;
2106 Op->EndLoc = S;
2107 return Op;
2108 }
2109
Jim Grosbach48399582011-10-12 17:34:41 +00002110 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2111 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2112 Op->Cop.Val = Val;
2113 Op->StartLoc = S;
2114 Op->EndLoc = E;
2115 return Op;
2116 }
2117
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002118 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002119 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002120 Op->Reg.RegNum = RegNum;
2121 Op->StartLoc = S;
2122 Op->EndLoc = S;
2123 return Op;
2124 }
2125
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002126 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002127 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002128 Op->Tok.Data = Str.data();
2129 Op->Tok.Length = Str.size();
2130 Op->StartLoc = S;
2131 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002132 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002133 }
2134
Bill Wendling2063b842010-11-18 23:43:05 +00002135 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002136 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002137 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002138 Op->StartLoc = S;
2139 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002140 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002141 }
2142
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002143 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2144 unsigned SrcReg,
2145 unsigned ShiftReg,
2146 unsigned ShiftImm,
2147 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002148 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002149 Op->RegShiftedReg.ShiftTy = ShTy;
2150 Op->RegShiftedReg.SrcReg = SrcReg;
2151 Op->RegShiftedReg.ShiftReg = ShiftReg;
2152 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002153 Op->StartLoc = S;
2154 Op->EndLoc = E;
2155 return Op;
2156 }
2157
Owen Andersonb595ed02011-07-21 18:54:16 +00002158 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2159 unsigned SrcReg,
2160 unsigned ShiftImm,
2161 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002162 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002163 Op->RegShiftedImm.ShiftTy = ShTy;
2164 Op->RegShiftedImm.SrcReg = SrcReg;
2165 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002166 Op->StartLoc = S;
2167 Op->EndLoc = E;
2168 return Op;
2169 }
2170
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002171 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002172 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002173 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002174 Op->ShifterImm.isASR = isASR;
2175 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002176 Op->StartLoc = S;
2177 Op->EndLoc = E;
2178 return Op;
2179 }
2180
Jim Grosbach833b9d32011-07-27 20:15:40 +00002181 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002182 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002183 Op->RotImm.Imm = Imm;
2184 Op->StartLoc = S;
2185 Op->EndLoc = E;
2186 return Op;
2187 }
2188
Jim Grosbach864b6092011-07-28 21:34:26 +00002189 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2190 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002191 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002192 Op->Bitfield.LSB = LSB;
2193 Op->Bitfield.Width = Width;
2194 Op->StartLoc = S;
2195 Op->EndLoc = E;
2196 return Op;
2197 }
2198
Bill Wendling2cae3272010-11-09 22:44:22 +00002199 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002200 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002201 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002202 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002203
Jim Grosbach75461af2011-09-13 22:56:44 +00002204 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002205 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002206 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002207 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002208 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002209
2210 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002211 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002212 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002213 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002214 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002215 Op->StartLoc = StartLoc;
2216 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002217 return Op;
2218 }
2219
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002220 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002221 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002222 ARMOperand *Op = new ARMOperand(k_VectorList);
2223 Op->VectorList.RegNum = RegNum;
2224 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002225 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002226 Op->StartLoc = S;
2227 Op->EndLoc = E;
2228 return Op;
2229 }
2230
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002231 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002232 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002233 SMLoc S, SMLoc E) {
2234 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2235 Op->VectorList.RegNum = RegNum;
2236 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002237 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002238 Op->StartLoc = S;
2239 Op->EndLoc = E;
2240 return Op;
2241 }
2242
Jim Grosbach04945c42011-12-02 00:35:16 +00002243 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002244 unsigned Index,
2245 bool isDoubleSpaced,
2246 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002247 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2248 Op->VectorList.RegNum = RegNum;
2249 Op->VectorList.Count = Count;
2250 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002251 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002252 Op->StartLoc = S;
2253 Op->EndLoc = E;
2254 return Op;
2255 }
2256
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002257 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2258 MCContext &Ctx) {
2259 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2260 Op->VectorIndex.Val = Idx;
2261 Op->StartLoc = S;
2262 Op->EndLoc = E;
2263 return Op;
2264 }
2265
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002266 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002267 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002268 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002269 Op->StartLoc = S;
2270 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002271 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002272 }
2273
Jim Grosbachd3595712011-08-03 23:50:40 +00002274 static ARMOperand *CreateMem(unsigned BaseRegNum,
2275 const MCConstantExpr *OffsetImm,
2276 unsigned OffsetRegNum,
2277 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002278 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002279 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002280 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002281 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002282 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002283 Op->Memory.BaseRegNum = BaseRegNum;
2284 Op->Memory.OffsetImm = OffsetImm;
2285 Op->Memory.OffsetRegNum = OffsetRegNum;
2286 Op->Memory.ShiftType = ShiftType;
2287 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002288 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002289 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002290 Op->StartLoc = S;
2291 Op->EndLoc = E;
2292 return Op;
2293 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002294
Jim Grosbachc320c852011-08-05 21:28:30 +00002295 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2296 ARM_AM::ShiftOpc ShiftTy,
2297 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002298 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002299 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002300 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002301 Op->PostIdxReg.isAdd = isAdd;
2302 Op->PostIdxReg.ShiftTy = ShiftTy;
2303 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002304 Op->StartLoc = S;
2305 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002306 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002307 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002308
2309 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002310 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002311 Op->MBOpt.Val = Opt;
2312 Op->StartLoc = S;
2313 Op->EndLoc = S;
2314 return Op;
2315 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002316
2317 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002318 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002319 Op->IFlags.Val = IFlags;
2320 Op->StartLoc = S;
2321 Op->EndLoc = S;
2322 return Op;
2323 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002324
2325 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002326 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002327 Op->MMask.Val = MMask;
2328 Op->StartLoc = S;
2329 Op->EndLoc = S;
2330 return Op;
2331 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002332};
2333
2334} // end anonymous namespace.
2335
Jim Grosbach602aa902011-07-13 15:34:57 +00002336void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002337 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002338 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002339 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002340 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002341 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002342 OS << "<ccout " << getReg() << ">";
2343 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002344 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002345 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002346 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2347 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2348 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002349 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2350 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2351 break;
2352 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002353 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002354 OS << "<coprocessor number: " << getCoproc() << ">";
2355 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002356 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002357 OS << "<coprocessor register: " << getCoproc() << ">";
2358 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002359 case k_CoprocOption:
2360 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2361 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002362 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002363 OS << "<mask: " << getMSRMask() << ">";
2364 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002365 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002366 getImm()->print(OS);
2367 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002368 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002369 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2370 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002371 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002372 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002373 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002374 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002375 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002376 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002377 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2378 << PostIdxReg.RegNum;
2379 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2380 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2381 << PostIdxReg.ShiftImm;
2382 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002383 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002384 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002385 OS << "<ARM_PROC::";
2386 unsigned IFlags = getProcIFlags();
2387 for (int i=2; i >= 0; --i)
2388 if (IFlags & (1 << i))
2389 OS << ARM_PROC::IFlagsToString(1 << i);
2390 OS << ">";
2391 break;
2392 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002393 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002394 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002395 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002396 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002397 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2398 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002399 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002400 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002401 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002402 << RegShiftedReg.SrcReg << " "
2403 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2404 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002405 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002406 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002407 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002408 << RegShiftedImm.SrcReg << " "
2409 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2410 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002411 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002412 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002413 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2414 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002415 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002416 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2417 << ", width: " << Bitfield.Width << ">";
2418 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002419 case k_RegisterList:
2420 case k_DPRRegisterList:
2421 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002422 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002423
Bill Wendlingbed94652010-11-09 23:28:44 +00002424 const SmallVectorImpl<unsigned> &RegList = getRegList();
2425 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002426 I = RegList.begin(), E = RegList.end(); I != E; ) {
2427 OS << *I;
2428 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002429 }
2430
2431 OS << ">";
2432 break;
2433 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002434 case k_VectorList:
2435 OS << "<vector_list " << VectorList.Count << " * "
2436 << VectorList.RegNum << ">";
2437 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002438 case k_VectorListAllLanes:
2439 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2440 << VectorList.RegNum << ">";
2441 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002442 case k_VectorListIndexed:
2443 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2444 << VectorList.Count << " * " << VectorList.RegNum << ">";
2445 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002447 OS << "'" << getToken() << "'";
2448 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002449 case k_VectorIndex:
2450 OS << "<vectorindex " << getVectorIndex() << ">";
2451 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002452 }
2453}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002454
2455/// @name Auto-generated Match Functions
2456/// {
2457
2458static unsigned MatchRegisterName(StringRef Name);
2459
2460/// }
2461
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002462bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2463 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002464 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002465 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002466 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002467
2468 return (RegNo == (unsigned)-1);
2469}
2470
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002471/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002472/// and if it is a register name the token is eaten and the register number is
2473/// returned. Otherwise return -1.
2474///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002475int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002476 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002477 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002478
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002479 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002480 unsigned RegNum = MatchRegisterName(lowerCase);
2481 if (!RegNum) {
2482 RegNum = StringSwitch<unsigned>(lowerCase)
2483 .Case("r13", ARM::SP)
2484 .Case("r14", ARM::LR)
2485 .Case("r15", ARM::PC)
2486 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002487 // Additional register name aliases for 'gas' compatibility.
2488 .Case("a1", ARM::R0)
2489 .Case("a2", ARM::R1)
2490 .Case("a3", ARM::R2)
2491 .Case("a4", ARM::R3)
2492 .Case("v1", ARM::R4)
2493 .Case("v2", ARM::R5)
2494 .Case("v3", ARM::R6)
2495 .Case("v4", ARM::R7)
2496 .Case("v5", ARM::R8)
2497 .Case("v6", ARM::R9)
2498 .Case("v7", ARM::R10)
2499 .Case("v8", ARM::R11)
2500 .Case("sb", ARM::R9)
2501 .Case("sl", ARM::R10)
2502 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002503 .Default(0);
2504 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002505 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002506 // Check for aliases registered via .req. Canonicalize to lower case.
2507 // That's more consistent since register names are case insensitive, and
2508 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2509 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002510 // If no match, return failure.
2511 if (Entry == RegisterReqs.end())
2512 return -1;
2513 Parser.Lex(); // Eat identifier token.
2514 return Entry->getValue();
2515 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002516
Chris Lattner44e5981c2010-10-30 04:09:10 +00002517 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002518
Chris Lattner44e5981c2010-10-30 04:09:10 +00002519 return RegNum;
2520}
Jim Grosbach99710a82010-11-01 16:44:21 +00002521
Jim Grosbachbb24c592011-07-13 18:49:30 +00002522// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2523// If a recoverable error occurs, return 1. If an irrecoverable error
2524// occurs, return -1. An irrecoverable error is one where tokens have been
2525// consumed in the process of trying to parse the shifter (i.e., when it is
2526// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002527int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002528 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2529 SMLoc S = Parser.getTok().getLoc();
2530 const AsmToken &Tok = Parser.getTok();
2531 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2532
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002533 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002534 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002535 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002536 .Case("lsl", ARM_AM::lsl)
2537 .Case("lsr", ARM_AM::lsr)
2538 .Case("asr", ARM_AM::asr)
2539 .Case("ror", ARM_AM::ror)
2540 .Case("rrx", ARM_AM::rrx)
2541 .Default(ARM_AM::no_shift);
2542
2543 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002544 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002545
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002546 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002547
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002548 // The source register for the shift has already been added to the
2549 // operand list, so we need to pop it off and combine it into the shifted
2550 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002551 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002552 if (!PrevOp->isReg())
2553 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2554 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002555
2556 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002557 int64_t Imm = 0;
2558 int ShiftReg = 0;
2559 if (ShiftTy == ARM_AM::rrx) {
2560 // RRX Doesn't have an explicit shift amount. The encoder expects
2561 // the shift register to be the same as the source register. Seems odd,
2562 // but OK.
2563 ShiftReg = SrcReg;
2564 } else {
2565 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002566 if (Parser.getTok().is(AsmToken::Hash) ||
2567 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002568 Parser.Lex(); // Eat hash.
2569 SMLoc ImmLoc = Parser.getTok().getLoc();
2570 const MCExpr *ShiftExpr = 0;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002571 if (getParser().ParseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002572 Error(ImmLoc, "invalid immediate shift value");
2573 return -1;
2574 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002575 // The expression must be evaluatable as an immediate.
2576 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002577 if (!CE) {
2578 Error(ImmLoc, "invalid immediate shift value");
2579 return -1;
2580 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002581 // Range check the immediate.
2582 // lsl, ror: 0 <= imm <= 31
2583 // lsr, asr: 0 <= imm <= 32
2584 Imm = CE->getValue();
2585 if (Imm < 0 ||
2586 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2587 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002588 Error(ImmLoc, "immediate shift value out of range");
2589 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002590 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002591 // shift by zero is a nop. Always send it through as lsl.
2592 // ('as' compatibility)
2593 if (Imm == 0)
2594 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002595 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002596 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002597 EndLoc = Parser.getTok().getEndLoc();
2598 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002599 if (ShiftReg == -1) {
2600 Error (L, "expected immediate or register in shift operand");
2601 return -1;
2602 }
2603 } else {
2604 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002605 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002606 return -1;
2607 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002608 }
2609
Owen Andersonb595ed02011-07-21 18:54:16 +00002610 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2611 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002612 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002613 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002614 else
2615 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002616 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002617
Jim Grosbachbb24c592011-07-13 18:49:30 +00002618 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002619}
2620
2621
Bill Wendling2063b842010-11-18 23:43:05 +00002622/// Try to parse a register name. The token must be an Identifier when called.
2623/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2624/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002625///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002626/// TODO this is likely to change to allow different register types and or to
2627/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002628bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002629tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002630 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002631 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002632 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002633 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002634
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002635 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2636 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002637
Chris Lattner44e5981c2010-10-30 04:09:10 +00002638 const AsmToken &ExclaimTok = Parser.getTok();
2639 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002640 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2641 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002642 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002643 return false;
2644 }
2645
2646 // Also check for an index operand. This is only legal for vector registers,
2647 // but that'll get caught OK in operand matching, so we don't need to
2648 // explicitly filter everything else out here.
2649 if (Parser.getTok().is(AsmToken::LBrac)) {
2650 SMLoc SIdx = Parser.getTok().getLoc();
2651 Parser.Lex(); // Eat left bracket token.
2652
2653 const MCExpr *ImmVal;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002654 if (getParser().ParseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002655 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002656 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002657 if (!MCE)
2658 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002659
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002660 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002661 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002662
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002663 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002664 Parser.Lex(); // Eat right bracket token.
2665
2666 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2667 SIdx, E,
2668 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002669 }
2670
Bill Wendling2063b842010-11-18 23:43:05 +00002671 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002672}
2673
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002674/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2675/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2676/// "c5", ...
2677static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002678 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2679 // but efficient.
2680 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002681 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002682 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002683 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002684 return -1;
2685 switch (Name[1]) {
2686 default: return -1;
2687 case '0': return 0;
2688 case '1': return 1;
2689 case '2': return 2;
2690 case '3': return 3;
2691 case '4': return 4;
2692 case '5': return 5;
2693 case '6': return 6;
2694 case '7': return 7;
2695 case '8': return 8;
2696 case '9': return 9;
2697 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002698 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002699 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002700 return -1;
2701 switch (Name[2]) {
2702 default: return -1;
2703 case '0': return 10;
2704 case '1': return 11;
2705 case '2': return 12;
2706 case '3': return 13;
2707 case '4': return 14;
2708 case '5': return 15;
2709 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002710 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002711}
2712
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002713/// parseITCondCode - Try to parse a condition code for an IT instruction.
2714ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2715parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2716 SMLoc S = Parser.getTok().getLoc();
2717 const AsmToken &Tok = Parser.getTok();
2718 if (!Tok.is(AsmToken::Identifier))
2719 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002720 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002721 .Case("eq", ARMCC::EQ)
2722 .Case("ne", ARMCC::NE)
2723 .Case("hs", ARMCC::HS)
2724 .Case("cs", ARMCC::HS)
2725 .Case("lo", ARMCC::LO)
2726 .Case("cc", ARMCC::LO)
2727 .Case("mi", ARMCC::MI)
2728 .Case("pl", ARMCC::PL)
2729 .Case("vs", ARMCC::VS)
2730 .Case("vc", ARMCC::VC)
2731 .Case("hi", ARMCC::HI)
2732 .Case("ls", ARMCC::LS)
2733 .Case("ge", ARMCC::GE)
2734 .Case("lt", ARMCC::LT)
2735 .Case("gt", ARMCC::GT)
2736 .Case("le", ARMCC::LE)
2737 .Case("al", ARMCC::AL)
2738 .Default(~0U);
2739 if (CC == ~0U)
2740 return MatchOperand_NoMatch;
2741 Parser.Lex(); // Eat the token.
2742
2743 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2744
2745 return MatchOperand_Success;
2746}
2747
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002748/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002749/// token must be an Identifier when called, and if it is a coprocessor
2750/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002751ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002752parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002753 SMLoc S = Parser.getTok().getLoc();
2754 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002755 if (Tok.isNot(AsmToken::Identifier))
2756 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002757
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002758 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002759 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002760 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002761
2762 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002763 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002764 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002765}
2766
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002767/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002768/// token must be an Identifier when called, and if it is a coprocessor
2769/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002770ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002771parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002772 SMLoc S = Parser.getTok().getLoc();
2773 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002774 if (Tok.isNot(AsmToken::Identifier))
2775 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002776
2777 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2778 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002779 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002780
2781 Parser.Lex(); // Eat identifier token.
2782 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002783 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002784}
2785
Jim Grosbach48399582011-10-12 17:34:41 +00002786/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2787/// coproc_option : '{' imm0_255 '}'
2788ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2789parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2790 SMLoc S = Parser.getTok().getLoc();
2791
2792 // If this isn't a '{', this isn't a coprocessor immediate operand.
2793 if (Parser.getTok().isNot(AsmToken::LCurly))
2794 return MatchOperand_NoMatch;
2795 Parser.Lex(); // Eat the '{'
2796
2797 const MCExpr *Expr;
2798 SMLoc Loc = Parser.getTok().getLoc();
2799 if (getParser().ParseExpression(Expr)) {
2800 Error(Loc, "illegal expression");
2801 return MatchOperand_ParseFail;
2802 }
2803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2804 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2805 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2806 return MatchOperand_ParseFail;
2807 }
2808 int Val = CE->getValue();
2809
2810 // Check for and consume the closing '}'
2811 if (Parser.getTok().isNot(AsmToken::RCurly))
2812 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002813 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002814 Parser.Lex(); // Eat the '}'
2815
2816 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2817 return MatchOperand_Success;
2818}
2819
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002820// For register list parsing, we need to map from raw GPR register numbering
2821// to the enumeration values. The enumeration values aren't sorted by
2822// register number due to our using "sp", "lr" and "pc" as canonical names.
2823static unsigned getNextRegister(unsigned Reg) {
2824 // If this is a GPR, we need to do it manually, otherwise we can rely
2825 // on the sort ordering of the enumeration since the other reg-classes
2826 // are sane.
2827 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2828 return Reg + 1;
2829 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002830 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002831 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2832 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2833 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2834 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2835 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2836 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2837 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2838 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2839 }
2840}
2841
Jim Grosbach85a23432011-11-11 21:27:40 +00002842// Return the low-subreg of a given Q register.
2843static unsigned getDRegFromQReg(unsigned QReg) {
2844 switch (QReg) {
2845 default: llvm_unreachable("expected a Q register!");
2846 case ARM::Q0: return ARM::D0;
2847 case ARM::Q1: return ARM::D2;
2848 case ARM::Q2: return ARM::D4;
2849 case ARM::Q3: return ARM::D6;
2850 case ARM::Q4: return ARM::D8;
2851 case ARM::Q5: return ARM::D10;
2852 case ARM::Q6: return ARM::D12;
2853 case ARM::Q7: return ARM::D14;
2854 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002855 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002856 case ARM::Q10: return ARM::D20;
2857 case ARM::Q11: return ARM::D22;
2858 case ARM::Q12: return ARM::D24;
2859 case ARM::Q13: return ARM::D26;
2860 case ARM::Q14: return ARM::D28;
2861 case ARM::Q15: return ARM::D30;
2862 }
2863}
2864
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002865/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002866bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002867parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002868 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002869 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002870 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002871 Parser.Lex(); // Eat '{' token.
2872 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002873
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002874 // Check the first register in the list to see what register class
2875 // this is a list of.
2876 int Reg = tryParseRegister();
2877 if (Reg == -1)
2878 return Error(RegLoc, "register expected");
2879
Jim Grosbach85a23432011-11-11 21:27:40 +00002880 // The reglist instructions have at most 16 registers, so reserve
2881 // space for that many.
2882 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2883
2884 // Allow Q regs and just interpret them as the two D sub-registers.
2885 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2886 Reg = getDRegFromQReg(Reg);
2887 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2888 ++Reg;
2889 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002890 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002891 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2892 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2893 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2894 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2895 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2896 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2897 else
2898 return Error(RegLoc, "invalid register in register list");
2899
Jim Grosbach85a23432011-11-11 21:27:40 +00002900 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002901 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002902
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002903 // This starts immediately after the first register token in the list,
2904 // so we can see either a comma or a minus (range separator) as a legal
2905 // next token.
2906 while (Parser.getTok().is(AsmToken::Comma) ||
2907 Parser.getTok().is(AsmToken::Minus)) {
2908 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00002909 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002910 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002911 int EndReg = tryParseRegister();
2912 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002913 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002914 // Allow Q regs and just interpret them as the two D sub-registers.
2915 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2916 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002917 // If the register is the same as the start reg, there's nothing
2918 // more to do.
2919 if (Reg == EndReg)
2920 continue;
2921 // The register must be in the same register class as the first.
2922 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002923 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002924 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002925 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002926 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00002927
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002928 // Add all the registers in the range to the register list.
2929 while (Reg != EndReg) {
2930 Reg = getNextRegister(Reg);
2931 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2932 }
2933 continue;
2934 }
2935 Parser.Lex(); // Eat the comma.
2936 RegLoc = Parser.getTok().getLoc();
2937 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00002938 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002939 Reg = tryParseRegister();
2940 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00002941 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002942 // Allow Q regs and just interpret them as the two D sub-registers.
2943 bool isQReg = false;
2944 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2945 Reg = getDRegFromQReg(Reg);
2946 isQReg = true;
2947 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002948 // The register must be in the same register class as the first.
2949 if (!RC->contains(Reg))
2950 return Error(RegLoc, "invalid register in register list");
2951 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002952 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00002953 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2954 Warning(RegLoc, "register list not in ascending order");
2955 else
2956 return Error(RegLoc, "register list not in ascending order");
2957 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00002958 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00002959 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2960 ") in register list");
2961 continue;
2962 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002963 // VFP register lists must also be contiguous.
2964 // It's OK to use the enumeration values directly here rather, as the
2965 // VFP register classes have the enum sorted properly.
2966 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2967 Reg != OldReg + 1)
2968 return Error(RegLoc, "non-contiguous register range");
2969 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00002970 if (isQReg)
2971 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00002972 }
2973
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002974 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002975 return Error(Parser.getTok().getLoc(), "'}' expected");
2976 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002977 Parser.Lex(); // Eat '}' token.
2978
Jim Grosbach18bf3632011-12-13 21:48:29 +00002979 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00002980 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00002981
2982 // The ARM system instruction variants for LDM/STM have a '^' token here.
2983 if (Parser.getTok().is(AsmToken::Caret)) {
2984 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2985 Parser.Lex(); // Eat '^' token.
2986 }
2987
Bill Wendling2063b842010-11-18 23:43:05 +00002988 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00002989}
2990
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002991// Helper function to parse the lane index for vector lists.
2992ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002993parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002994 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002995 if (Parser.getTok().is(AsmToken::LBrac)) {
2996 Parser.Lex(); // Eat the '['.
2997 if (Parser.getTok().is(AsmToken::RBrac)) {
2998 // "Dn[]" is the 'all lanes' syntax.
2999 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003000 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003001 Parser.Lex(); // Eat the ']'.
3002 return MatchOperand_Success;
3003 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003004
3005 // There's an optional '#' token here. Normally there wouldn't be, but
3006 // inline assemble puts one in, and it's friendly to accept that.
3007 if (Parser.getTok().is(AsmToken::Hash))
3008 Parser.Lex(); // Eat the '#'
3009
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003010 const MCExpr *LaneIndex;
3011 SMLoc Loc = Parser.getTok().getLoc();
3012 if (getParser().ParseExpression(LaneIndex)) {
3013 Error(Loc, "illegal expression");
3014 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003015 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003016 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3017 if (!CE) {
3018 Error(Loc, "lane index must be empty or an integer");
3019 return MatchOperand_ParseFail;
3020 }
3021 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3022 Error(Parser.getTok().getLoc(), "']' expected");
3023 return MatchOperand_ParseFail;
3024 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003025 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003026 Parser.Lex(); // Eat the ']'.
3027 int64_t Val = CE->getValue();
3028
3029 // FIXME: Make this range check context sensitive for .8, .16, .32.
3030 if (Val < 0 || Val > 7) {
3031 Error(Parser.getTok().getLoc(), "lane index out of range");
3032 return MatchOperand_ParseFail;
3033 }
3034 Index = Val;
3035 LaneKind = IndexedLane;
3036 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003037 }
3038 LaneKind = NoLanes;
3039 return MatchOperand_Success;
3040}
3041
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003042// parse a vector register list
3043ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3044parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003045 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003046 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003047 SMLoc S = Parser.getTok().getLoc();
3048 // As an extension (to match gas), support a plain D register or Q register
3049 // (without encosing curly braces) as a single or double entry list,
3050 // respectively.
3051 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003052 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003053 int Reg = tryParseRegister();
3054 if (Reg == -1)
3055 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003056 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003057 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003058 if (Res != MatchOperand_Success)
3059 return Res;
3060 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003061 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003062 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003063 break;
3064 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003065 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3066 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003067 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003068 case IndexedLane:
3069 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003070 LaneIndex,
3071 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003072 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003073 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003074 return MatchOperand_Success;
3075 }
3076 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3077 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003078 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003079 if (Res != MatchOperand_Success)
3080 return Res;
3081 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003082 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003083 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003084 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003085 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003086 break;
3087 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003088 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3089 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003090 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3091 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003092 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003093 case IndexedLane:
3094 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003095 LaneIndex,
3096 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003097 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003098 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003099 return MatchOperand_Success;
3100 }
3101 Error(S, "vector register expected");
3102 return MatchOperand_ParseFail;
3103 }
3104
3105 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003106 return MatchOperand_NoMatch;
3107
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003108 Parser.Lex(); // Eat '{' token.
3109 SMLoc RegLoc = Parser.getTok().getLoc();
3110
3111 int Reg = tryParseRegister();
3112 if (Reg == -1) {
3113 Error(RegLoc, "register expected");
3114 return MatchOperand_ParseFail;
3115 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003116 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003117 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003118 unsigned FirstReg = Reg;
3119 // The list is of D registers, but we also allow Q regs and just interpret
3120 // them as the two D sub-registers.
3121 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3122 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003123 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3124 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003125 ++Reg;
3126 ++Count;
3127 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003128
3129 SMLoc E;
3130 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003131 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003132
Jim Grosbache891fe82011-11-15 23:19:15 +00003133 while (Parser.getTok().is(AsmToken::Comma) ||
3134 Parser.getTok().is(AsmToken::Minus)) {
3135 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003136 if (!Spacing)
3137 Spacing = 1; // Register range implies a single spaced list.
3138 else if (Spacing == 2) {
3139 Error(Parser.getTok().getLoc(),
3140 "sequential registers in double spaced list");
3141 return MatchOperand_ParseFail;
3142 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003143 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003144 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003145 int EndReg = tryParseRegister();
3146 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003147 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003148 return MatchOperand_ParseFail;
3149 }
3150 // Allow Q regs and just interpret them as the two D sub-registers.
3151 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3152 EndReg = getDRegFromQReg(EndReg) + 1;
3153 // If the register is the same as the start reg, there's nothing
3154 // more to do.
3155 if (Reg == EndReg)
3156 continue;
3157 // The register must be in the same register class as the first.
3158 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003159 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003160 return MatchOperand_ParseFail;
3161 }
3162 // Ranges must go from low to high.
3163 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003164 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003165 return MatchOperand_ParseFail;
3166 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003167 // Parse the lane specifier if present.
3168 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003169 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003170 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3171 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003172 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003173 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003174 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003175 return MatchOperand_ParseFail;
3176 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003177
3178 // Add all the registers in the range to the register list.
3179 Count += EndReg - Reg;
3180 Reg = EndReg;
3181 continue;
3182 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003183 Parser.Lex(); // Eat the comma.
3184 RegLoc = Parser.getTok().getLoc();
3185 int OldReg = Reg;
3186 Reg = tryParseRegister();
3187 if (Reg == -1) {
3188 Error(RegLoc, "register expected");
3189 return MatchOperand_ParseFail;
3190 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003191 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003192 // It's OK to use the enumeration values directly here rather, as the
3193 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003194 //
3195 // The list is of D registers, but we also allow Q regs and just interpret
3196 // them as the two D sub-registers.
3197 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003198 if (!Spacing)
3199 Spacing = 1; // Register range implies a single spaced list.
3200 else if (Spacing == 2) {
3201 Error(RegLoc,
3202 "invalid register in double-spaced list (must be 'D' register')");
3203 return MatchOperand_ParseFail;
3204 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003205 Reg = getDRegFromQReg(Reg);
3206 if (Reg != OldReg + 1) {
3207 Error(RegLoc, "non-contiguous register range");
3208 return MatchOperand_ParseFail;
3209 }
3210 ++Reg;
3211 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003212 // Parse the lane specifier if present.
3213 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003214 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003215 SMLoc LaneLoc = Parser.getTok().getLoc();
3216 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3217 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003219 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003220 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 return MatchOperand_ParseFail;
3222 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003223 continue;
3224 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003225 // Normal D register.
3226 // Figure out the register spacing (single or double) of the list if
3227 // we don't know it already.
3228 if (!Spacing)
3229 Spacing = 1 + (Reg == OldReg + 2);
3230
3231 // Just check that it's contiguous and keep going.
3232 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003233 Error(RegLoc, "non-contiguous register range");
3234 return MatchOperand_ParseFail;
3235 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003236 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003237 // Parse the lane specifier if present.
3238 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003239 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003240 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003241 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003242 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003243 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003244 Error(EndLoc, "mismatched lane index in register list");
3245 return MatchOperand_ParseFail;
3246 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003247 }
3248
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003249 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003250 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003251 return MatchOperand_ParseFail;
3252 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003253 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003254 Parser.Lex(); // Eat '}' token.
3255
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003256 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003257 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003258 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003259 // composite register classes.
3260 if (Count == 2) {
3261 const MCRegisterClass *RC = (Spacing == 1) ?
3262 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3263 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3264 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3265 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003266
Jim Grosbach2f50e922011-12-15 21:44:33 +00003267 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3268 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003269 break;
3270 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003271 // Two-register operands have been converted to the
3272 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003273 if (Count == 2) {
3274 const MCRegisterClass *RC = (Spacing == 1) ?
3275 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3276 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003277 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3278 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003279 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003280 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003281 S, E));
3282 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003283 case IndexedLane:
3284 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003285 LaneIndex,
3286 (Spacing == 2),
3287 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003288 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003289 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003290 return MatchOperand_Success;
3291}
3292
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003293/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003294ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003295parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003296 SMLoc S = Parser.getTok().getLoc();
3297 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003298 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003299
Jiangning Liu288e1af2012-08-02 08:21:27 +00003300 if (Tok.is(AsmToken::Identifier)) {
3301 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003302
Jiangning Liu288e1af2012-08-02 08:21:27 +00003303 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3304 .Case("sy", ARM_MB::SY)
3305 .Case("st", ARM_MB::ST)
3306 .Case("sh", ARM_MB::ISH)
3307 .Case("ish", ARM_MB::ISH)
3308 .Case("shst", ARM_MB::ISHST)
3309 .Case("ishst", ARM_MB::ISHST)
3310 .Case("nsh", ARM_MB::NSH)
3311 .Case("un", ARM_MB::NSH)
3312 .Case("nshst", ARM_MB::NSHST)
3313 .Case("unst", ARM_MB::NSHST)
3314 .Case("osh", ARM_MB::OSH)
3315 .Case("oshst", ARM_MB::OSHST)
3316 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003317
Jiangning Liu288e1af2012-08-02 08:21:27 +00003318 if (Opt == ~0U)
3319 return MatchOperand_NoMatch;
3320
3321 Parser.Lex(); // Eat identifier token.
3322 } else if (Tok.is(AsmToken::Hash) ||
3323 Tok.is(AsmToken::Dollar) ||
3324 Tok.is(AsmToken::Integer)) {
3325 if (Parser.getTok().isNot(AsmToken::Integer))
3326 Parser.Lex(); // Eat the '#'.
3327 SMLoc Loc = Parser.getTok().getLoc();
3328
3329 const MCExpr *MemBarrierID;
3330 if (getParser().ParseExpression(MemBarrierID)) {
3331 Error(Loc, "illegal expression");
3332 return MatchOperand_ParseFail;
3333 }
3334
3335 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3336 if (!CE) {
3337 Error(Loc, "constant expression expected");
3338 return MatchOperand_ParseFail;
3339 }
3340
3341 int Val = CE->getValue();
3342 if (Val & ~0xf) {
3343 Error(Loc, "immediate value out of range");
3344 return MatchOperand_ParseFail;
3345 }
3346
3347 Opt = ARM_MB::RESERVED_0 + Val;
3348 } else
3349 return MatchOperand_ParseFail;
3350
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003351 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003352 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003353}
3354
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003355/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003356ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003357parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003358 SMLoc S = Parser.getTok().getLoc();
3359 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003360 if (!Tok.is(AsmToken::Identifier))
3361 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003362 StringRef IFlagsStr = Tok.getString();
3363
Owen Anderson10c5b122011-10-05 17:16:40 +00003364 // An iflags string of "none" is interpreted to mean that none of the AIF
3365 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003366 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003367 if (IFlagsStr != "none") {
3368 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3369 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3370 .Case("a", ARM_PROC::A)
3371 .Case("i", ARM_PROC::I)
3372 .Case("f", ARM_PROC::F)
3373 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003374
Owen Anderson10c5b122011-10-05 17:16:40 +00003375 // If some specific iflag is already set, it means that some letter is
3376 // present more than once, this is not acceptable.
3377 if (Flag == ~0U || (IFlags & Flag))
3378 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003379
Owen Anderson10c5b122011-10-05 17:16:40 +00003380 IFlags |= Flag;
3381 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003382 }
3383
3384 Parser.Lex(); // Eat identifier token.
3385 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3386 return MatchOperand_Success;
3387}
3388
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003389/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003390ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003391parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003392 SMLoc S = Parser.getTok().getLoc();
3393 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003394 if (!Tok.is(AsmToken::Identifier))
3395 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003396 StringRef Mask = Tok.getString();
3397
James Molloy21efa7d2011-09-28 14:21:38 +00003398 if (isMClass()) {
3399 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003400 std::string Name = Mask.lower();
3401 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003402 // Note: in the documentation:
3403 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3404 // for MSR APSR_nzcvq.
3405 // but we do make it an alias here. This is so to get the "mask encoding"
3406 // bits correct on MSR APSR writes.
3407 //
3408 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3409 // should really only be allowed when writing a special register. Note
3410 // they get dropped in the MRS instruction reading a special register as
3411 // the SYSm field is only 8 bits.
3412 //
3413 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3414 // includes the DSP extension but that is not checked.
3415 .Case("apsr", 0x800)
3416 .Case("apsr_nzcvq", 0x800)
3417 .Case("apsr_g", 0x400)
3418 .Case("apsr_nzcvqg", 0xc00)
3419 .Case("iapsr", 0x801)
3420 .Case("iapsr_nzcvq", 0x801)
3421 .Case("iapsr_g", 0x401)
3422 .Case("iapsr_nzcvqg", 0xc01)
3423 .Case("eapsr", 0x802)
3424 .Case("eapsr_nzcvq", 0x802)
3425 .Case("eapsr_g", 0x402)
3426 .Case("eapsr_nzcvqg", 0xc02)
3427 .Case("xpsr", 0x803)
3428 .Case("xpsr_nzcvq", 0x803)
3429 .Case("xpsr_g", 0x403)
3430 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003431 .Case("ipsr", 0x805)
3432 .Case("epsr", 0x806)
3433 .Case("iepsr", 0x807)
3434 .Case("msp", 0x808)
3435 .Case("psp", 0x809)
3436 .Case("primask", 0x810)
3437 .Case("basepri", 0x811)
3438 .Case("basepri_max", 0x812)
3439 .Case("faultmask", 0x813)
3440 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003441 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003442
James Molloy21efa7d2011-09-28 14:21:38 +00003443 if (FlagsVal == ~0U)
3444 return MatchOperand_NoMatch;
3445
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003446 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003447 // basepri, basepri_max and faultmask only valid for V7m.
3448 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003449
James Molloy21efa7d2011-09-28 14:21:38 +00003450 Parser.Lex(); // Eat identifier token.
3451 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3452 return MatchOperand_Success;
3453 }
3454
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003455 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3456 size_t Start = 0, Next = Mask.find('_');
3457 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003458 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003459 if (Next != StringRef::npos)
3460 Flags = Mask.slice(Next+1, Mask.size());
3461
3462 // FlagsVal contains the complete mask:
3463 // 3-0: Mask
3464 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3465 unsigned FlagsVal = 0;
3466
3467 if (SpecReg == "apsr") {
3468 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003469 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003470 .Case("g", 0x4) // same as CPSR_s
3471 .Case("nzcvqg", 0xc) // same as CPSR_fs
3472 .Default(~0U);
3473
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003474 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003475 if (!Flags.empty())
3476 return MatchOperand_NoMatch;
3477 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003478 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003479 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003480 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003481 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3482 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003483 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003484 for (int i = 0, e = Flags.size(); i != e; ++i) {
3485 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3486 .Case("c", 1)
3487 .Case("x", 2)
3488 .Case("s", 4)
3489 .Case("f", 8)
3490 .Default(~0U);
3491
3492 // If some specific flag is already set, it means that some letter is
3493 // present more than once, this is not acceptable.
3494 if (FlagsVal == ~0U || (FlagsVal & Flag))
3495 return MatchOperand_NoMatch;
3496 FlagsVal |= Flag;
3497 }
3498 } else // No match for special register.
3499 return MatchOperand_NoMatch;
3500
Owen Anderson03a173e2011-10-21 18:43:28 +00003501 // Special register without flags is NOT equivalent to "fc" flags.
3502 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3503 // two lines would enable gas compatibility at the expense of breaking
3504 // round-tripping.
3505 //
3506 // if (!FlagsVal)
3507 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003508
3509 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3510 if (SpecReg == "spsr")
3511 FlagsVal |= 16;
3512
3513 Parser.Lex(); // Eat identifier token.
3514 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3515 return MatchOperand_Success;
3516}
3517
Jim Grosbach27c1e252011-07-21 17:23:04 +00003518ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3519parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3520 int Low, int High) {
3521 const AsmToken &Tok = Parser.getTok();
3522 if (Tok.isNot(AsmToken::Identifier)) {
3523 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3524 return MatchOperand_ParseFail;
3525 }
3526 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003527 std::string LowerOp = Op.lower();
3528 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003529 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3530 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3531 return MatchOperand_ParseFail;
3532 }
3533 Parser.Lex(); // Eat shift type token.
3534
3535 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003536 if (Parser.getTok().isNot(AsmToken::Hash) &&
3537 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003538 Error(Parser.getTok().getLoc(), "'#' expected");
3539 return MatchOperand_ParseFail;
3540 }
3541 Parser.Lex(); // Eat hash token.
3542
3543 const MCExpr *ShiftAmount;
3544 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003545 SMLoc EndLoc;
3546 if (getParser().ParseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003547 Error(Loc, "illegal expression");
3548 return MatchOperand_ParseFail;
3549 }
3550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3551 if (!CE) {
3552 Error(Loc, "constant expression expected");
3553 return MatchOperand_ParseFail;
3554 }
3555 int Val = CE->getValue();
3556 if (Val < Low || Val > High) {
3557 Error(Loc, "immediate value out of range");
3558 return MatchOperand_ParseFail;
3559 }
3560
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003561 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003562
3563 return MatchOperand_Success;
3564}
3565
Jim Grosbach0a547702011-07-22 17:44:50 +00003566ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3567parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3568 const AsmToken &Tok = Parser.getTok();
3569 SMLoc S = Tok.getLoc();
3570 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003571 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003572 return MatchOperand_ParseFail;
3573 }
3574 int Val = StringSwitch<int>(Tok.getString())
3575 .Case("be", 1)
3576 .Case("le", 0)
3577 .Default(-1);
3578 Parser.Lex(); // Eat the token.
3579
3580 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003581 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003582 return MatchOperand_ParseFail;
3583 }
3584 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3585 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003586 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003587 return MatchOperand_Success;
3588}
3589
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003590/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3591/// instructions. Legal values are:
3592/// lsl #n 'n' in [0,31]
3593/// asr #n 'n' in [1,32]
3594/// n == 32 encoded as n == 0.
3595ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3596parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3597 const AsmToken &Tok = Parser.getTok();
3598 SMLoc S = Tok.getLoc();
3599 if (Tok.isNot(AsmToken::Identifier)) {
3600 Error(S, "shift operator 'asr' or 'lsl' expected");
3601 return MatchOperand_ParseFail;
3602 }
3603 StringRef ShiftName = Tok.getString();
3604 bool isASR;
3605 if (ShiftName == "lsl" || ShiftName == "LSL")
3606 isASR = false;
3607 else if (ShiftName == "asr" || ShiftName == "ASR")
3608 isASR = true;
3609 else {
3610 Error(S, "shift operator 'asr' or 'lsl' expected");
3611 return MatchOperand_ParseFail;
3612 }
3613 Parser.Lex(); // Eat the operator.
3614
3615 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003616 if (Parser.getTok().isNot(AsmToken::Hash) &&
3617 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003618 Error(Parser.getTok().getLoc(), "'#' expected");
3619 return MatchOperand_ParseFail;
3620 }
3621 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003622 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003623
3624 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003625 SMLoc EndLoc;
3626 if (getParser().ParseExpression(ShiftAmount, EndLoc)) {
3627 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003628 return MatchOperand_ParseFail;
3629 }
3630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3631 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003632 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003633 return MatchOperand_ParseFail;
3634 }
3635
3636 int64_t Val = CE->getValue();
3637 if (isASR) {
3638 // Shift amount must be in [1,32]
3639 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003640 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003641 return MatchOperand_ParseFail;
3642 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003643 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3644 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003645 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003646 return MatchOperand_ParseFail;
3647 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003648 if (Val == 32) Val = 0;
3649 } else {
3650 // Shift amount must be in [1,32]
3651 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003652 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003653 return MatchOperand_ParseFail;
3654 }
3655 }
3656
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003657 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003658
3659 return MatchOperand_Success;
3660}
3661
Jim Grosbach833b9d32011-07-27 20:15:40 +00003662/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3663/// of instructions. Legal values are:
3664/// ror #n 'n' in {0, 8, 16, 24}
3665ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3666parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3667 const AsmToken &Tok = Parser.getTok();
3668 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003669 if (Tok.isNot(AsmToken::Identifier))
3670 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003671 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003672 if (ShiftName != "ror" && ShiftName != "ROR")
3673 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003674 Parser.Lex(); // Eat the operator.
3675
3676 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003677 if (Parser.getTok().isNot(AsmToken::Hash) &&
3678 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003679 Error(Parser.getTok().getLoc(), "'#' expected");
3680 return MatchOperand_ParseFail;
3681 }
3682 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003683 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003684
3685 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003686 SMLoc EndLoc;
3687 if (getParser().ParseExpression(ShiftAmount, EndLoc)) {
3688 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003689 return MatchOperand_ParseFail;
3690 }
3691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3692 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003693 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003694 return MatchOperand_ParseFail;
3695 }
3696
3697 int64_t Val = CE->getValue();
3698 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3699 // normally, zero is represented in asm by omitting the rotate operand
3700 // entirely.
3701 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003702 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003703 return MatchOperand_ParseFail;
3704 }
3705
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003706 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003707
3708 return MatchOperand_Success;
3709}
3710
Jim Grosbach864b6092011-07-28 21:34:26 +00003711ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3712parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3713 SMLoc S = Parser.getTok().getLoc();
3714 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003715 if (Parser.getTok().isNot(AsmToken::Hash) &&
3716 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003717 Error(Parser.getTok().getLoc(), "'#' expected");
3718 return MatchOperand_ParseFail;
3719 }
3720 Parser.Lex(); // Eat hash token.
3721
3722 const MCExpr *LSBExpr;
3723 SMLoc E = Parser.getTok().getLoc();
3724 if (getParser().ParseExpression(LSBExpr)) {
3725 Error(E, "malformed immediate expression");
3726 return MatchOperand_ParseFail;
3727 }
3728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3729 if (!CE) {
3730 Error(E, "'lsb' operand must be an immediate");
3731 return MatchOperand_ParseFail;
3732 }
3733
3734 int64_t LSB = CE->getValue();
3735 // The LSB must be in the range [0,31]
3736 if (LSB < 0 || LSB > 31) {
3737 Error(E, "'lsb' operand must be in the range [0,31]");
3738 return MatchOperand_ParseFail;
3739 }
3740 E = Parser.getTok().getLoc();
3741
3742 // Expect another immediate operand.
3743 if (Parser.getTok().isNot(AsmToken::Comma)) {
3744 Error(Parser.getTok().getLoc(), "too few operands");
3745 return MatchOperand_ParseFail;
3746 }
3747 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003748 if (Parser.getTok().isNot(AsmToken::Hash) &&
3749 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003750 Error(Parser.getTok().getLoc(), "'#' expected");
3751 return MatchOperand_ParseFail;
3752 }
3753 Parser.Lex(); // Eat hash token.
3754
3755 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003756 SMLoc EndLoc;
3757 if (getParser().ParseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003758 Error(E, "malformed immediate expression");
3759 return MatchOperand_ParseFail;
3760 }
3761 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3762 if (!CE) {
3763 Error(E, "'width' operand must be an immediate");
3764 return MatchOperand_ParseFail;
3765 }
3766
3767 int64_t Width = CE->getValue();
3768 // The LSB must be in the range [1,32-lsb]
3769 if (Width < 1 || Width > 32 - LSB) {
3770 Error(E, "'width' operand must be in the range [1,32-lsb]");
3771 return MatchOperand_ParseFail;
3772 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003773
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003774 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003775
3776 return MatchOperand_Success;
3777}
3778
Jim Grosbachd3595712011-08-03 23:50:40 +00003779ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3780parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3781 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003782 // postidx_reg := '+' register {, shift}
3783 // | '-' register {, shift}
3784 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003785
3786 // This method must return MatchOperand_NoMatch without consuming any tokens
3787 // in the case where there is no match, as other alternatives take other
3788 // parse methods.
3789 AsmToken Tok = Parser.getTok();
3790 SMLoc S = Tok.getLoc();
3791 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003792 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003793 if (Tok.is(AsmToken::Plus)) {
3794 Parser.Lex(); // Eat the '+' token.
3795 haveEaten = true;
3796 } else if (Tok.is(AsmToken::Minus)) {
3797 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003798 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003799 haveEaten = true;
3800 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003801
3802 SMLoc E = Parser.getTok().getEndLoc();
3803 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003804 if (Reg == -1) {
3805 if (!haveEaten)
3806 return MatchOperand_NoMatch;
3807 Error(Parser.getTok().getLoc(), "register expected");
3808 return MatchOperand_ParseFail;
3809 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003810
Jim Grosbachc320c852011-08-05 21:28:30 +00003811 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3812 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003813 if (Parser.getTok().is(AsmToken::Comma)) {
3814 Parser.Lex(); // Eat the ','.
3815 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3816 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003817
3818 // FIXME: Only approximates end...may include intervening whitespace.
3819 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003820 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003821
3822 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3823 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003824
3825 return MatchOperand_Success;
3826}
3827
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003828ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3829parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3830 // Check for a post-index addressing register operand. Specifically:
3831 // am3offset := '+' register
3832 // | '-' register
3833 // | register
3834 // | # imm
3835 // | # + imm
3836 // | # - imm
3837
3838 // This method must return MatchOperand_NoMatch without consuming any tokens
3839 // in the case where there is no match, as other alternatives take other
3840 // parse methods.
3841 AsmToken Tok = Parser.getTok();
3842 SMLoc S = Tok.getLoc();
3843
3844 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003845 if (Parser.getTok().is(AsmToken::Hash) ||
3846 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003847 Parser.Lex(); // Eat the '#'.
3848 // Explicitly look for a '-', as we need to encode negative zero
3849 // differently.
3850 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3851 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003852 SMLoc E;
3853 if (getParser().ParseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003854 return MatchOperand_ParseFail;
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3856 if (!CE) {
3857 Error(S, "constant expression expected");
3858 return MatchOperand_ParseFail;
3859 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003860 // Negative zero is encoded as the flag value INT32_MIN.
3861 int32_t Val = CE->getValue();
3862 if (isNegative && Val == 0)
3863 Val = INT32_MIN;
3864
3865 Operands.push_back(
3866 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3867
3868 return MatchOperand_Success;
3869 }
3870
3871
3872 bool haveEaten = false;
3873 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003874 if (Tok.is(AsmToken::Plus)) {
3875 Parser.Lex(); // Eat the '+' token.
3876 haveEaten = true;
3877 } else if (Tok.is(AsmToken::Minus)) {
3878 Parser.Lex(); // Eat the '-' token.
3879 isAdd = false;
3880 haveEaten = true;
3881 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003882
3883 Tok = Parser.getTok();
3884 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003885 if (Reg == -1) {
3886 if (!haveEaten)
3887 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003888 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003889 return MatchOperand_ParseFail;
3890 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003891
3892 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003893 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003894
3895 return MatchOperand_Success;
3896}
3897
Jim Grosbach7db8d692011-09-08 22:07:06 +00003898/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3899/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3900/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003901void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003902cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003903 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3904 // Rt, Rt2
3905 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3906 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3907 // Create a writeback register dummy placeholder.
3908 Inst.addOperand(MCOperand::CreateReg(0));
3909 // addr
3910 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3911 // pred
3912 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003913}
3914
3915/// cvtT2StrdPre - Convert parsed operands to MCInst.
3916/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3917/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003918void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003919cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003920 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3921 // Create a writeback register dummy placeholder.
3922 Inst.addOperand(MCOperand::CreateReg(0));
3923 // Rt, Rt2
3924 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3925 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3926 // addr
3927 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3928 // pred
3929 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003930}
3931
Jim Grosbachc086f682011-09-08 00:39:19 +00003932/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3933/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3934/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003935void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003936cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00003937 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3938 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3939
3940 // Create a writeback register dummy placeholder.
3941 Inst.addOperand(MCOperand::CreateImm(0));
3942
3943 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3944 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00003945}
3946
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003947/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3948/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3949/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003950void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003951cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003952 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3953 // Create a writeback register dummy placeholder.
3954 Inst.addOperand(MCOperand::CreateImm(0));
3955 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3956 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3957 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003958}
3959
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003960/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003961/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3962/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003963void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003964cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003965 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3966 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3967
3968 // Create a writeback register dummy placeholder.
3969 Inst.addOperand(MCOperand::CreateImm(0));
3970
Jim Grosbachd3595712011-08-03 23:50:40 +00003971 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003972 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003973}
3974
Owen Anderson16d33f32011-08-26 20:43:14 +00003975/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3976/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3977/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003978void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003979cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00003980 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3981 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3982
3983 // Create a writeback register dummy placeholder.
3984 Inst.addOperand(MCOperand::CreateImm(0));
3985
3986 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3987 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00003988}
3989
3990
Jim Grosbachd564bf32011-08-11 19:22:40 +00003991/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3992/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3993/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003994void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003995cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00003996 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3997 // Create a writeback register dummy placeholder.
3998 Inst.addOperand(MCOperand::CreateImm(0));
3999 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4000 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4001 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00004002}
4003
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004004/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004005/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4006/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004007void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004008cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004009 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4010 // Create a writeback register dummy placeholder.
4011 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00004012 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4013 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4014 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004015}
4016
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004017/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4018/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4019/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004020void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004021cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004022 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4023 // Create a writeback register dummy placeholder.
4024 Inst.addOperand(MCOperand::CreateImm(0));
4025 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4026 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4027 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004028}
4029
Jim Grosbachd3595712011-08-03 23:50:40 +00004030/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4031/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4032/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004033void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004034cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004035 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4036 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004037 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004038 // Create a writeback register dummy placeholder.
4039 Inst.addOperand(MCOperand::CreateImm(0));
4040 // addr
4041 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4042 // offset
4043 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4044 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004045 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004046}
4047
Jim Grosbachd3595712011-08-03 23:50:40 +00004048/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004049/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4050/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004051void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004052cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004053 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4054 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004055 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004056 // Create a writeback register dummy placeholder.
4057 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004058 // addr
4059 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4060 // offset
4061 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4062 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004063 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004064}
4065
Jim Grosbachd3595712011-08-03 23:50:40 +00004066/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004067/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4068/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004069void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004070cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004071 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004072 // Create a writeback register dummy placeholder.
4073 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004074 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004075 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004076 // addr
4077 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4078 // offset
4079 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4080 // pred
4081 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004082}
4083
4084/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4085/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4086/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004087void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004088cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004089 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4090 // Create a writeback register dummy placeholder.
4091 Inst.addOperand(MCOperand::CreateImm(0));
4092 // Rt
4093 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4094 // addr
4095 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4096 // offset
4097 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4098 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004099 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004100}
4101
Jim Grosbach5b96b802011-08-10 20:29:19 +00004102/// cvtLdrdPre - Convert parsed operands to MCInst.
4103/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4104/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004105void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004106cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004107 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4108 // Rt, Rt2
4109 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4110 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4111 // Create a writeback register dummy placeholder.
4112 Inst.addOperand(MCOperand::CreateImm(0));
4113 // addr
4114 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4115 // pred
4116 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004117}
4118
Jim Grosbacheb09f492011-08-11 20:28:23 +00004119/// cvtStrdPre - Convert parsed operands to MCInst.
4120/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4121/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004122void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004123cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004124 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4125 // Create a writeback register dummy placeholder.
4126 Inst.addOperand(MCOperand::CreateImm(0));
4127 // Rt, Rt2
4128 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4129 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4130 // addr
4131 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4132 // pred
4133 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004134}
4135
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004136/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4137/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4138/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004139void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004140cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004141 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4142 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4143 // Create a writeback register dummy placeholder.
4144 Inst.addOperand(MCOperand::CreateImm(0));
4145 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4146 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004147}
4148
Chad Rosier5eec49f2012-08-30 23:00:00 +00004149/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004150/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4151/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004152void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004153cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004154 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004155 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4156 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004157 // If we have a three-operand form, make sure to set Rn to be the operand
4158 // that isn't the same as Rd.
4159 unsigned RegOp = 4;
4160 if (Operands.size() == 6 &&
4161 ((ARMOperand*)Operands[4])->getReg() ==
4162 ((ARMOperand*)Operands[3])->getReg())
4163 RegOp = 5;
4164 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4165 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004166 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004167}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004168
Chad Rosier98cfa102012-08-31 00:03:31 +00004169void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004170cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004171 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4172 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004173 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004174 // Create a writeback register dummy placeholder.
4175 Inst.addOperand(MCOperand::CreateImm(0));
4176 // Vn
4177 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4178 // pred
4179 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004180}
4181
Chad Rosier98cfa102012-08-31 00:03:31 +00004182void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004183cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004184 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4185 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004186 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004187 // Create a writeback register dummy placeholder.
4188 Inst.addOperand(MCOperand::CreateImm(0));
4189 // Vn
4190 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4191 // Vm
4192 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4193 // pred
4194 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004195}
4196
Chad Rosier98cfa102012-08-31 00:03:31 +00004197void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004198cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004199 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4200 // Create a writeback register dummy placeholder.
4201 Inst.addOperand(MCOperand::CreateImm(0));
4202 // Vn
4203 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4204 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004205 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004206 // pred
4207 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004208}
4209
Chad Rosier98cfa102012-08-31 00:03:31 +00004210void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004211cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004212 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4213 // Create a writeback register dummy placeholder.
4214 Inst.addOperand(MCOperand::CreateImm(0));
4215 // Vn
4216 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4217 // Vm
4218 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4219 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004220 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004221 // pred
4222 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004223}
4224
Bill Wendlinge18980a2010-11-06 22:36:58 +00004225/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004226/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004227bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004228parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004229 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004230 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004231 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004232 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004233 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004234
Sean Callanan936b0d32010-01-19 21:44:56 +00004235 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004236 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004237 if (BaseRegNum == -1)
4238 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004239
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004240 // The next token must either be a comma or a closing bracket.
4241 const AsmToken &Tok = Parser.getTok();
4242 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004243 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004244
Jim Grosbachd3595712011-08-03 23:50:40 +00004245 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004246 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004247 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004248
Jim Grosbachd3595712011-08-03 23:50:40 +00004249 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004250 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004251
Jim Grosbach40700e02011-09-19 18:42:21 +00004252 // If there's a pre-indexing writeback marker, '!', just add it as a token
4253 // operand. It's rather odd, but syntactically valid.
4254 if (Parser.getTok().is(AsmToken::Exclaim)) {
4255 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4256 Parser.Lex(); // Eat the '!'.
4257 }
4258
Jim Grosbachd3595712011-08-03 23:50:40 +00004259 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004260 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004261
Jim Grosbachd3595712011-08-03 23:50:40 +00004262 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4263 Parser.Lex(); // Eat the comma.
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004264
Jim Grosbacha95ec992011-10-11 17:29:55 +00004265 // If we have a ':', it's an alignment specifier.
4266 if (Parser.getTok().is(AsmToken::Colon)) {
4267 Parser.Lex(); // Eat the ':'.
4268 E = Parser.getTok().getLoc();
4269
4270 const MCExpr *Expr;
4271 if (getParser().ParseExpression(Expr))
4272 return true;
4273
4274 // The expression has to be a constant. Memory references with relocations
4275 // don't come through here, as they use the <label> forms of the relevant
4276 // instructions.
4277 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4278 if (!CE)
4279 return Error (E, "constant expression expected");
4280
4281 unsigned Align = 0;
4282 switch (CE->getValue()) {
4283 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004284 return Error(E,
4285 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4286 case 16: Align = 2; break;
4287 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004288 case 64: Align = 8; break;
4289 case 128: Align = 16; break;
4290 case 256: Align = 32; break;
4291 }
4292
4293 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004294 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004295 return Error(Parser.getTok().getLoc(), "']' expected");
4296 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004297 Parser.Lex(); // Eat right bracket token.
4298
4299 // Don't worry about range checking the value here. That's handled by
4300 // the is*() predicates.
4301 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4302 ARM_AM::no_shift, 0, Align,
4303 false, S, E));
4304
4305 // If there's a pre-indexing writeback marker, '!', just add it as a token
4306 // operand.
4307 if (Parser.getTok().is(AsmToken::Exclaim)) {
4308 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4309 Parser.Lex(); // Eat the '!'.
4310 }
4311
4312 return false;
4313 }
4314
4315 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004316 // offset. Be friendly and also accept a plain integer (without a leading
4317 // hash) for gas compatibility.
4318 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004319 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004320 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004321 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach8279c182011-11-15 22:14:41 +00004322 Parser.Lex(); // Eat the '#'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004323 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004324
Owen Anderson967674d2011-08-29 19:36:44 +00004325 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004326 const MCExpr *Offset;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004327 if (getParser().ParseExpression(Offset))
4328 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004329
4330 // The expression has to be a constant. Memory references with relocations
4331 // don't come through here, as they use the <label> forms of the relevant
4332 // instructions.
4333 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4334 if (!CE)
4335 return Error (E, "constant expression expected");
4336
Owen Anderson967674d2011-08-29 19:36:44 +00004337 // If the constant was #-0, represent it as INT32_MIN.
4338 int32_t Val = CE->getValue();
4339 if (isNegative && Val == 0)
4340 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4341
Jim Grosbachd3595712011-08-03 23:50:40 +00004342 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004343 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004344 return Error(Parser.getTok().getLoc(), "']' expected");
4345 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004346 Parser.Lex(); // Eat right bracket token.
4347
4348 // Don't worry about range checking the value here. That's handled by
4349 // the is*() predicates.
4350 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004351 ARM_AM::no_shift, 0, 0,
4352 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004353
4354 // If there's a pre-indexing writeback marker, '!', just add it as a token
4355 // operand.
4356 if (Parser.getTok().is(AsmToken::Exclaim)) {
4357 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4358 Parser.Lex(); // Eat the '!'.
4359 }
4360
4361 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004362 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004363
4364 // The register offset is optionally preceded by a '+' or '-'
4365 bool isNegative = false;
4366 if (Parser.getTok().is(AsmToken::Minus)) {
4367 isNegative = true;
4368 Parser.Lex(); // Eat the '-'.
4369 } else if (Parser.getTok().is(AsmToken::Plus)) {
4370 // Nothing to do.
4371 Parser.Lex(); // Eat the '+'.
4372 }
4373
4374 E = Parser.getTok().getLoc();
4375 int OffsetRegNum = tryParseRegister();
4376 if (OffsetRegNum == -1)
4377 return Error(E, "register expected");
4378
4379 // If there's a shift operator, handle it.
4380 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004381 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004382 if (Parser.getTok().is(AsmToken::Comma)) {
4383 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004384 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004385 return true;
4386 }
4387
4388 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004389 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004390 return Error(Parser.getTok().getLoc(), "']' expected");
4391 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004392 Parser.Lex(); // Eat right bracket token.
4393
4394 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004395 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004396 S, E));
4397
Jim Grosbachc320c852011-08-05 21:28:30 +00004398 // If there's a pre-indexing writeback marker, '!', just add it as a token
4399 // operand.
4400 if (Parser.getTok().is(AsmToken::Exclaim)) {
4401 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4402 Parser.Lex(); // Eat the '!'.
4403 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004404
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 return false;
4406}
4407
Jim Grosbachd3595712011-08-03 23:50:40 +00004408/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409/// ( lsl | lsr | asr | ror ) , # shift_amount
4410/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004411/// return true if it parses a shift otherwise it returns false.
4412bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4413 unsigned &Amount) {
4414 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004415 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004416 if (Tok.isNot(AsmToken::Identifier))
4417 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004418 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004419 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4420 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004421 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004422 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004423 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004424 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004425 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004426 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004427 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004428 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004429 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004430 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004431 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004432 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004433
Jim Grosbachd3595712011-08-03 23:50:40 +00004434 // rrx stands alone.
4435 Amount = 0;
4436 if (St != ARM_AM::rrx) {
4437 Loc = Parser.getTok().getLoc();
4438 // A '#' and a shift amount.
4439 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004440 if (HashTok.isNot(AsmToken::Hash) &&
4441 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004442 return Error(HashTok.getLoc(), "'#' expected");
4443 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004444
Jim Grosbachd3595712011-08-03 23:50:40 +00004445 const MCExpr *Expr;
4446 if (getParser().ParseExpression(Expr))
4447 return true;
4448 // Range check the immediate.
4449 // lsl, ror: 0 <= imm <= 31
4450 // lsr, asr: 0 <= imm <= 32
4451 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4452 if (!CE)
4453 return Error(Loc, "shift amount must be an immediate");
4454 int64_t Imm = CE->getValue();
4455 if (Imm < 0 ||
4456 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4457 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4458 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004459 // If <ShiftTy> #0, turn it into a no_shift.
4460 if (Imm == 0)
4461 St = ARM_AM::lsl;
4462 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4463 if (Imm == 32)
4464 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004465 Amount = Imm;
4466 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004467
4468 return false;
4469}
4470
Jim Grosbache7fbce72011-10-03 23:38:36 +00004471/// parseFPImm - A floating point immediate expression operand.
4472ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4473parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004474 // Anything that can accept a floating point constant as an operand
4475 // needs to go through here, as the regular ParseExpression is
4476 // integer only.
4477 //
4478 // This routine still creates a generic Immediate operand, containing
4479 // a bitcast of the 64-bit floating point value. The various operands
4480 // that accept floats can check whether the value is valid for them
4481 // via the standard is*() predicates.
4482
Jim Grosbache7fbce72011-10-03 23:38:36 +00004483 SMLoc S = Parser.getTok().getLoc();
4484
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004485 if (Parser.getTok().isNot(AsmToken::Hash) &&
4486 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004487 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004488
4489 // Disambiguate the VMOV forms that can accept an FP immediate.
4490 // vmov.f32 <sreg>, #imm
4491 // vmov.f64 <dreg>, #imm
4492 // vmov.f32 <dreg>, #imm @ vector f32x2
4493 // vmov.f32 <qreg>, #imm @ vector f32x4
4494 //
4495 // There are also the NEON VMOV instructions which expect an
4496 // integer constant. Make sure we don't try to parse an FPImm
4497 // for these:
4498 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4499 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4500 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4501 TyOp->getToken() != ".f64"))
4502 return MatchOperand_NoMatch;
4503
Jim Grosbache7fbce72011-10-03 23:38:36 +00004504 Parser.Lex(); // Eat the '#'.
4505
4506 // Handle negation, as that still comes through as a separate token.
4507 bool isNegative = false;
4508 if (Parser.getTok().is(AsmToken::Minus)) {
4509 isNegative = true;
4510 Parser.Lex();
4511 }
4512 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004513 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004514 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004515 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004516 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4517 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004518 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004519 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004520 Operands.push_back(ARMOperand::CreateImm(
4521 MCConstantExpr::Create(IntVal, getContext()),
4522 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004523 return MatchOperand_Success;
4524 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004525 // Also handle plain integers. Instructions which allow floating point
4526 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004527 if (Tok.is(AsmToken::Integer)) {
4528 int64_t Val = Tok.getIntVal();
4529 Parser.Lex(); // Eat the token.
4530 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004531 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004532 return MatchOperand_ParseFail;
4533 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004534 double RealVal = ARM_AM::getFPImmFloat(Val);
4535 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4536 Operands.push_back(ARMOperand::CreateImm(
4537 MCConstantExpr::Create(Val, getContext()), S,
4538 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004539 return MatchOperand_Success;
4540 }
4541
Jim Grosbach235c8d22012-01-19 02:47:30 +00004542 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004543 return MatchOperand_ParseFail;
4544}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004545
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004546/// Parse a arm instruction operand. For now this parses the operand regardless
4547/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004548bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004549 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004550 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004551
4552 // Check if the current operand has a custom associated parser, if so, try to
4553 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004554 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4555 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004556 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004557 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4558 // there was a match, but an error occurred, in which case, just return that
4559 // the operand parsing failed.
4560 if (ResTy == MatchOperand_ParseFail)
4561 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004562
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004563 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004564 default:
4565 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004566 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004567 case AsmToken::Identifier: {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004568 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling2063b842010-11-18 23:43:05 +00004569 return false;
Jim Grosbach0d6022d2011-07-26 20:41:24 +00004570 int Res = tryParseShiftRegister(Operands);
Jim Grosbachbb24c592011-07-13 18:49:30 +00004571 if (Res == 0) // success
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004572 return false;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004573 else if (Res == -1) // irrecoverable error
4574 return true;
Jim Grosbach4eda1452011-12-20 22:26:38 +00004575 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachd28888d2012-03-15 21:34:14 +00004576 if (Mnemonic == "vmrs" &&
4577 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004578 S = Parser.getTok().getLoc();
4579 Parser.Lex();
Jim Grosbachd28888d2012-03-15 21:34:14 +00004580 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004581 return false;
4582 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004583
4584 // Fall though for the Identifier case that is not a register or a
4585 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004586 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004587 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004588 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004589 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004590 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004591 // This was not a register so parse other operands that start with an
4592 // identifier (like labels) as expressions and create them as immediates.
4593 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004594 S = Parser.getTok().getLoc();
Kevin Enderby146dcf22009-10-15 20:48:48 +00004595 if (getParser().ParseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004596 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004597 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004598 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4599 return false;
4600 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004601 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004602 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004603 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004604 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004605 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004606 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004607 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004608 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004609 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004610
4611 if (Parser.getTok().isNot(AsmToken::Colon)) {
4612 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4613 const MCExpr *ImmVal;
4614 if (getParser().ParseExpression(ImmVal))
4615 return true;
4616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4617 if (CE) {
4618 int32_t Val = CE->getValue();
4619 if (isNegative && Val == 0)
4620 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4621 }
4622 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4623 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4624 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004625 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004626 // w/ a ':' after the '#', it's just like a plain ':'.
4627 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004628 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004629 case AsmToken::Colon: {
4630 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004631 // FIXME: Check it's an expression prefix,
4632 // e.g. (FOO - :lower16:BAR) isn't legal.
4633 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004634 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004635 return true;
4636
Evan Cheng965b3c72011-01-13 07:58:56 +00004637 const MCExpr *SubExprVal;
4638 if (getParser().ParseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004639 return true;
4640
Evan Cheng965b3c72011-01-13 07:58:56 +00004641 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004642 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004643 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004644 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004645 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004646 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004647 }
4648}
4649
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004650// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004651// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004652bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004653 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004654
4655 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004656 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004657 Parser.Lex(); // Eat ':'
4658
4659 if (getLexer().isNot(AsmToken::Identifier)) {
4660 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4661 return true;
4662 }
4663
4664 StringRef IDVal = Parser.getTok().getIdentifier();
4665 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004666 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004667 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004668 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004669 } else {
4670 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4671 return true;
4672 }
4673 Parser.Lex();
4674
4675 if (getLexer().isNot(AsmToken::Colon)) {
4676 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4677 return true;
4678 }
4679 Parser.Lex(); // Eat the last ':'
4680 return false;
4681}
4682
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004683/// \brief Given a mnemonic, split out possible predication code and carry
4684/// setting letters to form a canonical mnemonic and flags.
4685//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004686// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004687// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004688StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004689 unsigned &PredicationCode,
4690 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004691 unsigned &ProcessorIMod,
4692 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004693 PredicationCode = ARMCC::AL;
4694 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004695 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004696
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004697 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004698 //
4699 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004700 if ((Mnemonic == "movs" && isThumb()) ||
4701 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4702 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4703 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4704 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4705 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4706 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004707 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4708 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004709 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004710
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004711 // First, split out any predication code. Ignore mnemonics we know aren't
4712 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004713 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004714 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004715 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004716 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004717 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4718 .Case("eq", ARMCC::EQ)
4719 .Case("ne", ARMCC::NE)
4720 .Case("hs", ARMCC::HS)
4721 .Case("cs", ARMCC::HS)
4722 .Case("lo", ARMCC::LO)
4723 .Case("cc", ARMCC::LO)
4724 .Case("mi", ARMCC::MI)
4725 .Case("pl", ARMCC::PL)
4726 .Case("vs", ARMCC::VS)
4727 .Case("vc", ARMCC::VC)
4728 .Case("hi", ARMCC::HI)
4729 .Case("ls", ARMCC::LS)
4730 .Case("ge", ARMCC::GE)
4731 .Case("lt", ARMCC::LT)
4732 .Case("gt", ARMCC::GT)
4733 .Case("le", ARMCC::LE)
4734 .Case("al", ARMCC::AL)
4735 .Default(~0U);
4736 if (CC != ~0U) {
4737 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4738 PredicationCode = CC;
4739 }
Bill Wendling193961b2010-10-29 23:50:21 +00004740 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004741
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004742 // Next, determine if we have a carry setting bit. We explicitly ignore all
4743 // the instructions we know end in 's'.
4744 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004745 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004746 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4747 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4748 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004749 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004750 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004751 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004752 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004753 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004754 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004755 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4756 CarrySetting = true;
4757 }
4758
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004759 // The "cps" instruction can have a interrupt mode operand which is glued into
4760 // the mnemonic. Check if this is the case, split it and parse the imod op
4761 if (Mnemonic.startswith("cps")) {
4762 // Split out any imod code.
4763 unsigned IMod =
4764 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4765 .Case("ie", ARM_PROC::IE)
4766 .Case("id", ARM_PROC::ID)
4767 .Default(~0U);
4768 if (IMod != ~0U) {
4769 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4770 ProcessorIMod = IMod;
4771 }
4772 }
4773
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004774 // The "it" instruction has the condition mask on the end of the mnemonic.
4775 if (Mnemonic.startswith("it")) {
4776 ITMask = Mnemonic.slice(2, Mnemonic.size());
4777 Mnemonic = Mnemonic.slice(0, 2);
4778 }
4779
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004780 return Mnemonic;
4781}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004782
4783/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4784/// inclusion of carry set or predication code operands.
4785//
4786// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004787void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004788getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004789 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004790 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4791 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004792 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004793 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004794 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004795 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004796 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004797 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004798 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004799 Mnemonic == "mla" || Mnemonic == "smlal" ||
4800 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004801 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004802 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004803 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004804
Daniel Dunbar09264122011-01-11 19:06:29 +00004805 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4806 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4807 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4808 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004809 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4810 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004811 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004812 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4813 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4814 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004815 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4816 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004817 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004818 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004819 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004820 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004821
Jim Grosbach6c45b752011-09-16 16:39:25 +00004822 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004823 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004824 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004825 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004826 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004827}
4828
Jim Grosbach7283da92011-08-16 21:12:37 +00004829bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4830 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004831 // FIXME: This is all horribly hacky. We really need a better way to deal
4832 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004833
4834 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4835 // another does not. Specifically, the MOVW instruction does not. So we
4836 // special case it here and remove the defaulted (non-setting) cc_out
4837 // operand if that's the instruction we're trying to match.
4838 //
4839 // We do this as post-processing of the explicit operands rather than just
4840 // conditionally adding the cc_out in the first place because we need
4841 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004842 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004843 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4844 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4845 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4846 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004847
4848 // Register-register 'add' for thumb does not have a cc_out operand
4849 // when there are only two register operands.
4850 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4851 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4852 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4853 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4854 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004855 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004856 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4857 // have to check the immediate range here since Thumb2 has a variant
4858 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004859 if (((isThumb() && Mnemonic == "add") ||
4860 (isThumbTwo() && Mnemonic == "sub")) &&
4861 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004862 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4863 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4864 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004865 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004866 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004867 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004868 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004869 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4870 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004871 // selecting via the generic "add" mnemonic, so to know that we
4872 // should remove the cc_out operand, we have to explicitly check that
4873 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004874 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4875 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004876 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4877 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4878 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4879 // Nest conditions rather than one big 'if' statement for readability.
4880 //
4881 // If either register is a high reg, it's either one of the SP
4882 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004883 // check against T3. If the second register is the PC, this is an
4884 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004885 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4886 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004887 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004888 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4889 return false;
4890 // If both registers are low, we're in an IT block, and the immediate is
4891 // in range, we should use encoding T1 instead, which has a cc_out.
4892 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004893 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004894 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4895 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4896 return false;
4897
4898 // Otherwise, we use encoding T4, which does not have a cc_out
4899 // operand.
4900 return true;
4901 }
4902
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004903 // The thumb2 multiply instruction doesn't have a CCOut register, so
4904 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4905 // use the 16-bit encoding or not.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4911 // If the registers aren't low regs, the destination reg isn't the
4912 // same as one of the source regs, or the cc_out operand is zero
4913 // outside of an IT block, we have to use the 32-bit encoding, so
4914 // remove the cc_out operand.
4915 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4916 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004917 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004918 !inITBlock() ||
4919 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4920 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4921 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4922 static_cast<ARMOperand*>(Operands[4])->getReg())))
4923 return true;
4924
Jim Grosbachefa7e952011-11-15 19:55:16 +00004925 // Also check the 'mul' syntax variant that doesn't specify an explicit
4926 // destination register.
4927 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4928 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4929 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4930 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4931 // If the registers aren't low regs or the cc_out operand is zero
4932 // outside of an IT block, we have to use the 32-bit encoding, so
4933 // remove the cc_out operand.
4934 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4935 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4936 !inITBlock()))
4937 return true;
4938
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004939
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004940
Jim Grosbach4b701af2011-08-24 21:42:27 +00004941 // Register-register 'add/sub' for thumb does not have a cc_out operand
4942 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4943 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4944 // right, this will result in better diagnostics (which operand is off)
4945 // anyway.
4946 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4947 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004948 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4949 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004950 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4951 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4952 (Operands.size() == 6 &&
4953 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004954 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004955
Jim Grosbach7283da92011-08-16 21:12:37 +00004956 return false;
4957}
4958
Jim Grosbach12952fe2011-11-11 23:08:10 +00004959static bool isDataTypeToken(StringRef Tok) {
4960 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4961 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4962 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4963 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4964 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4965 Tok == ".f" || Tok == ".d";
4966}
4967
4968// FIXME: This bit should probably be handled via an explicit match class
4969// in the .td files that matches the suffix instead of having it be
4970// a literal string token the way it is now.
4971static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4972 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4973}
4974
Jim Grosbach8be2f652011-12-09 23:34:09 +00004975static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004976/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004977bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4978 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004979 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004980 // Apply mnemonic aliases before doing anything else, as the destination
4981 // mnemnonic may include suffices and we want to handle them normally.
4982 // The generic tblgen'erated code does this later, at the start of
4983 // MatchInstructionImpl(), but that's too late for aliases that include
4984 // any sort of suffix.
4985 unsigned AvailableFeatures = getAvailableFeatures();
4986 applyMnemonicAliases(Name, AvailableFeatures);
4987
Jim Grosbachab5830e2011-12-14 02:16:11 +00004988 // First check for the ARM-specific .req directive.
4989 if (Parser.getTok().is(AsmToken::Identifier) &&
4990 Parser.getTok().getIdentifier() == ".req") {
4991 parseDirectiveReq(Name, NameLoc);
4992 // We always return 'error' for this, as we're done with this
4993 // statement and don't need to match the 'instruction."
4994 return true;
4995 }
4996
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004997 // Create the leading tokens for the mnemonic, split by '.' characters.
4998 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004999 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005000
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005001 // Split out the predication code and carry setting flag from the mnemonic.
5002 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005003 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005004 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005005 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005006 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005007 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005008
Jim Grosbach1c171b12011-08-25 17:23:55 +00005009 // In Thumb1, only the branch (B) instruction can be predicated.
5010 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5011 Parser.EatToEndOfStatement();
5012 return Error(NameLoc, "conditional execution not supported in Thumb1");
5013 }
5014
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005015 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5016
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005017 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5018 // is the mask as it will be for the IT encoding if the conditional
5019 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5020 // where the conditional bit0 is zero, the instruction post-processing
5021 // will adjust the mask accordingly.
5022 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005023 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5024 if (ITMask.size() > 3) {
5025 Parser.EatToEndOfStatement();
5026 return Error(Loc, "too many conditions on IT instruction");
5027 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005028 unsigned Mask = 8;
5029 for (unsigned i = ITMask.size(); i != 0; --i) {
5030 char pos = ITMask[i - 1];
5031 if (pos != 't' && pos != 'e') {
5032 Parser.EatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005033 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005034 }
5035 Mask >>= 1;
5036 if (ITMask[i - 1] == 't')
5037 Mask |= 8;
5038 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005039 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005040 }
5041
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005042 // FIXME: This is all a pretty gross hack. We should automatically handle
5043 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005044
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005045 // Next, add the CCOut and ConditionCode operands, if needed.
5046 //
5047 // For mnemonics which can ever incorporate a carry setting bit or predication
5048 // code, our matching model involves us always generating CCOut and
5049 // ConditionCode operands to match the mnemonic "as written" and then we let
5050 // the matcher deal with finding the right instruction or generating an
5051 // appropriate error.
5052 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005053 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005054
Jim Grosbach03a8a162011-07-14 22:04:21 +00005055 // If we had a carry-set on an instruction that can't do that, issue an
5056 // error.
5057 if (!CanAcceptCarrySet && CarrySetting) {
5058 Parser.EatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005059 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005060 "' can not set flags, but 's' suffix specified");
5061 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005062 // If we had a predication code on an instruction that can't do that, issue an
5063 // error.
5064 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5065 Parser.EatToEndOfStatement();
5066 return Error(NameLoc, "instruction '" + Mnemonic +
5067 "' is not predicable, but condition code specified");
5068 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005069
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005070 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005071 if (CanAcceptCarrySet) {
5072 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005073 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005074 Loc));
5075 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005076
5077 // Add the predication code operand, if necessary.
5078 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005079 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5080 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005081 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005082 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005083 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005084
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005085 // Add the processor imod operand, if necessary.
5086 if (ProcessorIMod) {
5087 Operands.push_back(ARMOperand::CreateImm(
5088 MCConstantExpr::Create(ProcessorIMod, getContext()),
5089 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005090 }
5091
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005092 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005093 while (Next != StringRef::npos) {
5094 Start = Next;
5095 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005096 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005097
Jim Grosbach12952fe2011-11-11 23:08:10 +00005098 // Some NEON instructions have an optional datatype suffix that is
5099 // completely ignored. Check for that.
5100 if (isDataTypeToken(ExtraToken) &&
5101 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5102 continue;
5103
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005104 if (ExtraToken != ".n") {
5105 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5106 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5107 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005108 }
5109
5110 // Read the remaining operands.
5111 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005112 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005113 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005114 Parser.EatToEndOfStatement();
5115 return true;
5116 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005117
5118 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005119 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005120
5121 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005122 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005123 Parser.EatToEndOfStatement();
5124 return true;
5125 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005126 }
5127 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005128
Chris Lattnera2a9d162010-09-11 16:18:25 +00005129 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005130 SMLoc Loc = getLexer().getLoc();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005131 Parser.EatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005132 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005133 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005134
Chris Lattner91689c12010-09-08 05:10:46 +00005135 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005136
Jim Grosbach7283da92011-08-16 21:12:37 +00005137 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5138 // do and don't have a cc_out optional-def operand. With some spot-checks
5139 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005140 // parse and adjust accordingly before actually matching. We shouldn't ever
5141 // try to remove a cc_out operand that was explicitly set on the the
5142 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5143 // table driven matcher doesn't fit well with the ARM instruction set.
5144 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005145 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5146 Operands.erase(Operands.begin() + 1);
5147 delete Op;
5148 }
5149
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005150 // ARM mode 'blx' need special handling, as the register operand version
5151 // is predicable, but the label operand version is not. So, we can't rely
5152 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005153 // a k_CondCode operand in the list. If we're trying to match the label
5154 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005155 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5156 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5157 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5158 Operands.erase(Operands.begin() + 1);
5159 delete Op;
5160 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005161
Weiming Zhao8f56f882012-11-16 21:55:34 +00005162 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5163 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5164 // a single GPRPair reg operand is used in the .td file to replace the two
5165 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5166 // expressed as a GPRPair, so we have to manually merge them.
5167 // FIXME: We would really like to be able to tablegen'erate this.
5168 if (!isThumb() && Operands.size() > 4 &&
5169 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5170 bool isLoad = (Mnemonic == "ldrexd");
5171 unsigned Idx = isLoad ? 2 : 3;
5172 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5173 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5174
5175 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5176 // Adjust only if Op1 and Op2 are GPRs.
5177 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5178 MRC.contains(Op2->getReg())) {
5179 unsigned Reg1 = Op1->getReg();
5180 unsigned Reg2 = Op2->getReg();
5181 unsigned Rt = MRI->getEncodingValue(Reg1);
5182 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5183
5184 // Rt2 must be Rt + 1 and Rt must be even.
5185 if (Rt + 1 != Rt2 || (Rt & 1)) {
5186 Error(Op2->getStartLoc(), isLoad ?
5187 "destination operands must be sequential" :
5188 "source operands must be sequential");
5189 return true;
5190 }
5191 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5192 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5193 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5194 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5195 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5196 delete Op1;
5197 delete Op2;
5198 }
5199 }
5200
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005201 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005202}
5203
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005204// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005205
5206// return 'true' if register list contains non-low GPR registers,
5207// 'false' otherwise. If Reg is in the register list or is HiReg, set
5208// 'containsReg' to true.
5209static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5210 unsigned HiReg, bool &containsReg) {
5211 containsReg = false;
5212 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5213 unsigned OpReg = Inst.getOperand(i).getReg();
5214 if (OpReg == Reg)
5215 containsReg = true;
5216 // Anything other than a low register isn't legal here.
5217 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5218 return true;
5219 }
5220 return false;
5221}
5222
Jim Grosbacha31f2232011-09-07 18:05:34 +00005223// Check if the specified regisgter is in the register list of the inst,
5224// starting at the indicated operand number.
5225static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5226 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5227 unsigned OpReg = Inst.getOperand(i).getReg();
5228 if (OpReg == Reg)
5229 return true;
5230 }
5231 return false;
5232}
5233
Jim Grosbached16ec42011-08-29 22:24:09 +00005234// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5235// the ARMInsts array) instead. Getting that here requires awkward
5236// API changes, though. Better way?
5237namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005238extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005239}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005240static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005241 return ARMInsts[Opcode];
5242}
5243
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005244// FIXME: We would really like to be able to tablegen'erate this.
5245bool ARMAsmParser::
5246validateInstruction(MCInst &Inst,
5247 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005248 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005249 SMLoc Loc = Operands[0]->getStartLoc();
5250 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005251 // NOTE: BKPT instruction has the interesting property of being
5252 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005253 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005254 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5255 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005256 unsigned bit = 1;
5257 if (ITState.FirstCond)
5258 ITState.FirstCond = false;
5259 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005260 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005261 // The instruction must be predicable.
5262 if (!MCID.isPredicable())
5263 return Error(Loc, "instructions in IT block must be predicable");
5264 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5265 unsigned ITCond = bit ? ITState.Cond :
5266 ARMCC::getOppositeCondition(ITState.Cond);
5267 if (Cond != ITCond) {
5268 // Find the condition code Operand to get its SMLoc information.
5269 SMLoc CondLoc;
5270 for (unsigned i = 1; i < Operands.size(); ++i)
5271 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5272 CondLoc = Operands[i]->getStartLoc();
5273 return Error(CondLoc, "incorrect condition in IT block; got '" +
5274 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5275 "', but expected '" +
5276 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5277 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005278 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005279 } else if (isThumbTwo() && MCID.isPredicable() &&
5280 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005281 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5282 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005283 return Error(Loc, "predicated instructions must be in IT block");
5284
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005285 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005286 case ARM::LDRD:
5287 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005288 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005289 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005290 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5291 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005292 if (Rt2 != Rt + 1)
5293 return Error(Operands[3]->getStartLoc(),
5294 "destination operands must be sequential");
5295 return false;
5296 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005297 case ARM::STRD: {
5298 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005299 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5300 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005301 if (Rt2 != Rt + 1)
5302 return Error(Operands[3]->getStartLoc(),
5303 "source operands must be sequential");
5304 return false;
5305 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005306 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005307 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005308 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005309 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5310 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005311 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005312 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005313 "source operands must be sequential");
5314 return false;
5315 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005316 case ARM::SBFX:
5317 case ARM::UBFX: {
5318 // width must be in range [1, 32-lsb]
5319 unsigned lsb = Inst.getOperand(2).getImm();
5320 unsigned widthm1 = Inst.getOperand(3).getImm();
5321 if (widthm1 >= 32 - lsb)
5322 return Error(Operands[5]->getStartLoc(),
5323 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005324 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005325 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005326 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005327 // If we're parsing Thumb2, the .w variant is available and handles
5328 // most cases that are normally illegal for a Thumb1 LDM
5329 // instruction. We'll make the transformation in processInstruction()
5330 // if necessary.
5331 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005332 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005333 // in the register list.
5334 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005335 bool hasWritebackToken =
5336 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5337 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005338 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005339 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005340 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5341 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005342 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005343 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005344 return Error(Operands[2]->getStartLoc(),
5345 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005346 // If we should not have writeback, there must not be a '!'. This is
5347 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005348 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005349 return Error(Operands[3]->getStartLoc(),
5350 "writeback operator '!' not allowed when base register "
5351 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005352
5353 break;
5354 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005355 case ARM::t2LDMIA_UPD: {
5356 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5357 return Error(Operands[4]->getStartLoc(),
5358 "writeback operator '!' not allowed when base register "
5359 "in register list");
5360 break;
5361 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005362 case ARM::tMUL: {
5363 // The second source operand must be the same register as the destination
5364 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005365 //
5366 // In this case, we must directly check the parsed operands because the
5367 // cvtThumbMultiply() function is written in such a way that it guarantees
5368 // this first statement is always true for the new Inst. Essentially, the
5369 // destination is unconditionally copied into the second source operand
5370 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005371 if (Operands.size() == 6 &&
5372 (((ARMOperand*)Operands[3])->getReg() !=
5373 ((ARMOperand*)Operands[5])->getReg()) &&
5374 (((ARMOperand*)Operands[3])->getReg() !=
5375 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005376 return Error(Operands[3]->getStartLoc(),
5377 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005378 }
5379 break;
5380 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005381 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5382 // so only issue a diagnostic for thumb1. The instructions will be
5383 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005384 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005385 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005386 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5387 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005388 return Error(Operands[2]->getStartLoc(),
5389 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005390 break;
5391 }
5392 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005393 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005394 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5395 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005396 return Error(Operands[2]->getStartLoc(),
5397 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005398 break;
5399 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005400 case ARM::tSTMIA_UPD: {
5401 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005402 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005403 return Error(Operands[4]->getStartLoc(),
5404 "registers must be in range r0-r7");
5405 break;
5406 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005407 case ARM::tADDrSP: {
5408 // If the non-SP source operand and the destination operand are not the
5409 // same, we need thumb2 (for the wide encoding), or we have an error.
5410 if (!isThumbTwo() &&
5411 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5412 return Error(Operands[4]->getStartLoc(),
5413 "source register must be the same as destination");
5414 }
5415 break;
5416 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005417 }
5418
5419 return false;
5420}
5421
Jim Grosbach1a747242012-01-23 23:45:44 +00005422static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005423 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005424 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005425 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005426 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5427 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5428 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5429 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5430 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5431 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5432 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5433 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5434 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005435
5436 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005437 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5438 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5439 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5440 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5441 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005442
Jim Grosbach1e946a42012-01-24 00:43:12 +00005443 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5444 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5445 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5446 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5447 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005448
Jim Grosbach1e946a42012-01-24 00:43:12 +00005449 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5450 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5451 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5452 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5453 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005454
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005455 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005456 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5457 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5458 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5459 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5460 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5461 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5462 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5463 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5464 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5465 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5466 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5467 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5468 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5469 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5470 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005471
Jim Grosbach1a747242012-01-23 23:45:44 +00005472 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005473 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5474 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5475 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5476 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5477 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5478 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5479 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5480 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5481 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5482 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5483 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5484 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5485 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5486 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5487 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5488 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5489 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5490 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005491
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005492 // VST4LN
5493 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5494 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5495 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5496 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5497 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5498 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5499 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5500 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5501 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5502 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5503 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5504 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5505 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5506 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5507 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5508
Jim Grosbachda70eac2012-01-24 00:58:13 +00005509 // VST4
5510 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5511 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5512 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5513 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5514 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5515 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5516 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5517 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5518 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5519 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5520 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5521 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5522 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5523 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5524 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5525 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5526 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5527 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005528 }
5529}
5530
Jim Grosbach1a747242012-01-23 23:45:44 +00005531static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005532 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005533 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005534 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005535 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5536 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5537 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5538 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5539 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5540 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5541 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5542 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5543 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005544
5545 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005546 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5547 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5548 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5549 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5550 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5551 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5552 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5553 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5554 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5555 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5556 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5557 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5558 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5559 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5560 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005561
Jim Grosbachb78403c2012-01-24 23:47:04 +00005562 // VLD3DUP
5563 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5564 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5565 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5566 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5567 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5568 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5569 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5570 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5571 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5572 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5573 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5574 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5575 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5576 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5577 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5578 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5579 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5580 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5581
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005582 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005583 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5584 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5585 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5586 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5587 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5588 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5589 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5590 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5591 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5592 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5593 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5594 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5595 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5596 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5597 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005598
5599 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005600 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5601 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5602 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5603 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5604 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5605 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5606 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5607 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5608 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5609 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5610 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5611 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5612 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5613 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5614 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5615 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5616 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5617 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005618
Jim Grosbach14952a02012-01-24 18:37:25 +00005619 // VLD4LN
5620 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5621 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5622 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5623 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5624 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5625 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5626 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5627 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5628 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5629 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5630 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5631 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5632 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5633 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5634 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5635
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005636 // VLD4DUP
5637 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5638 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5639 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5640 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5641 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5642 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5643 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5644 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5645 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5646 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5647 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5648 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5649 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5650 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5651 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5652 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5653 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5654 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5655
Jim Grosbached561fc2012-01-24 00:43:17 +00005656 // VLD4
5657 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5658 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5659 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5660 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5661 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5662 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5663 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5664 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5665 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5666 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5667 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5668 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5669 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5670 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5671 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5672 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5673 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5674 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005675 }
5676}
5677
Jim Grosbachafad0532011-11-10 23:42:14 +00005678bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005679processInstruction(MCInst &Inst,
5680 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5681 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005682 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5683 case ARM::ADDri: {
5684 if (Inst.getOperand(1).getReg() != ARM::PC ||
5685 Inst.getOperand(5).getReg() != 0)
5686 return false;
5687 MCInst TmpInst;
5688 TmpInst.setOpcode(ARM::ADR);
5689 TmpInst.addOperand(Inst.getOperand(0));
5690 TmpInst.addOperand(Inst.getOperand(2));
5691 TmpInst.addOperand(Inst.getOperand(3));
5692 TmpInst.addOperand(Inst.getOperand(4));
5693 Inst = TmpInst;
5694 return true;
5695 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005696 // Aliases for alternate PC+imm syntax of LDR instructions.
5697 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005698 // Select the narrow version if the immediate will fit.
5699 if (Inst.getOperand(1).getImm() > 0 &&
5700 Inst.getOperand(1).getImm() <= 0xff)
5701 Inst.setOpcode(ARM::tLDRpci);
5702 else
5703 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005704 return true;
5705 case ARM::t2LDRBpcrel:
5706 Inst.setOpcode(ARM::t2LDRBpci);
5707 return true;
5708 case ARM::t2LDRHpcrel:
5709 Inst.setOpcode(ARM::t2LDRHpci);
5710 return true;
5711 case ARM::t2LDRSBpcrel:
5712 Inst.setOpcode(ARM::t2LDRSBpci);
5713 return true;
5714 case ARM::t2LDRSHpcrel:
5715 Inst.setOpcode(ARM::t2LDRSHpci);
5716 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005717 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005718 case ARM::VST1LNdWB_register_Asm_8:
5719 case ARM::VST1LNdWB_register_Asm_16:
5720 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005721 MCInst TmpInst;
5722 // Shuffle the operands around so the lane index operand is in the
5723 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005724 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5731 TmpInst.addOperand(Inst.getOperand(1)); // lane
5732 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5733 TmpInst.addOperand(Inst.getOperand(6));
5734 Inst = TmpInst;
5735 return true;
5736 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005737
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005738 case ARM::VST2LNdWB_register_Asm_8:
5739 case ARM::VST2LNdWB_register_Asm_16:
5740 case ARM::VST2LNdWB_register_Asm_32:
5741 case ARM::VST2LNqWB_register_Asm_16:
5742 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005743 MCInst TmpInst;
5744 // Shuffle the operands around so the lane index operand is in the
5745 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005746 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005747 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005748 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5749 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5750 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5751 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5754 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005755 TmpInst.addOperand(Inst.getOperand(1)); // lane
5756 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5757 TmpInst.addOperand(Inst.getOperand(6));
5758 Inst = TmpInst;
5759 return true;
5760 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005761
5762 case ARM::VST3LNdWB_register_Asm_8:
5763 case ARM::VST3LNdWB_register_Asm_16:
5764 case ARM::VST3LNdWB_register_Asm_32:
5765 case ARM::VST3LNqWB_register_Asm_16:
5766 case ARM::VST3LNqWB_register_Asm_32: {
5767 MCInst TmpInst;
5768 // Shuffle the operands around so the lane index operand is in the
5769 // right place.
5770 unsigned Spacing;
5771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5775 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5778 Spacing));
5779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5780 Spacing * 2));
5781 TmpInst.addOperand(Inst.getOperand(1)); // lane
5782 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5783 TmpInst.addOperand(Inst.getOperand(6));
5784 Inst = TmpInst;
5785 return true;
5786 }
5787
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005788 case ARM::VST4LNdWB_register_Asm_8:
5789 case ARM::VST4LNdWB_register_Asm_16:
5790 case ARM::VST4LNdWB_register_Asm_32:
5791 case ARM::VST4LNqWB_register_Asm_16:
5792 case ARM::VST4LNqWB_register_Asm_32: {
5793 MCInst TmpInst;
5794 // Shuffle the operands around so the lane index operand is in the
5795 // right place.
5796 unsigned Spacing;
5797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5798 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5799 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5800 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5801 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5804 Spacing));
5805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5806 Spacing * 2));
5807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5808 Spacing * 3));
5809 TmpInst.addOperand(Inst.getOperand(1)); // lane
5810 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5811 TmpInst.addOperand(Inst.getOperand(6));
5812 Inst = TmpInst;
5813 return true;
5814 }
5815
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005816 case ARM::VST1LNdWB_fixed_Asm_8:
5817 case ARM::VST1LNdWB_fixed_Asm_16:
5818 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005819 MCInst TmpInst;
5820 // Shuffle the operands around so the lane index operand is in the
5821 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005822 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5827 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5828 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5829 TmpInst.addOperand(Inst.getOperand(1)); // lane
5830 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5831 TmpInst.addOperand(Inst.getOperand(5));
5832 Inst = TmpInst;
5833 return true;
5834 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005835
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005836 case ARM::VST2LNdWB_fixed_Asm_8:
5837 case ARM::VST2LNdWB_fixed_Asm_16:
5838 case ARM::VST2LNdWB_fixed_Asm_32:
5839 case ARM::VST2LNqWB_fixed_Asm_16:
5840 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005841 MCInst TmpInst;
5842 // Shuffle the operands around so the lane index operand is in the
5843 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005844 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005845 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005846 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5847 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5848 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5849 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5850 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5852 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005853 TmpInst.addOperand(Inst.getOperand(1)); // lane
5854 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5855 TmpInst.addOperand(Inst.getOperand(5));
5856 Inst = TmpInst;
5857 return true;
5858 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005859
5860 case ARM::VST3LNdWB_fixed_Asm_8:
5861 case ARM::VST3LNdWB_fixed_Asm_16:
5862 case ARM::VST3LNdWB_fixed_Asm_32:
5863 case ARM::VST3LNqWB_fixed_Asm_16:
5864 case ARM::VST3LNqWB_fixed_Asm_32: {
5865 MCInst TmpInst;
5866 // Shuffle the operands around so the lane index operand is in the
5867 // right place.
5868 unsigned Spacing;
5869 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5870 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5871 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5872 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5873 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5874 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5876 Spacing));
5877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5878 Spacing * 2));
5879 TmpInst.addOperand(Inst.getOperand(1)); // lane
5880 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5881 TmpInst.addOperand(Inst.getOperand(5));
5882 Inst = TmpInst;
5883 return true;
5884 }
5885
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005886 case ARM::VST4LNdWB_fixed_Asm_8:
5887 case ARM::VST4LNdWB_fixed_Asm_16:
5888 case ARM::VST4LNdWB_fixed_Asm_32:
5889 case ARM::VST4LNqWB_fixed_Asm_16:
5890 case ARM::VST4LNqWB_fixed_Asm_32: {
5891 MCInst TmpInst;
5892 // Shuffle the operands around so the lane index operand is in the
5893 // right place.
5894 unsigned Spacing;
5895 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5896 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5897 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5898 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5899 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5900 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5901 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5902 Spacing));
5903 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5904 Spacing * 2));
5905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5906 Spacing * 3));
5907 TmpInst.addOperand(Inst.getOperand(1)); // lane
5908 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5909 TmpInst.addOperand(Inst.getOperand(5));
5910 Inst = TmpInst;
5911 return true;
5912 }
5913
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005914 case ARM::VST1LNdAsm_8:
5915 case ARM::VST1LNdAsm_16:
5916 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005917 MCInst TmpInst;
5918 // Shuffle the operands around so the lane index operand is in the
5919 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005920 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005921 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005922 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5923 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5924 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5925 TmpInst.addOperand(Inst.getOperand(1)); // lane
5926 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5927 TmpInst.addOperand(Inst.getOperand(5));
5928 Inst = TmpInst;
5929 return true;
5930 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005931
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005932 case ARM::VST2LNdAsm_8:
5933 case ARM::VST2LNdAsm_16:
5934 case ARM::VST2LNdAsm_32:
5935 case ARM::VST2LNqAsm_16:
5936 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005937 MCInst TmpInst;
5938 // Shuffle the operands around so the lane index operand is in the
5939 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005940 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005941 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005942 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5943 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5946 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005947 TmpInst.addOperand(Inst.getOperand(1)); // lane
5948 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5949 TmpInst.addOperand(Inst.getOperand(5));
5950 Inst = TmpInst;
5951 return true;
5952 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005953
5954 case ARM::VST3LNdAsm_8:
5955 case ARM::VST3LNdAsm_16:
5956 case ARM::VST3LNdAsm_32:
5957 case ARM::VST3LNqAsm_16:
5958 case ARM::VST3LNqAsm_32: {
5959 MCInst TmpInst;
5960 // Shuffle the operands around so the lane index operand is in the
5961 // right place.
5962 unsigned Spacing;
5963 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5964 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5965 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5966 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5968 Spacing));
5969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5970 Spacing * 2));
5971 TmpInst.addOperand(Inst.getOperand(1)); // lane
5972 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5973 TmpInst.addOperand(Inst.getOperand(5));
5974 Inst = TmpInst;
5975 return true;
5976 }
5977
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005978 case ARM::VST4LNdAsm_8:
5979 case ARM::VST4LNdAsm_16:
5980 case ARM::VST4LNdAsm_32:
5981 case ARM::VST4LNqAsm_16:
5982 case ARM::VST4LNqAsm_32: {
5983 MCInst TmpInst;
5984 // Shuffle the operands around so the lane index operand is in the
5985 // right place.
5986 unsigned Spacing;
5987 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5988 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5989 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5990 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5992 Spacing));
5993 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5994 Spacing * 2));
5995 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5996 Spacing * 3));
5997 TmpInst.addOperand(Inst.getOperand(1)); // lane
5998 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5999 TmpInst.addOperand(Inst.getOperand(5));
6000 Inst = TmpInst;
6001 return true;
6002 }
6003
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006004 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006005 case ARM::VLD1LNdWB_register_Asm_8:
6006 case ARM::VLD1LNdWB_register_Asm_16:
6007 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006008 MCInst TmpInst;
6009 // Shuffle the operands around so the lane index operand is in the
6010 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006011 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006012 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006013 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6014 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6015 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6016 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6017 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6018 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6019 TmpInst.addOperand(Inst.getOperand(1)); // lane
6020 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6021 TmpInst.addOperand(Inst.getOperand(6));
6022 Inst = TmpInst;
6023 return true;
6024 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006025
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006026 case ARM::VLD2LNdWB_register_Asm_8:
6027 case ARM::VLD2LNdWB_register_Asm_16:
6028 case ARM::VLD2LNdWB_register_Asm_32:
6029 case ARM::VLD2LNqWB_register_Asm_16:
6030 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006031 MCInst TmpInst;
6032 // Shuffle the operands around so the lane index operand is in the
6033 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006034 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006035 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006036 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6038 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006039 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6040 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6041 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6042 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6043 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6045 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006046 TmpInst.addOperand(Inst.getOperand(1)); // lane
6047 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6048 TmpInst.addOperand(Inst.getOperand(6));
6049 Inst = TmpInst;
6050 return true;
6051 }
6052
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006053 case ARM::VLD3LNdWB_register_Asm_8:
6054 case ARM::VLD3LNdWB_register_Asm_16:
6055 case ARM::VLD3LNdWB_register_Asm_32:
6056 case ARM::VLD3LNqWB_register_Asm_16:
6057 case ARM::VLD3LNqWB_register_Asm_32: {
6058 MCInst TmpInst;
6059 // Shuffle the operands around so the lane index operand is in the
6060 // right place.
6061 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006062 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006063 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6065 Spacing));
6066 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006067 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006068 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6069 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6070 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6071 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6072 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing));
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006076 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006077 TmpInst.addOperand(Inst.getOperand(1)); // lane
6078 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6079 TmpInst.addOperand(Inst.getOperand(6));
6080 Inst = TmpInst;
6081 return true;
6082 }
6083
Jim Grosbach14952a02012-01-24 18:37:25 +00006084 case ARM::VLD4LNdWB_register_Asm_8:
6085 case ARM::VLD4LNdWB_register_Asm_16:
6086 case ARM::VLD4LNdWB_register_Asm_32:
6087 case ARM::VLD4LNqWB_register_Asm_16:
6088 case ARM::VLD4LNqWB_register_Asm_32: {
6089 MCInst TmpInst;
6090 // Shuffle the operands around so the lane index operand is in the
6091 // right place.
6092 unsigned Spacing;
6093 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6094 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6095 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6096 Spacing));
6097 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6098 Spacing * 2));
6099 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6100 Spacing * 3));
6101 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6102 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6103 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6104 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6105 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6107 Spacing));
6108 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6109 Spacing * 2));
6110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6111 Spacing * 3));
6112 TmpInst.addOperand(Inst.getOperand(1)); // lane
6113 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6114 TmpInst.addOperand(Inst.getOperand(6));
6115 Inst = TmpInst;
6116 return true;
6117 }
6118
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006119 case ARM::VLD1LNdWB_fixed_Asm_8:
6120 case ARM::VLD1LNdWB_fixed_Asm_16:
6121 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006122 MCInst TmpInst;
6123 // Shuffle the operands around so the lane index operand is in the
6124 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006125 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006126 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006127 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6128 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6129 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6130 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6131 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6132 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6133 TmpInst.addOperand(Inst.getOperand(1)); // lane
6134 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6135 TmpInst.addOperand(Inst.getOperand(5));
6136 Inst = TmpInst;
6137 return true;
6138 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006139
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006140 case ARM::VLD2LNdWB_fixed_Asm_8:
6141 case ARM::VLD2LNdWB_fixed_Asm_16:
6142 case ARM::VLD2LNdWB_fixed_Asm_32:
6143 case ARM::VLD2LNqWB_fixed_Asm_16:
6144 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006145 MCInst TmpInst;
6146 // Shuffle the operands around so the lane index operand is in the
6147 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006148 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006149 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006150 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6152 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006153 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6154 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6155 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6156 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6157 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6159 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006160 TmpInst.addOperand(Inst.getOperand(1)); // lane
6161 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6162 TmpInst.addOperand(Inst.getOperand(5));
6163 Inst = TmpInst;
6164 return true;
6165 }
6166
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006167 case ARM::VLD3LNdWB_fixed_Asm_8:
6168 case ARM::VLD3LNdWB_fixed_Asm_16:
6169 case ARM::VLD3LNdWB_fixed_Asm_32:
6170 case ARM::VLD3LNqWB_fixed_Asm_16:
6171 case ARM::VLD3LNqWB_fixed_Asm_32: {
6172 MCInst TmpInst;
6173 // Shuffle the operands around so the lane index operand is in the
6174 // right place.
6175 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006176 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006177 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6179 Spacing));
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006181 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006182 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6183 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6184 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6185 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6186 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 Spacing));
6189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006190 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006191 TmpInst.addOperand(Inst.getOperand(1)); // lane
6192 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6193 TmpInst.addOperand(Inst.getOperand(5));
6194 Inst = TmpInst;
6195 return true;
6196 }
6197
Jim Grosbach14952a02012-01-24 18:37:25 +00006198 case ARM::VLD4LNdWB_fixed_Asm_8:
6199 case ARM::VLD4LNdWB_fixed_Asm_16:
6200 case ARM::VLD4LNdWB_fixed_Asm_32:
6201 case ARM::VLD4LNqWB_fixed_Asm_16:
6202 case ARM::VLD4LNqWB_fixed_Asm_32: {
6203 MCInst TmpInst;
6204 // Shuffle the operands around so the lane index operand is in the
6205 // right place.
6206 unsigned Spacing;
6207 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6208 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 Spacing));
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 Spacing * 2));
6213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 Spacing * 3));
6215 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6216 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6217 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6218 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6219 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6221 Spacing));
6222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6223 Spacing * 2));
6224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 Spacing * 3));
6226 TmpInst.addOperand(Inst.getOperand(1)); // lane
6227 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6228 TmpInst.addOperand(Inst.getOperand(5));
6229 Inst = TmpInst;
6230 return true;
6231 }
6232
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006233 case ARM::VLD1LNdAsm_8:
6234 case ARM::VLD1LNdAsm_16:
6235 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006236 MCInst TmpInst;
6237 // Shuffle the operands around so the lane index operand is in the
6238 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006239 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006240 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006241 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6242 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6243 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6244 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6245 TmpInst.addOperand(Inst.getOperand(1)); // lane
6246 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6247 TmpInst.addOperand(Inst.getOperand(5));
6248 Inst = TmpInst;
6249 return true;
6250 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006251
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006252 case ARM::VLD2LNdAsm_8:
6253 case ARM::VLD2LNdAsm_16:
6254 case ARM::VLD2LNdAsm_32:
6255 case ARM::VLD2LNqAsm_16:
6256 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006257 MCInst TmpInst;
6258 // Shuffle the operands around so the lane index operand is in the
6259 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006260 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006261 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006262 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006265 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6266 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6267 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6269 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006270 TmpInst.addOperand(Inst.getOperand(1)); // lane
6271 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6272 TmpInst.addOperand(Inst.getOperand(5));
6273 Inst = TmpInst;
6274 return true;
6275 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006276
6277 case ARM::VLD3LNdAsm_8:
6278 case ARM::VLD3LNdAsm_16:
6279 case ARM::VLD3LNdAsm_32:
6280 case ARM::VLD3LNqAsm_16:
6281 case ARM::VLD3LNqAsm_32: {
6282 MCInst TmpInst;
6283 // Shuffle the operands around so the lane index operand is in the
6284 // right place.
6285 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006286 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006287 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6288 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6289 Spacing));
6290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006291 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006292 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6293 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6294 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 Spacing));
6297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006298 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006299 TmpInst.addOperand(Inst.getOperand(1)); // lane
6300 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6301 TmpInst.addOperand(Inst.getOperand(5));
6302 Inst = TmpInst;
6303 return true;
6304 }
6305
Jim Grosbach14952a02012-01-24 18:37:25 +00006306 case ARM::VLD4LNdAsm_8:
6307 case ARM::VLD4LNdAsm_16:
6308 case ARM::VLD4LNdAsm_32:
6309 case ARM::VLD4LNqAsm_16:
6310 case ARM::VLD4LNqAsm_32: {
6311 MCInst TmpInst;
6312 // Shuffle the operands around so the lane index operand is in the
6313 // right place.
6314 unsigned Spacing;
6315 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6316 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 Spacing));
6319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6320 Spacing * 2));
6321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 Spacing * 3));
6323 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6324 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6325 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6326 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6327 Spacing));
6328 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6329 Spacing * 2));
6330 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6331 Spacing * 3));
6332 TmpInst.addOperand(Inst.getOperand(1)); // lane
6333 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6334 TmpInst.addOperand(Inst.getOperand(5));
6335 Inst = TmpInst;
6336 return true;
6337 }
6338
Jim Grosbachb78403c2012-01-24 23:47:04 +00006339 // VLD3DUP single 3-element structure to all lanes instructions.
6340 case ARM::VLD3DUPdAsm_8:
6341 case ARM::VLD3DUPdAsm_16:
6342 case ARM::VLD3DUPdAsm_32:
6343 case ARM::VLD3DUPqAsm_8:
6344 case ARM::VLD3DUPqAsm_16:
6345 case ARM::VLD3DUPqAsm_32: {
6346 MCInst TmpInst;
6347 unsigned Spacing;
6348 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6349 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6350 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6351 Spacing));
6352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6353 Spacing * 2));
6354 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6355 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6356 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6357 TmpInst.addOperand(Inst.getOperand(4));
6358 Inst = TmpInst;
6359 return true;
6360 }
6361
6362 case ARM::VLD3DUPdWB_fixed_Asm_8:
6363 case ARM::VLD3DUPdWB_fixed_Asm_16:
6364 case ARM::VLD3DUPdWB_fixed_Asm_32:
6365 case ARM::VLD3DUPqWB_fixed_Asm_8:
6366 case ARM::VLD3DUPqWB_fixed_Asm_16:
6367 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6368 MCInst TmpInst;
6369 unsigned Spacing;
6370 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6371 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6372 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6373 Spacing));
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 Spacing * 2));
6376 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6377 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6378 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6379 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6380 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6381 TmpInst.addOperand(Inst.getOperand(4));
6382 Inst = TmpInst;
6383 return true;
6384 }
6385
6386 case ARM::VLD3DUPdWB_register_Asm_8:
6387 case ARM::VLD3DUPdWB_register_Asm_16:
6388 case ARM::VLD3DUPdWB_register_Asm_32:
6389 case ARM::VLD3DUPqWB_register_Asm_8:
6390 case ARM::VLD3DUPqWB_register_Asm_16:
6391 case ARM::VLD3DUPqWB_register_Asm_32: {
6392 MCInst TmpInst;
6393 unsigned Spacing;
6394 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6395 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6397 Spacing));
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing * 2));
6400 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6401 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6402 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6403 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6404 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6405 TmpInst.addOperand(Inst.getOperand(5));
6406 Inst = TmpInst;
6407 return true;
6408 }
6409
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006410 // VLD3 multiple 3-element structure instructions.
6411 case ARM::VLD3dAsm_8:
6412 case ARM::VLD3dAsm_16:
6413 case ARM::VLD3dAsm_32:
6414 case ARM::VLD3qAsm_8:
6415 case ARM::VLD3qAsm_16:
6416 case ARM::VLD3qAsm_32: {
6417 MCInst TmpInst;
6418 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006419 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006420 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6422 Spacing));
6423 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 Spacing * 2));
6425 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6426 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6427 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6428 TmpInst.addOperand(Inst.getOperand(4));
6429 Inst = TmpInst;
6430 return true;
6431 }
6432
6433 case ARM::VLD3dWB_fixed_Asm_8:
6434 case ARM::VLD3dWB_fixed_Asm_16:
6435 case ARM::VLD3dWB_fixed_Asm_32:
6436 case ARM::VLD3qWB_fixed_Asm_8:
6437 case ARM::VLD3qWB_fixed_Asm_16:
6438 case ARM::VLD3qWB_fixed_Asm_32: {
6439 MCInst TmpInst;
6440 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006441 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006442 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 Spacing));
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 Spacing * 2));
6447 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6448 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6449 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6450 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6451 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6452 TmpInst.addOperand(Inst.getOperand(4));
6453 Inst = TmpInst;
6454 return true;
6455 }
6456
6457 case ARM::VLD3dWB_register_Asm_8:
6458 case ARM::VLD3dWB_register_Asm_16:
6459 case ARM::VLD3dWB_register_Asm_32:
6460 case ARM::VLD3qWB_register_Asm_8:
6461 case ARM::VLD3qWB_register_Asm_16:
6462 case ARM::VLD3qWB_register_Asm_32: {
6463 MCInst TmpInst;
6464 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006465 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006466 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6468 Spacing));
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing * 2));
6471 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6472 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6473 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6474 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6475 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6476 TmpInst.addOperand(Inst.getOperand(5));
6477 Inst = TmpInst;
6478 return true;
6479 }
6480
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006481 // VLD4DUP single 3-element structure to all lanes instructions.
6482 case ARM::VLD4DUPdAsm_8:
6483 case ARM::VLD4DUPdAsm_16:
6484 case ARM::VLD4DUPdAsm_32:
6485 case ARM::VLD4DUPqAsm_8:
6486 case ARM::VLD4DUPqAsm_16:
6487 case ARM::VLD4DUPqAsm_32: {
6488 MCInst TmpInst;
6489 unsigned Spacing;
6490 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6491 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6493 Spacing));
6494 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6495 Spacing * 2));
6496 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6497 Spacing * 3));
6498 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6499 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6500 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6501 TmpInst.addOperand(Inst.getOperand(4));
6502 Inst = TmpInst;
6503 return true;
6504 }
6505
6506 case ARM::VLD4DUPdWB_fixed_Asm_8:
6507 case ARM::VLD4DUPdWB_fixed_Asm_16:
6508 case ARM::VLD4DUPdWB_fixed_Asm_32:
6509 case ARM::VLD4DUPqWB_fixed_Asm_8:
6510 case ARM::VLD4DUPqWB_fixed_Asm_16:
6511 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6512 MCInst TmpInst;
6513 unsigned Spacing;
6514 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6515 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6516 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6517 Spacing));
6518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 Spacing * 2));
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 Spacing * 3));
6522 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6523 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6524 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6525 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6526 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6527 TmpInst.addOperand(Inst.getOperand(4));
6528 Inst = TmpInst;
6529 return true;
6530 }
6531
6532 case ARM::VLD4DUPdWB_register_Asm_8:
6533 case ARM::VLD4DUPdWB_register_Asm_16:
6534 case ARM::VLD4DUPdWB_register_Asm_32:
6535 case ARM::VLD4DUPqWB_register_Asm_8:
6536 case ARM::VLD4DUPqWB_register_Asm_16:
6537 case ARM::VLD4DUPqWB_register_Asm_32: {
6538 MCInst TmpInst;
6539 unsigned Spacing;
6540 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6541 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6542 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6543 Spacing));
6544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6545 Spacing * 2));
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing * 3));
6548 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6549 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6550 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6551 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6552 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6553 TmpInst.addOperand(Inst.getOperand(5));
6554 Inst = TmpInst;
6555 return true;
6556 }
6557
6558 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006559 case ARM::VLD4dAsm_8:
6560 case ARM::VLD4dAsm_16:
6561 case ARM::VLD4dAsm_32:
6562 case ARM::VLD4qAsm_8:
6563 case ARM::VLD4qAsm_16:
6564 case ARM::VLD4qAsm_32: {
6565 MCInst TmpInst;
6566 unsigned Spacing;
6567 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6568 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6569 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6570 Spacing));
6571 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6572 Spacing * 2));
6573 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 Spacing * 3));
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6577 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6578 TmpInst.addOperand(Inst.getOperand(4));
6579 Inst = TmpInst;
6580 return true;
6581 }
6582
6583 case ARM::VLD4dWB_fixed_Asm_8:
6584 case ARM::VLD4dWB_fixed_Asm_16:
6585 case ARM::VLD4dWB_fixed_Asm_32:
6586 case ARM::VLD4qWB_fixed_Asm_8:
6587 case ARM::VLD4qWB_fixed_Asm_16:
6588 case ARM::VLD4qWB_fixed_Asm_32: {
6589 MCInst TmpInst;
6590 unsigned Spacing;
6591 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6592 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6594 Spacing));
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing * 2));
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing * 3));
6599 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6600 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6601 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6602 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6603 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6604 TmpInst.addOperand(Inst.getOperand(4));
6605 Inst = TmpInst;
6606 return true;
6607 }
6608
6609 case ARM::VLD4dWB_register_Asm_8:
6610 case ARM::VLD4dWB_register_Asm_16:
6611 case ARM::VLD4dWB_register_Asm_32:
6612 case ARM::VLD4qWB_register_Asm_8:
6613 case ARM::VLD4qWB_register_Asm_16:
6614 case ARM::VLD4qWB_register_Asm_32: {
6615 MCInst TmpInst;
6616 unsigned Spacing;
6617 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6618 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing));
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing * 2));
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing * 3));
6625 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6626 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6627 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6628 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6629 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6630 TmpInst.addOperand(Inst.getOperand(5));
6631 Inst = TmpInst;
6632 return true;
6633 }
6634
Jim Grosbach1a747242012-01-23 23:45:44 +00006635 // VST3 multiple 3-element structure instructions.
6636 case ARM::VST3dAsm_8:
6637 case ARM::VST3dAsm_16:
6638 case ARM::VST3dAsm_32:
6639 case ARM::VST3qAsm_8:
6640 case ARM::VST3qAsm_16:
6641 case ARM::VST3qAsm_32: {
6642 MCInst TmpInst;
6643 unsigned Spacing;
6644 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6645 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6646 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6647 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6648 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6649 Spacing));
6650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6651 Spacing * 2));
6652 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6653 TmpInst.addOperand(Inst.getOperand(4));
6654 Inst = TmpInst;
6655 return true;
6656 }
6657
6658 case ARM::VST3dWB_fixed_Asm_8:
6659 case ARM::VST3dWB_fixed_Asm_16:
6660 case ARM::VST3dWB_fixed_Asm_32:
6661 case ARM::VST3qWB_fixed_Asm_8:
6662 case ARM::VST3qWB_fixed_Asm_16:
6663 case ARM::VST3qWB_fixed_Asm_32: {
6664 MCInst TmpInst;
6665 unsigned Spacing;
6666 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6670 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6671 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6673 Spacing));
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing * 2));
6676 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6677 TmpInst.addOperand(Inst.getOperand(4));
6678 Inst = TmpInst;
6679 return true;
6680 }
6681
6682 case ARM::VST3dWB_register_Asm_8:
6683 case ARM::VST3dWB_register_Asm_16:
6684 case ARM::VST3dWB_register_Asm_32:
6685 case ARM::VST3qWB_register_Asm_8:
6686 case ARM::VST3qWB_register_Asm_16:
6687 case ARM::VST3qWB_register_Asm_32: {
6688 MCInst TmpInst;
6689 unsigned Spacing;
6690 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6691 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6692 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6693 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6694 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6697 Spacing));
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing * 2));
6700 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6701 TmpInst.addOperand(Inst.getOperand(5));
6702 Inst = TmpInst;
6703 return true;
6704 }
6705
Jim Grosbachda70eac2012-01-24 00:58:13 +00006706 // VST4 multiple 3-element structure instructions.
6707 case ARM::VST4dAsm_8:
6708 case ARM::VST4dAsm_16:
6709 case ARM::VST4dAsm_32:
6710 case ARM::VST4qAsm_8:
6711 case ARM::VST4qAsm_16:
6712 case ARM::VST4qAsm_32: {
6713 MCInst TmpInst;
6714 unsigned Spacing;
6715 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6716 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6717 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6718 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 Spacing));
6721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6722 Spacing * 2));
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6724 Spacing * 3));
6725 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6726 TmpInst.addOperand(Inst.getOperand(4));
6727 Inst = TmpInst;
6728 return true;
6729 }
6730
6731 case ARM::VST4dWB_fixed_Asm_8:
6732 case ARM::VST4dWB_fixed_Asm_16:
6733 case ARM::VST4dWB_fixed_Asm_32:
6734 case ARM::VST4qWB_fixed_Asm_8:
6735 case ARM::VST4qWB_fixed_Asm_16:
6736 case ARM::VST4qWB_fixed_Asm_32: {
6737 MCInst TmpInst;
6738 unsigned Spacing;
6739 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6740 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6742 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6743 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6744 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 Spacing));
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 Spacing * 2));
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6750 Spacing * 3));
6751 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6752 TmpInst.addOperand(Inst.getOperand(4));
6753 Inst = TmpInst;
6754 return true;
6755 }
6756
6757 case ARM::VST4dWB_register_Asm_8:
6758 case ARM::VST4dWB_register_Asm_16:
6759 case ARM::VST4dWB_register_Asm_32:
6760 case ARM::VST4qWB_register_Asm_8:
6761 case ARM::VST4qWB_register_Asm_16:
6762 case ARM::VST4qWB_register_Asm_32: {
6763 MCInst TmpInst;
6764 unsigned Spacing;
6765 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6766 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6767 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6768 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6769 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6770 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6772 Spacing));
6773 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6774 Spacing * 2));
6775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6776 Spacing * 3));
6777 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6778 TmpInst.addOperand(Inst.getOperand(5));
6779 Inst = TmpInst;
6780 return true;
6781 }
6782
Jim Grosbachad66de12012-04-11 00:15:16 +00006783 // Handle encoding choice for the shift-immediate instructions.
6784 case ARM::t2LSLri:
6785 case ARM::t2LSRri:
6786 case ARM::t2ASRri: {
6787 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6788 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6789 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6790 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6791 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6792 unsigned NewOpc;
6793 switch (Inst.getOpcode()) {
6794 default: llvm_unreachable("unexpected opcode");
6795 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6796 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6797 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6798 }
6799 // The Thumb1 operands aren't in the same order. Awesome, eh?
6800 MCInst TmpInst;
6801 TmpInst.setOpcode(NewOpc);
6802 TmpInst.addOperand(Inst.getOperand(0));
6803 TmpInst.addOperand(Inst.getOperand(5));
6804 TmpInst.addOperand(Inst.getOperand(1));
6805 TmpInst.addOperand(Inst.getOperand(2));
6806 TmpInst.addOperand(Inst.getOperand(3));
6807 TmpInst.addOperand(Inst.getOperand(4));
6808 Inst = TmpInst;
6809 return true;
6810 }
6811 return false;
6812 }
6813
Jim Grosbach485e5622011-12-13 22:45:11 +00006814 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006815 case ARM::t2MOVsr:
6816 case ARM::t2MOVSsr: {
6817 // Which instruction to expand to depends on the CCOut operand and
6818 // whether we're in an IT block if the register operands are low
6819 // registers.
6820 bool isNarrow = false;
6821 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6822 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6823 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6824 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6825 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6826 isNarrow = true;
6827 MCInst TmpInst;
6828 unsigned newOpc;
6829 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6830 default: llvm_unreachable("unexpected opcode!");
6831 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6832 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6833 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6834 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6835 }
6836 TmpInst.setOpcode(newOpc);
6837 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6838 if (isNarrow)
6839 TmpInst.addOperand(MCOperand::CreateReg(
6840 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6841 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6842 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6843 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6844 TmpInst.addOperand(Inst.getOperand(5));
6845 if (!isNarrow)
6846 TmpInst.addOperand(MCOperand::CreateReg(
6847 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6848 Inst = TmpInst;
6849 return true;
6850 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006851 case ARM::t2MOVsi:
6852 case ARM::t2MOVSsi: {
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 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6860 isNarrow = true;
6861 MCInst TmpInst;
6862 unsigned newOpc;
6863 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6864 default: llvm_unreachable("unexpected opcode!");
6865 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6866 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6867 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6868 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006869 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006870 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006871 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6872 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006873 TmpInst.setOpcode(newOpc);
6874 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6875 if (isNarrow)
6876 TmpInst.addOperand(MCOperand::CreateReg(
6877 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006879 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006880 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006881 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6882 TmpInst.addOperand(Inst.getOperand(4));
6883 if (!isNarrow)
6884 TmpInst.addOperand(MCOperand::CreateReg(
6885 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6886 Inst = TmpInst;
6887 return true;
6888 }
6889 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006890 case ARM::ASRr:
6891 case ARM::LSRr:
6892 case ARM::LSLr:
6893 case ARM::RORr: {
6894 ARM_AM::ShiftOpc ShiftTy;
6895 switch(Inst.getOpcode()) {
6896 default: llvm_unreachable("unexpected opcode!");
6897 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6898 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6899 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6900 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6901 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006902 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6903 MCInst TmpInst;
6904 TmpInst.setOpcode(ARM::MOVsr);
6905 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6906 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6907 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6908 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6909 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6910 TmpInst.addOperand(Inst.getOperand(4));
6911 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6912 Inst = TmpInst;
6913 return true;
6914 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006915 case ARM::ASRi:
6916 case ARM::LSRi:
6917 case ARM::LSLi:
6918 case ARM::RORi: {
6919 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006920 switch(Inst.getOpcode()) {
6921 default: llvm_unreachable("unexpected opcode!");
6922 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6923 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6924 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6925 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6926 }
6927 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006928 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006929 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006930 // A shift by 32 should be encoded as 0 when permitted
6931 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6932 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006933 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006934 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006935 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006936 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6937 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006938 if (Opc == ARM::MOVsi)
6939 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006940 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6941 TmpInst.addOperand(Inst.getOperand(4));
6942 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6943 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006944 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006945 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006946 case ARM::RRXi: {
6947 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6948 MCInst TmpInst;
6949 TmpInst.setOpcode(ARM::MOVsi);
6950 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6951 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6952 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6953 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6954 TmpInst.addOperand(Inst.getOperand(3));
6955 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6956 Inst = TmpInst;
6957 return true;
6958 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006959 case ARM::t2LDMIA_UPD: {
6960 // If this is a load of a single register, then we should use
6961 // a post-indexed LDR instruction instead, per the ARM ARM.
6962 if (Inst.getNumOperands() != 5)
6963 return false;
6964 MCInst TmpInst;
6965 TmpInst.setOpcode(ARM::t2LDR_POST);
6966 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6967 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6968 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6969 TmpInst.addOperand(MCOperand::CreateImm(4));
6970 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6971 TmpInst.addOperand(Inst.getOperand(3));
6972 Inst = TmpInst;
6973 return true;
6974 }
6975 case ARM::t2STMDB_UPD: {
6976 // If this is a store of a single register, then we should use
6977 // a pre-indexed STR instruction instead, per the ARM ARM.
6978 if (Inst.getNumOperands() != 5)
6979 return false;
6980 MCInst TmpInst;
6981 TmpInst.setOpcode(ARM::t2STR_PRE);
6982 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6983 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6984 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6985 TmpInst.addOperand(MCOperand::CreateImm(-4));
6986 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6987 TmpInst.addOperand(Inst.getOperand(3));
6988 Inst = TmpInst;
6989 return true;
6990 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006991 case ARM::LDMIA_UPD:
6992 // If this is a load of a single register via a 'pop', then we should use
6993 // a post-indexed LDR instruction instead, per the ARM ARM.
6994 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6995 Inst.getNumOperands() == 5) {
6996 MCInst TmpInst;
6997 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6998 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6999 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7000 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7001 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7002 TmpInst.addOperand(MCOperand::CreateImm(4));
7003 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7004 TmpInst.addOperand(Inst.getOperand(3));
7005 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007006 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007007 }
7008 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007009 case ARM::STMDB_UPD:
7010 // If this is a store of a single register via a 'push', then we should use
7011 // a pre-indexed STR instruction instead, per the ARM ARM.
7012 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7013 Inst.getNumOperands() == 5) {
7014 MCInst TmpInst;
7015 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7016 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7017 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7018 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7019 TmpInst.addOperand(MCOperand::CreateImm(-4));
7020 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7021 TmpInst.addOperand(Inst.getOperand(3));
7022 Inst = TmpInst;
7023 }
7024 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007025 case ARM::t2ADDri12:
7026 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7027 // mnemonic was used (not "addw"), encoding T3 is preferred.
7028 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7029 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7030 break;
7031 Inst.setOpcode(ARM::t2ADDri);
7032 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7033 break;
7034 case ARM::t2SUBri12:
7035 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7036 // mnemonic was used (not "subw"), encoding T3 is preferred.
7037 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7038 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7039 break;
7040 Inst.setOpcode(ARM::t2SUBri);
7041 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7042 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007043 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007044 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007045 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7046 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7047 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007048 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007049 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007050 return true;
7051 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007052 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007053 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007054 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007055 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7056 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7057 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007058 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007059 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007060 return true;
7061 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007062 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007063 case ARM::t2ADDri:
7064 case ARM::t2SUBri: {
7065 // If the destination and first source operand are the same, and
7066 // the flags are compatible with the current IT status, use encoding T2
7067 // instead of T3. For compatibility with the system 'as'. Make sure the
7068 // wide encoding wasn't explicit.
7069 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007070 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007071 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7072 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7073 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7074 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7075 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7076 break;
7077 MCInst TmpInst;
7078 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7079 ARM::tADDi8 : ARM::tSUBi8);
7080 TmpInst.addOperand(Inst.getOperand(0));
7081 TmpInst.addOperand(Inst.getOperand(5));
7082 TmpInst.addOperand(Inst.getOperand(0));
7083 TmpInst.addOperand(Inst.getOperand(2));
7084 TmpInst.addOperand(Inst.getOperand(3));
7085 TmpInst.addOperand(Inst.getOperand(4));
7086 Inst = TmpInst;
7087 return true;
7088 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007089 case ARM::t2ADDrr: {
7090 // If the destination and first source operand are the same, and
7091 // there's no setting of the flags, use encoding T2 instead of T3.
7092 // Note that this is only for ADD, not SUB. This mirrors the system
7093 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7094 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7095 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007096 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7097 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007098 break;
7099 MCInst TmpInst;
7100 TmpInst.setOpcode(ARM::tADDhirr);
7101 TmpInst.addOperand(Inst.getOperand(0));
7102 TmpInst.addOperand(Inst.getOperand(0));
7103 TmpInst.addOperand(Inst.getOperand(2));
7104 TmpInst.addOperand(Inst.getOperand(3));
7105 TmpInst.addOperand(Inst.getOperand(4));
7106 Inst = TmpInst;
7107 return true;
7108 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007109 case ARM::tADDrSP: {
7110 // If the non-SP source operand and the destination operand are not the
7111 // same, we need to use the 32-bit encoding if it's available.
7112 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7113 Inst.setOpcode(ARM::t2ADDrr);
7114 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7115 return true;
7116 }
7117 break;
7118 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007119 case ARM::tB:
7120 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007121 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007122 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007123 return true;
7124 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007125 break;
7126 case ARM::t2B:
7127 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007128 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007129 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007130 return true;
7131 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007132 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007133 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007134 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007135 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007136 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007137 return true;
7138 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007139 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007140 case ARM::tBcc:
7141 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007142 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007143 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007144 return true;
7145 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007146 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007147 case ARM::tLDMIA: {
7148 // If the register list contains any high registers, or if the writeback
7149 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7150 // instead if we're in Thumb2. Otherwise, this should have generated
7151 // an error in validateInstruction().
7152 unsigned Rn = Inst.getOperand(0).getReg();
7153 bool hasWritebackToken =
7154 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7155 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7156 bool listContainsBase;
7157 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7158 (!listContainsBase && !hasWritebackToken) ||
7159 (listContainsBase && hasWritebackToken)) {
7160 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7161 assert (isThumbTwo());
7162 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7163 // If we're switching to the updating version, we need to insert
7164 // the writeback tied operand.
7165 if (hasWritebackToken)
7166 Inst.insert(Inst.begin(),
7167 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007168 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007169 }
7170 break;
7171 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007172 case ARM::tSTMIA_UPD: {
7173 // If the register list contains any high registers, we need to use
7174 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7175 // should have generated an error in validateInstruction().
7176 unsigned Rn = Inst.getOperand(0).getReg();
7177 bool listContainsBase;
7178 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7179 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7180 assert (isThumbTwo());
7181 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007182 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007183 }
7184 break;
7185 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007186 case ARM::tPOP: {
7187 bool listContainsBase;
7188 // If the register list contains any high registers, we need to use
7189 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7190 // should have generated an error in validateInstruction().
7191 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007192 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007193 assert (isThumbTwo());
7194 Inst.setOpcode(ARM::t2LDMIA_UPD);
7195 // Add the base register and writeback operands.
7196 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7197 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007198 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007199 }
7200 case ARM::tPUSH: {
7201 bool listContainsBase;
7202 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007203 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007204 assert (isThumbTwo());
7205 Inst.setOpcode(ARM::t2STMDB_UPD);
7206 // Add the base register and writeback operands.
7207 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7208 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007209 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007210 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007211 case ARM::t2MOVi: {
7212 // If we can use the 16-bit encoding and the user didn't explicitly
7213 // request the 32-bit variant, transform it here.
7214 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007215 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007216 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7217 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7218 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007219 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7220 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7221 // The operands aren't in the same order for tMOVi8...
7222 MCInst TmpInst;
7223 TmpInst.setOpcode(ARM::tMOVi8);
7224 TmpInst.addOperand(Inst.getOperand(0));
7225 TmpInst.addOperand(Inst.getOperand(4));
7226 TmpInst.addOperand(Inst.getOperand(1));
7227 TmpInst.addOperand(Inst.getOperand(2));
7228 TmpInst.addOperand(Inst.getOperand(3));
7229 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007230 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007231 }
7232 break;
7233 }
7234 case ARM::t2MOVr: {
7235 // If we can use the 16-bit encoding and the user didn't explicitly
7236 // request the 32-bit variant, transform it here.
7237 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7238 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7239 Inst.getOperand(2).getImm() == ARMCC::AL &&
7240 Inst.getOperand(4).getReg() == ARM::CPSR &&
7241 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7242 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7243 // The operands aren't the same for tMOV[S]r... (no cc_out)
7244 MCInst TmpInst;
7245 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7246 TmpInst.addOperand(Inst.getOperand(0));
7247 TmpInst.addOperand(Inst.getOperand(1));
7248 TmpInst.addOperand(Inst.getOperand(2));
7249 TmpInst.addOperand(Inst.getOperand(3));
7250 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007251 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007252 }
7253 break;
7254 }
Jim Grosbach82213192011-09-19 20:29:33 +00007255 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007256 case ARM::t2SXTB:
7257 case ARM::t2UXTH:
7258 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007259 // If we can use the 16-bit encoding and the user didn't explicitly
7260 // request the 32-bit variant, transform it here.
7261 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7262 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7263 Inst.getOperand(2).getImm() == 0 &&
7264 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7265 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007266 unsigned NewOpc;
7267 switch (Inst.getOpcode()) {
7268 default: llvm_unreachable("Illegal opcode!");
7269 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7270 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7271 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7272 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7273 }
Jim Grosbach82213192011-09-19 20:29:33 +00007274 // The operands aren't the same for thumb1 (no rotate operand).
7275 MCInst TmpInst;
7276 TmpInst.setOpcode(NewOpc);
7277 TmpInst.addOperand(Inst.getOperand(0));
7278 TmpInst.addOperand(Inst.getOperand(1));
7279 TmpInst.addOperand(Inst.getOperand(3));
7280 TmpInst.addOperand(Inst.getOperand(4));
7281 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007282 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007283 }
7284 break;
7285 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007286 case ARM::MOVsi: {
7287 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007288 // rrx shifts and asr/lsr of #32 is encoded as 0
7289 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7290 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007291 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7292 // Shifting by zero is accepted as a vanilla 'MOVr'
7293 MCInst TmpInst;
7294 TmpInst.setOpcode(ARM::MOVr);
7295 TmpInst.addOperand(Inst.getOperand(0));
7296 TmpInst.addOperand(Inst.getOperand(1));
7297 TmpInst.addOperand(Inst.getOperand(3));
7298 TmpInst.addOperand(Inst.getOperand(4));
7299 TmpInst.addOperand(Inst.getOperand(5));
7300 Inst = TmpInst;
7301 return true;
7302 }
7303 return false;
7304 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007305 case ARM::ANDrsi:
7306 case ARM::ORRrsi:
7307 case ARM::EORrsi:
7308 case ARM::BICrsi:
7309 case ARM::SUBrsi:
7310 case ARM::ADDrsi: {
7311 unsigned newOpc;
7312 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7313 if (SOpc == ARM_AM::rrx) return false;
7314 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007315 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007316 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7317 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7318 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7319 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7320 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7321 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7322 }
7323 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007324 // The exception is for right shifts, where 0 == 32
7325 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7326 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007327 MCInst TmpInst;
7328 TmpInst.setOpcode(newOpc);
7329 TmpInst.addOperand(Inst.getOperand(0));
7330 TmpInst.addOperand(Inst.getOperand(1));
7331 TmpInst.addOperand(Inst.getOperand(2));
7332 TmpInst.addOperand(Inst.getOperand(4));
7333 TmpInst.addOperand(Inst.getOperand(5));
7334 TmpInst.addOperand(Inst.getOperand(6));
7335 Inst = TmpInst;
7336 return true;
7337 }
7338 return false;
7339 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007340 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007341 case ARM::t2IT: {
7342 // The mask bits for all but the first condition are represented as
7343 // the low bit of the condition code value implies 't'. We currently
7344 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007345 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007346 MCOperand &MO = Inst.getOperand(1);
7347 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007348 unsigned OrigMask = Mask;
7349 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007350 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007351 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7352 for (unsigned i = 3; i != TZ; --i)
7353 Mask ^= 1 << i;
Richard Bartonf435b092012-04-27 08:42:59 +00007354 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007355 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007356
7357 // Set up the IT block state according to the IT instruction we just
7358 // matched.
7359 assert(!inITBlock() && "nested IT blocks?!");
7360 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7361 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7362 ITState.CurPosition = 0;
7363 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007364 break;
7365 }
Richard Bartona39625e2012-07-09 16:12:24 +00007366 case ARM::t2LSLrr:
7367 case ARM::t2LSRrr:
7368 case ARM::t2ASRrr:
7369 case ARM::t2SBCrr:
7370 case ARM::t2RORrr:
7371 case ARM::t2BICrr:
7372 {
Richard Bartond5660372012-07-09 16:14:28 +00007373 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007374 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7375 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7376 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007377 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7378 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007379 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7380 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7381 unsigned NewOpc;
7382 switch (Inst.getOpcode()) {
7383 default: llvm_unreachable("unexpected opcode");
7384 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7385 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7386 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7387 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7388 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7389 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7390 }
7391 MCInst TmpInst;
7392 TmpInst.setOpcode(NewOpc);
7393 TmpInst.addOperand(Inst.getOperand(0));
7394 TmpInst.addOperand(Inst.getOperand(5));
7395 TmpInst.addOperand(Inst.getOperand(1));
7396 TmpInst.addOperand(Inst.getOperand(2));
7397 TmpInst.addOperand(Inst.getOperand(3));
7398 TmpInst.addOperand(Inst.getOperand(4));
7399 Inst = TmpInst;
7400 return true;
7401 }
7402 return false;
7403 }
7404 case ARM::t2ANDrr:
7405 case ARM::t2EORrr:
7406 case ARM::t2ADCrr:
7407 case ARM::t2ORRrr:
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 // These instructions are special in that they are commutable, so shorter encodings
7411 // are available more often.
7412 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7413 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7414 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7415 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007416 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7417 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007418 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7419 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7420 unsigned NewOpc;
7421 switch (Inst.getOpcode()) {
7422 default: llvm_unreachable("unexpected opcode");
7423 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7424 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7425 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7426 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7427 }
7428 MCInst TmpInst;
7429 TmpInst.setOpcode(NewOpc);
7430 TmpInst.addOperand(Inst.getOperand(0));
7431 TmpInst.addOperand(Inst.getOperand(5));
7432 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7433 TmpInst.addOperand(Inst.getOperand(1));
7434 TmpInst.addOperand(Inst.getOperand(2));
7435 } else {
7436 TmpInst.addOperand(Inst.getOperand(2));
7437 TmpInst.addOperand(Inst.getOperand(1));
7438 }
7439 TmpInst.addOperand(Inst.getOperand(3));
7440 TmpInst.addOperand(Inst.getOperand(4));
7441 Inst = TmpInst;
7442 return true;
7443 }
7444 return false;
7445 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007446 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007447 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007448}
7449
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007450unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7451 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7452 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007453 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007454 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007455 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7456 assert(MCID.hasOptionalDef() &&
7457 "optionally flag setting instruction missing optional def operand");
7458 assert(MCID.NumOperands == Inst.getNumOperands() &&
7459 "operand count mismatch!");
7460 // Find the optional-def operand (cc_out).
7461 unsigned OpNo;
7462 for (OpNo = 0;
7463 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7464 ++OpNo)
7465 ;
7466 // If we're parsing Thumb1, reject it completely.
7467 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7468 return Match_MnemonicFail;
7469 // If we're parsing Thumb2, which form is legal depends on whether we're
7470 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007471 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7472 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007473 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007474 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7475 inITBlock())
7476 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007477 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007478 // Some high-register supporting Thumb1 encodings only allow both registers
7479 // to be from r0-r7 when in Thumb2.
7480 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7481 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7482 isARMLowRegister(Inst.getOperand(2).getReg()))
7483 return Match_RequiresThumb2;
7484 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007485 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007486 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7487 isARMLowRegister(Inst.getOperand(1).getReg()))
7488 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007489 return Match_Success;
7490}
7491
Jim Grosbach5117ef72012-04-24 22:40:08 +00007492static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007493bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007494MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007495 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007496 MCStreamer &Out, unsigned &ErrorInfo,
7497 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007498 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007499 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007500
Chad Rosier2f480a82012-10-12 22:53:36 +00007501 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007502 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007503 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007504 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007505 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007506 // Context sensitive operand constraints aren't handled by the matcher,
7507 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007508 if (validateInstruction(Inst, Operands)) {
7509 // Still progress the IT block, otherwise one wrong condition causes
7510 // nasty cascading errors.
7511 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007512 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007513 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007514
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007515 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007516 // encoding is selected. Loop on it while changes happen so the
7517 // individual transformations can chain off each other. E.g.,
7518 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7519 while (processInstruction(Inst, Operands))
7520 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007521
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007522 // Only move forward at the very end so that everything in validate
7523 // and process gets a consistent answer about whether we're in an IT
7524 // block.
7525 forwardITPosition();
7526
Jim Grosbach82f76d12012-01-25 19:52:01 +00007527 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7528 // doesn't actually encode.
7529 if (Inst.getOpcode() == ARM::ITasm)
7530 return false;
7531
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007532 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007533 Out.EmitInstruction(Inst);
7534 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007535 case Match_MissingFeature: {
7536 assert(ErrorInfo && "Unknown missing feature!");
7537 // Special case the error message for the very common case where only
7538 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7539 std::string Msg = "instruction requires:";
7540 unsigned Mask = 1;
7541 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7542 if (ErrorInfo & Mask) {
7543 Msg += " ";
7544 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7545 }
7546 Mask <<= 1;
7547 }
7548 return Error(IDLoc, Msg);
7549 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007550 case Match_InvalidOperand: {
7551 SMLoc ErrorLoc = IDLoc;
7552 if (ErrorInfo != ~0U) {
7553 if (ErrorInfo >= Operands.size())
7554 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007555
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007556 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7557 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7558 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007559
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007560 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007561 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007562 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007563 return Error(IDLoc, "invalid instruction",
7564 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007565 case Match_RequiresNotITBlock:
7566 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007567 case Match_RequiresITBlock:
7568 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007569 case Match_RequiresV6:
7570 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7571 case Match_RequiresThumb2:
7572 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007573 case Match_ImmRange0_15: {
7574 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7575 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7576 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7577 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007578 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007579
Eric Christopher91d7b902010-10-29 09:26:59 +00007580 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007581}
7582
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007583/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007584bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7585 StringRef IDVal = DirectiveID.getIdentifier();
7586 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007587 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007588 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007589 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007590 else if (IDVal == ".arm")
7591 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007592 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007593 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007594 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007595 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007596 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007597 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007598 else if (IDVal == ".unreq")
7599 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007600 else if (IDVal == ".arch")
7601 return parseDirectiveArch(DirectiveID.getLoc());
7602 else if (IDVal == ".eabi_attribute")
7603 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007604 return true;
7605}
7606
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007607/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007608/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007609bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007610 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7611 for (;;) {
7612 const MCExpr *Value;
7613 if (getParser().ParseExpression(Value))
7614 return true;
7615
Eric Christopherbf7bc492013-01-09 03:52:05 +00007616 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007617
7618 if (getLexer().is(AsmToken::EndOfStatement))
7619 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007620
Kevin Enderbyccab3172009-09-15 00:27:25 +00007621 // FIXME: Improve diagnostic.
7622 if (getLexer().isNot(AsmToken::Comma))
7623 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007624 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007625 }
7626 }
7627
Sean Callanana83fd7d2010-01-19 20:27:46 +00007628 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007629 return false;
7630}
7631
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007632/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007633/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007634bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007635 if (getLexer().isNot(AsmToken::EndOfStatement))
7636 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007637 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007638
Jim Grosbach7f882392011-12-07 18:04:19 +00007639 if (!isThumb())
7640 SwitchMode();
7641 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7642 return false;
7643}
7644
7645/// parseDirectiveARM
7646/// ::= .arm
7647bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7648 if (getLexer().isNot(AsmToken::EndOfStatement))
7649 return Error(L, "unexpected token in directive");
7650 Parser.Lex();
7651
7652 if (isThumb())
7653 SwitchMode();
7654 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007655 return false;
7656}
7657
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007658/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007659/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007660bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007661 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7662 bool isMachO = MAI.hasSubsectionsViaSymbols();
7663 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007664 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007665
Jim Grosbach1152cc02011-12-21 22:30:16 +00007666 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007667 // ELF doesn't
7668 if (isMachO) {
7669 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007670 if (Tok.isNot(AsmToken::EndOfStatement)) {
7671 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7672 return Error(L, "unexpected token in .thumb_func directive");
7673 Name = Tok.getIdentifier();
7674 Parser.Lex(); // Consume the identifier token.
7675 needFuncName = false;
7676 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007677 }
7678
Jim Grosbach1152cc02011-12-21 22:30:16 +00007679 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007680 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007681
7682 // Eat the end of statement and any blank lines that follow.
7683 while (getLexer().is(AsmToken::EndOfStatement))
7684 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007685
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007686 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007687 // We really should be checking the next symbol definition even if there's
7688 // stuff in between.
7689 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007690 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007691 }
7692
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007693 // Mark symbol as a thumb symbol.
7694 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7695 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007696 return false;
7697}
7698
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007699/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007700/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007701bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007702 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007703 if (Tok.isNot(AsmToken::Identifier))
7704 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007705 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007706 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007707 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007708 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007709 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007710 else
7711 return Error(L, "unrecognized syntax mode in .syntax directive");
7712
7713 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007714 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007715 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007716
7717 // TODO tell the MC streamer the mode
7718 // getParser().getStreamer().Emit???();
7719 return false;
7720}
7721
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007722/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007723/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007724bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007725 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007726 if (Tok.isNot(AsmToken::Integer))
7727 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007728 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007729 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007730 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007731 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007732 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007733 else
7734 return Error(L, "invalid operand to .code directive");
7735
7736 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007737 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007738 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007739
Evan Cheng284b4672011-07-08 22:36:29 +00007740 if (Val == 16) {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007741 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007742 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007743 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007744 } else {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007745 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007746 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007747 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007748 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007749
Kevin Enderby146dcf22009-10-15 20:48:48 +00007750 return false;
7751}
7752
Jim Grosbachab5830e2011-12-14 02:16:11 +00007753/// parseDirectiveReq
7754/// ::= name .req registername
7755bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7756 Parser.Lex(); // Eat the '.req' token.
7757 unsigned Reg;
7758 SMLoc SRegLoc, ERegLoc;
7759 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7760 Parser.EatToEndOfStatement();
7761 return Error(SRegLoc, "register name expected");
7762 }
7763
7764 // Shouldn't be anything else.
7765 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7766 Parser.EatToEndOfStatement();
7767 return Error(Parser.getTok().getLoc(),
7768 "unexpected input in .req directive.");
7769 }
7770
7771 Parser.Lex(); // Consume the EndOfStatement
7772
7773 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7774 return Error(SRegLoc, "redefinition of '" + Name +
7775 "' does not match original.");
7776
7777 return false;
7778}
7779
7780/// parseDirectiveUneq
7781/// ::= .unreq registername
7782bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7783 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7784 Parser.EatToEndOfStatement();
7785 return Error(L, "unexpected input in .unreq directive.");
7786 }
7787 RegisterReqs.erase(Parser.getTok().getIdentifier());
7788 Parser.Lex(); // Eat the identifier.
7789 return false;
7790}
7791
Jason W Kim135d2442011-12-20 17:38:12 +00007792/// parseDirectiveArch
7793/// ::= .arch token
7794bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7795 return true;
7796}
7797
7798/// parseDirectiveEabiAttr
7799/// ::= .eabi_attribute int, int
7800bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7801 return true;
7802}
7803
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007804/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007805extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007806 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7807 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007808}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007809
Chris Lattner3e4582a2010-09-06 19:11:01 +00007810#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00007811#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00007812#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007813#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00007814
7815// Define this matcher function after the auto-generated include so we
7816// have the match class enum definitions.
7817unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
7818 unsigned Kind) {
7819 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
7820 // If the kind is a token for a literal immediate, check if our asm
7821 // operand matches. This is for InstAliases which have a fixed-value
7822 // immediate in the syntax.
7823 if (Kind == MCK__35_0 && Op->isImm()) {
7824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
7825 if (!CE)
7826 return Match_InvalidOperand;
7827 if (CE->getValue() == 0)
7828 return Match_Success;
7829 }
7830 return Match_InvalidOperand;
7831}