blob: 314d37d7d589972d9ce9d4a741f4e64b2886ebff [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
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000093 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000094 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Tim Northovera2292d02013-06-10 23:20:58 +0000155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
157 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
160 }
James Molloy21efa7d2011-09-28 14:21:38 +0000161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
163 }
Tim Northovera2292d02013-06-10 23:20:58 +0000164 bool hasARM() const {
165 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
166 }
167
Evan Cheng284b4672011-07-08 22:36:29 +0000168 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000169 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
170 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000171 }
James Molloy21efa7d2011-09-28 14:21:38 +0000172 bool isMClass() const {
173 return STI.getFeatureBits() & ARM::FeatureMClass;
174 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000175
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000176 /// @name Auto-generated Match Functions
177 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000178
Chris Lattner3e4582a2010-09-06 19:11:01 +0000179#define GET_ASSEMBLER_HEADER
180#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000181
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000182 /// }
183
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000184 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000185 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000186 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000187 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000188 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000189 OperandMatchResultTy parseCoprocOptionOperand(
190 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000191 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000192 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000193 OperandMatchResultTy parseInstSyncBarrierOptOperand(
194 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000195 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000196 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000197 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000198 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000199 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
200 StringRef Op, int Low, int High);
201 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
202 return parsePKHImm(O, "lsl", 0, 31);
203 }
204 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "asr", 1, 32);
206 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000207 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000208 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000209 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000210 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000211 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000212 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000213 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000214 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000215 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
216 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000217
218 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000219 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
220 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
221 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000222 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000223 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000224 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000225 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000226 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000227 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000228 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000229 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000230 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000231 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000232 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000233 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000234 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000235 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000236 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000237 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000238 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000239 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000240 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000241 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000242 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000243 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
244 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
245 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000246 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000247 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000248 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000249 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000250 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000251 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000252 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000253 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000254 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000255 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000256 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000257 bool validateInstruction(MCInst &Inst,
258 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000259 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000260 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000261 bool shouldOmitCCOutOperand(StringRef Mnemonic,
262 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000263
Kevin Enderbyccab3172009-09-15 00:27:25 +0000264public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000265 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000266 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000267 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000268 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000269 Match_RequiresThumb2,
270#define GET_OPERAND_DIAGNOSTIC_TYPES
271#include "ARMGenAsmMatcher.inc"
272
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000273 };
274
Evan Cheng91111d22011-07-09 05:47:46 +0000275 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000276 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000277 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000278
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000279 // Cache the MCRegisterInfo.
280 MRI = &getContext().getRegisterInfo();
281
Evan Cheng4d1ca962011-07-08 01:53:10 +0000282 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000283 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000284
285 // Not in an ITBlock to start with.
286 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000287
288 // Set ELF header flags.
289 // FIXME: This should eventually end up somewhere else where more
290 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000291 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
292 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
293 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000294 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000295
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000296 // Implementation of the MCTargetAsmParser interface:
297 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000298 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
299 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000300 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000301 bool ParseDirective(AsmToken DirectiveID);
302
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000303 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000304 unsigned checkTargetMatchPredicate(MCInst &Inst);
305
Chad Rosier49963552012-10-13 00:26:04 +0000306 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000307 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000308 MCStreamer &Out, unsigned &ErrorInfo,
309 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000310};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000311} // end anonymous namespace
312
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000313namespace {
314
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000315/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000316/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000317class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000318 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000319 k_CondCode,
320 k_CCOut,
321 k_ITCondMask,
322 k_CoprocNum,
323 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000324 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000325 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000326 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000327 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000328 k_Memory,
329 k_PostIndexRegister,
330 k_MSRMask,
331 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000332 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000333 k_Register,
334 k_RegisterList,
335 k_DPRRegisterList,
336 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000337 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000338 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000339 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000340 k_ShiftedRegister,
341 k_ShiftedImmediate,
342 k_ShifterImmediate,
343 k_RotateImmediate,
344 k_BitfieldDescriptor,
345 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000346 } Kind;
347
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000348 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000349 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000350
Eric Christopher8996c5d2013-03-15 00:42:55 +0000351 struct CCOp {
352 ARMCC::CondCodes Val;
353 };
354
355 struct CopOp {
356 unsigned Val;
357 };
358
359 struct CoprocOptionOp {
360 unsigned Val;
361 };
362
363 struct ITMaskOp {
364 unsigned Mask:4;
365 };
366
367 struct MBOptOp {
368 ARM_MB::MemBOpt Val;
369 };
370
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000371 struct ISBOptOp {
372 ARM_ISB::InstSyncBOpt Val;
373 };
374
Eric Christopher8996c5d2013-03-15 00:42:55 +0000375 struct IFlagsOp {
376 ARM_PROC::IFlags Val;
377 };
378
379 struct MMaskOp {
380 unsigned Val;
381 };
382
383 struct TokOp {
384 const char *Data;
385 unsigned Length;
386 };
387
388 struct RegOp {
389 unsigned RegNum;
390 };
391
392 // A vector register list is a sequential list of 1 to 4 registers.
393 struct VectorListOp {
394 unsigned RegNum;
395 unsigned Count;
396 unsigned LaneIndex;
397 bool isDoubleSpaced;
398 };
399
400 struct VectorIndexOp {
401 unsigned Val;
402 };
403
404 struct ImmOp {
405 const MCExpr *Val;
406 };
407
408 /// Combined record for all forms of ARM address expressions.
409 struct MemoryOp {
410 unsigned BaseRegNum;
411 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
412 // was specified.
413 const MCConstantExpr *OffsetImm; // Offset immediate value
414 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
415 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
416 unsigned ShiftImm; // shift for OffsetReg.
417 unsigned Alignment; // 0 = no alignment specified
418 // n = alignment in bytes (2, 4, 8, 16, or 32)
419 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
420 };
421
422 struct PostIdxRegOp {
423 unsigned RegNum;
424 bool isAdd;
425 ARM_AM::ShiftOpc ShiftTy;
426 unsigned ShiftImm;
427 };
428
429 struct ShifterImmOp {
430 bool isASR;
431 unsigned Imm;
432 };
433
434 struct RegShiftedRegOp {
435 ARM_AM::ShiftOpc ShiftTy;
436 unsigned SrcReg;
437 unsigned ShiftReg;
438 unsigned ShiftImm;
439 };
440
441 struct RegShiftedImmOp {
442 ARM_AM::ShiftOpc ShiftTy;
443 unsigned SrcReg;
444 unsigned ShiftImm;
445 };
446
447 struct RotImmOp {
448 unsigned Imm;
449 };
450
451 struct BitfieldOp {
452 unsigned LSB;
453 unsigned Width;
454 };
455
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000456 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000457 struct CCOp CC;
458 struct CopOp Cop;
459 struct CoprocOptionOp CoprocOption;
460 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000461 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000462 struct ITMaskOp ITMask;
463 struct IFlagsOp IFlags;
464 struct MMaskOp MMask;
465 struct TokOp Tok;
466 struct RegOp Reg;
467 struct VectorListOp VectorList;
468 struct VectorIndexOp VectorIndex;
469 struct ImmOp Imm;
470 struct MemoryOp Memory;
471 struct PostIdxRegOp PostIdxReg;
472 struct ShifterImmOp ShifterImm;
473 struct RegShiftedRegOp RegShiftedReg;
474 struct RegShiftedImmOp RegShiftedImm;
475 struct RotImmOp RotImm;
476 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000477 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000478
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000479 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
480public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000481 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
482 Kind = o.Kind;
483 StartLoc = o.StartLoc;
484 EndLoc = o.EndLoc;
485 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000486 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000487 CC = o.CC;
488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000490 ITMask = o.ITMask;
491 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000492 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000493 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000494 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000495 case k_CCOut:
496 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000497 Reg = o.Reg;
498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_RegisterList:
500 case k_DPRRegisterList:
501 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000502 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000503 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000504 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000505 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000506 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000507 VectorList = o.VectorList;
508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 case k_CoprocNum:
510 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000511 Cop = o.Cop;
512 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000513 case k_CoprocOption:
514 CoprocOption = o.CoprocOption;
515 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000516 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000517 Imm = o.Imm;
518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000519 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000520 MBOpt = o.MBOpt;
521 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000522 case k_InstSyncBarrierOpt:
523 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000524 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000525 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000526 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000527 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000528 PostIdxReg = o.PostIdxReg;
529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000530 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000531 MMask = o.MMask;
532 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000533 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000534 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000536 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000537 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000540 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000541 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000542 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000543 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000544 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000546 RotImm = o.RotImm;
547 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000548 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000549 Bitfield = o.Bitfield;
550 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000551 case k_VectorIndex:
552 VectorIndex = o.VectorIndex;
553 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000554 }
555 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000556
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000557 /// getStartLoc - Get the location of the first token of this operand.
558 SMLoc getStartLoc() const { return StartLoc; }
559 /// getEndLoc - Get the location of the last token of this operand.
560 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000561 /// getLocRange - Get the range between the first and last token of this
562 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000563 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
564
Daniel Dunbard8042b72010-08-11 06:36:53 +0000565 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000566 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000567 return CC.Val;
568 }
569
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000570 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000572 return Cop.Val;
573 }
574
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000575 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000576 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000577 return StringRef(Tok.Data, Tok.Length);
578 }
579
580 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000582 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000583 }
584
Bill Wendlingbed94652010-11-09 23:28:44 +0000585 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000586 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
587 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000588 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000589 }
590
Kevin Enderbyf5079942009-10-13 22:19:02 +0000591 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000592 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000593 return Imm.Val;
594 }
595
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000596 unsigned getVectorIndex() const {
597 assert(Kind == k_VectorIndex && "Invalid access!");
598 return VectorIndex.Val;
599 }
600
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000601 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000602 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000603 return MBOpt.Val;
604 }
605
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000606 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
607 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
608 return ISBOpt.Val;
609 }
610
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000611 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000612 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000613 return IFlags.Val;
614 }
615
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000616 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000617 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000618 return MMask.Val;
619 }
620
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000621 bool isCoprocNum() const { return Kind == k_CoprocNum; }
622 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000623 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000624 bool isCondCode() const { return Kind == k_CondCode; }
625 bool isCCOut() const { return Kind == k_CCOut; }
626 bool isITMask() const { return Kind == k_ITCondMask; }
627 bool isITCondCode() const { return Kind == k_CondCode; }
628 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000629 bool isFPImm() const {
630 if (!isImm()) return false;
631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
632 if (!CE) return false;
633 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
634 return Val != -1;
635 }
Jim Grosbachea231912011-12-22 22:19:05 +0000636 bool isFBits16() const {
637 if (!isImm()) return false;
638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
639 if (!CE) return false;
640 int64_t Value = CE->getValue();
641 return Value >= 0 && Value <= 16;
642 }
643 bool isFBits32() const {
644 if (!isImm()) return false;
645 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
646 if (!CE) return false;
647 int64_t Value = CE->getValue();
648 return Value >= 1 && Value <= 32;
649 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000650 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000651 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
653 if (!CE) return false;
654 int64_t Value = CE->getValue();
655 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
656 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000657 bool isImm0_4() const {
658 if (!isImm()) return false;
659 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
660 if (!CE) return false;
661 int64_t Value = CE->getValue();
662 return Value >= 0 && Value < 5;
663 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000664 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000665 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
667 if (!CE) return false;
668 int64_t Value = CE->getValue();
669 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
670 }
671 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000672 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
674 if (!CE) return false;
675 int64_t Value = CE->getValue();
676 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
677 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000678 bool isImm0_508s4Neg() const {
679 if (!isImm()) return false;
680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
681 if (!CE) return false;
682 int64_t Value = -CE->getValue();
683 // explicitly exclude zero. we want that to use the normal 0_508 version.
684 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
685 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000686 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000687 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
689 if (!CE) return false;
690 int64_t Value = CE->getValue();
691 return Value >= 0 && Value < 256;
692 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000693 bool isImm0_4095() const {
694 if (!isImm()) return false;
695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
696 if (!CE) return false;
697 int64_t Value = CE->getValue();
698 return Value >= 0 && Value < 4096;
699 }
700 bool isImm0_4095Neg() const {
701 if (!isImm()) return false;
702 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
703 if (!CE) return false;
704 int64_t Value = -CE->getValue();
705 return Value > 0 && Value < 4096;
706 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000707 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000708 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000709 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
710 if (!CE) return false;
711 int64_t Value = CE->getValue();
712 return Value >= 0 && Value < 2;
713 }
714 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000715 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000716 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
717 if (!CE) return false;
718 int64_t Value = CE->getValue();
719 return Value >= 0 && Value < 4;
720 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000721 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000722 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000723 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
724 if (!CE) return false;
725 int64_t Value = CE->getValue();
726 return Value >= 0 && Value < 8;
727 }
728 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000729 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
731 if (!CE) return false;
732 int64_t Value = CE->getValue();
733 return Value >= 0 && Value < 16;
734 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000735 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000736 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
738 if (!CE) return false;
739 int64_t Value = CE->getValue();
740 return Value >= 0 && Value < 32;
741 }
Jim Grosbach00326402011-12-08 01:30:04 +0000742 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000743 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
745 if (!CE) return false;
746 int64_t Value = CE->getValue();
747 return Value >= 0 && Value < 64;
748 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000749 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000750 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
752 if (!CE) return false;
753 int64_t Value = CE->getValue();
754 return Value == 8;
755 }
756 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000757 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
759 if (!CE) return false;
760 int64_t Value = CE->getValue();
761 return Value == 16;
762 }
763 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000764 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
766 if (!CE) return false;
767 int64_t Value = CE->getValue();
768 return Value == 32;
769 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000770 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000771 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
773 if (!CE) return false;
774 int64_t Value = CE->getValue();
775 return Value > 0 && Value <= 8;
776 }
777 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000778 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
780 if (!CE) return false;
781 int64_t Value = CE->getValue();
782 return Value > 0 && Value <= 16;
783 }
784 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000785 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
787 if (!CE) return false;
788 int64_t Value = CE->getValue();
789 return Value > 0 && Value <= 32;
790 }
791 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000792 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
794 if (!CE) return false;
795 int64_t Value = CE->getValue();
796 return Value > 0 && Value <= 64;
797 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000798 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000799 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
801 if (!CE) return false;
802 int64_t Value = CE->getValue();
803 return Value > 0 && Value < 8;
804 }
805 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000806 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000807 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
808 if (!CE) return false;
809 int64_t Value = CE->getValue();
810 return Value > 0 && Value < 16;
811 }
812 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000813 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
815 if (!CE) return false;
816 int64_t Value = CE->getValue();
817 return Value > 0 && Value < 32;
818 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000819 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000820 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
824 return Value > 0 && Value < 17;
825 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000826 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000827 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return Value > 0 && Value < 33;
832 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000833 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000834 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 return Value >= 0 && Value < 33;
839 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000840 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000841 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
843 if (!CE) return false;
844 int64_t Value = CE->getValue();
845 return Value >= 0 && Value < 65536;
846 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000847 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000848 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
850 // If it's not a constant expression, it'll generate a fixup and be
851 // handled later.
852 if (!CE) return true;
853 int64_t Value = CE->getValue();
854 return Value >= 0 && Value < 65536;
855 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000856 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000857 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value >= 0 && Value <= 0xffffff;
862 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000863 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000864 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value > 0 && Value < 33;
869 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000870 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000871 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 if (!CE) return false;
874 int64_t Value = CE->getValue();
875 return Value >= 0 && Value < 32;
876 }
877 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000878 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000879 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
880 if (!CE) return false;
881 int64_t Value = CE->getValue();
882 return Value > 0 && Value <= 32;
883 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000884 bool isAdrLabel() const {
885 // If we have an immediate that's not a constant, treat it as a label
886 // reference needing a fixup. If it is a constant, but it can't fit
887 // into shift immediate encoding, we reject it.
888 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
889 else return (isARMSOImm() || isARMSOImmNeg());
890 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000891 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000892 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
894 if (!CE) return false;
895 int64_t Value = CE->getValue();
896 return ARM_AM::getSOImmVal(Value) != -1;
897 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000898 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000899 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
901 if (!CE) return false;
902 int64_t Value = CE->getValue();
903 return ARM_AM::getSOImmVal(~Value) != -1;
904 }
Jim Grosbach30506252011-12-08 00:31:07 +0000905 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000906 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000910 // Only use this when not representable as a plain so_imm.
911 return ARM_AM::getSOImmVal(Value) == -1 &&
912 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000913 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000914 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000915 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
917 if (!CE) return false;
918 int64_t Value = CE->getValue();
919 return ARM_AM::getT2SOImmVal(Value) != -1;
920 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000921 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000922 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000923 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
924 if (!CE) return false;
925 int64_t Value = CE->getValue();
926 return ARM_AM::getT2SOImmVal(~Value) != -1;
927 }
Jim Grosbach30506252011-12-08 00:31:07 +0000928 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000929 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000930 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
931 if (!CE) return false;
932 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000933 // Only use this when not representable as a plain so_imm.
934 return ARM_AM::getT2SOImmVal(Value) == -1 &&
935 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000936 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000937 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000938 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return Value == 1 || Value == 0;
943 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000944 bool isReg() const { return Kind == k_Register; }
945 bool isRegList() const { return Kind == k_RegisterList; }
946 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
947 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
948 bool isToken() const { return Kind == k_Token; }
949 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000950 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000951 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000952 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
953 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
954 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
955 bool isRotImm() const { return Kind == k_RotateImmediate; }
956 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
957 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000958 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000959 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000960 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000961 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000962 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000963 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000964 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000965 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
966 (alignOK || Memory.Alignment == 0);
967 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000968 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000969 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000970 return false;
971 // Base register must be PC.
972 if (Memory.BaseRegNum != ARM::PC)
973 return false;
974 // Immediate offset in range [-4095, 4095].
975 if (!Memory.OffsetImm) return true;
976 int64_t Val = Memory.OffsetImm->getValue();
977 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
978 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000979 bool isAlignedMemory() const {
980 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000981 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000982 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000983 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000984 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000985 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000986 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000987 if (!Memory.OffsetImm) return true;
988 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000989 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000990 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000991 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000992 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000993 // Immediate offset in range [-4095, 4095].
994 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
995 if (!CE) return false;
996 int64_t Val = CE->getValue();
997 return Val > -4096 && Val < 4096;
998 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000999 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001000 // If we have an immediate that's not a constant, treat it as a label
1001 // reference needing a fixup. If it is a constant, it's something else
1002 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001003 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001004 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001005 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001006 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001007 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001008 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001009 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001010 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001011 if (!Memory.OffsetImm) return true;
1012 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001013 // The #-0 offset is encoded as INT32_MIN, and we have to check
1014 // for this too.
1015 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001016 }
1017 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001018 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001019 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001020 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001021 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1022 // Immediate offset in range [-255, 255].
1023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1024 if (!CE) return false;
1025 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001026 // Special case, #-0 is INT32_MIN.
1027 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001028 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001029 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001030 // If we have an immediate that's not a constant, treat it as a label
1031 // reference needing a fixup. If it is a constant, it's something else
1032 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001033 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001034 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001035 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001036 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001037 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001038 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001039 if (!Memory.OffsetImm) return true;
1040 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001041 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001042 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001043 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001044 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001045 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001046 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001047 return false;
1048 return true;
1049 }
1050 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001051 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001052 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1053 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001054 return false;
1055 return true;
1056 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001057 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001058 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001059 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001060 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001061 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001062 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001063 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001064 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001065 return false;
1066 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001067 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001068 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001069 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001070 return false;
1071 return true;
1072 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001073 bool isMemThumbRR() const {
1074 // Thumb reg+reg addressing is simple. Just two registers, a base and
1075 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001076 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001077 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001078 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001079 return isARMLowRegister(Memory.BaseRegNum) &&
1080 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001081 }
1082 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001083 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001084 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001085 return false;
1086 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001087 if (!Memory.OffsetImm) return true;
1088 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001089 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1090 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001091 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001092 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001093 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001094 return false;
1095 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001096 if (!Memory.OffsetImm) return true;
1097 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001098 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1099 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001100 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001101 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001102 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001103 return false;
1104 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001105 if (!Memory.OffsetImm) return true;
1106 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001107 return Val >= 0 && Val <= 31;
1108 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001109 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001110 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001111 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001112 return false;
1113 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001114 if (!Memory.OffsetImm) return true;
1115 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001116 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001117 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001118 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001119 // If we have an immediate that's not a constant, treat it as a label
1120 // reference needing a fixup. If it is a constant, it's something else
1121 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001122 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001123 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001124 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001125 return false;
1126 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001127 if (!Memory.OffsetImm) return true;
1128 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001129 // Special case, #-0 is INT32_MIN.
1130 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001131 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001132 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001133 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001134 return false;
1135 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001136 if (!Memory.OffsetImm) return true;
1137 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001138 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1139 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001140 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001141 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001142 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001143 // Base reg of PC isn't allowed for these encodings.
1144 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001145 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001146 if (!Memory.OffsetImm) return true;
1147 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001148 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001149 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001150 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001151 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001152 return false;
1153 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001154 if (!Memory.OffsetImm) return true;
1155 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001156 return Val >= 0 && Val < 256;
1157 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001158 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001159 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001160 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001161 // Base reg of PC isn't allowed for these encodings.
1162 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001163 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001164 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001165 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001166 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001167 }
1168 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001169 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001170 return false;
1171 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001172 if (!Memory.OffsetImm) return true;
1173 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001174 return (Val >= 0 && Val < 4096);
1175 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001176 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001177 // If we have an immediate that's not a constant, treat it as a label
1178 // reference needing a fixup. If it is a constant, it's something else
1179 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001180 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001181 return true;
1182
Chad Rosier41099832012-09-11 23:02:35 +00001183 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001184 return false;
1185 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001186 if (!Memory.OffsetImm) return true;
1187 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001188 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001189 }
1190 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001191 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001192 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1193 if (!CE) return false;
1194 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001195 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001196 }
Jim Grosbach93981412011-10-11 21:55:36 +00001197 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001198 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001199 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1200 if (!CE) return false;
1201 int64_t Val = CE->getValue();
1202 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1203 (Val == INT32_MIN);
1204 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001205
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001206 bool isMSRMask() const { return Kind == k_MSRMask; }
1207 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001208
Jim Grosbach741cd732011-10-17 22:26:03 +00001209 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001210 bool isSingleSpacedVectorList() const {
1211 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1212 }
1213 bool isDoubleSpacedVectorList() const {
1214 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1215 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001216 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001217 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001218 return VectorList.Count == 1;
1219 }
1220
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001221 bool isVecListDPair() const {
1222 if (!isSingleSpacedVectorList()) return false;
1223 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1224 .contains(VectorList.RegNum));
1225 }
1226
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001227 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001228 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001229 return VectorList.Count == 3;
1230 }
1231
Jim Grosbach846bcff2011-10-21 20:35:01 +00001232 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001233 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001234 return VectorList.Count == 4;
1235 }
1236
Jim Grosbache5307f92012-03-05 21:43:40 +00001237 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001238 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001239 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1240 .contains(VectorList.RegNum));
1241 }
1242
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001243 bool isVecListThreeQ() const {
1244 if (!isDoubleSpacedVectorList()) return false;
1245 return VectorList.Count == 3;
1246 }
1247
Jim Grosbach1e946a42012-01-24 00:43:12 +00001248 bool isVecListFourQ() const {
1249 if (!isDoubleSpacedVectorList()) return false;
1250 return VectorList.Count == 4;
1251 }
1252
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001253 bool isSingleSpacedVectorAllLanes() const {
1254 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1255 }
1256 bool isDoubleSpacedVectorAllLanes() const {
1257 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1258 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001259 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001260 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001261 return VectorList.Count == 1;
1262 }
1263
Jim Grosbach13a292c2012-03-06 22:01:44 +00001264 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001265 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001266 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1267 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001268 }
1269
Jim Grosbached428bc2012-03-06 23:10:38 +00001270 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001271 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001272 return VectorList.Count == 2;
1273 }
1274
Jim Grosbachb78403c2012-01-24 23:47:04 +00001275 bool isVecListThreeDAllLanes() const {
1276 if (!isSingleSpacedVectorAllLanes()) return false;
1277 return VectorList.Count == 3;
1278 }
1279
1280 bool isVecListThreeQAllLanes() const {
1281 if (!isDoubleSpacedVectorAllLanes()) return false;
1282 return VectorList.Count == 3;
1283 }
1284
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001285 bool isVecListFourDAllLanes() const {
1286 if (!isSingleSpacedVectorAllLanes()) return false;
1287 return VectorList.Count == 4;
1288 }
1289
1290 bool isVecListFourQAllLanes() const {
1291 if (!isDoubleSpacedVectorAllLanes()) return false;
1292 return VectorList.Count == 4;
1293 }
1294
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001295 bool isSingleSpacedVectorIndexed() const {
1296 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1297 }
1298 bool isDoubleSpacedVectorIndexed() const {
1299 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1300 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001301 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001302 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001303 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1304 }
1305
Jim Grosbachda511042011-12-14 23:35:06 +00001306 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001307 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001308 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1309 }
1310
1311 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001312 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001313 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1314 }
1315
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001316 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001317 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001318 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1319 }
1320
Jim Grosbachda511042011-12-14 23:35:06 +00001321 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001322 if (!isSingleSpacedVectorIndexed()) return false;
1323 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1324 }
1325
1326 bool isVecListTwoQWordIndexed() const {
1327 if (!isDoubleSpacedVectorIndexed()) return false;
1328 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1329 }
1330
1331 bool isVecListTwoQHWordIndexed() const {
1332 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001333 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1334 }
1335
1336 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001337 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001338 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1339 }
1340
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001341 bool isVecListThreeDByteIndexed() const {
1342 if (!isSingleSpacedVectorIndexed()) return false;
1343 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1344 }
1345
1346 bool isVecListThreeDHWordIndexed() const {
1347 if (!isSingleSpacedVectorIndexed()) return false;
1348 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1349 }
1350
1351 bool isVecListThreeQWordIndexed() const {
1352 if (!isDoubleSpacedVectorIndexed()) return false;
1353 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1354 }
1355
1356 bool isVecListThreeQHWordIndexed() const {
1357 if (!isDoubleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1359 }
1360
1361 bool isVecListThreeDWordIndexed() const {
1362 if (!isSingleSpacedVectorIndexed()) return false;
1363 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1364 }
1365
Jim Grosbach14952a02012-01-24 18:37:25 +00001366 bool isVecListFourDByteIndexed() const {
1367 if (!isSingleSpacedVectorIndexed()) return false;
1368 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1369 }
1370
1371 bool isVecListFourDHWordIndexed() const {
1372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1374 }
1375
1376 bool isVecListFourQWordIndexed() const {
1377 if (!isDoubleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1379 }
1380
1381 bool isVecListFourQHWordIndexed() const {
1382 if (!isDoubleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1384 }
1385
1386 bool isVecListFourDWordIndexed() const {
1387 if (!isSingleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1389 }
1390
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001391 bool isVectorIndex8() const {
1392 if (Kind != k_VectorIndex) return false;
1393 return VectorIndex.Val < 8;
1394 }
1395 bool isVectorIndex16() const {
1396 if (Kind != k_VectorIndex) return false;
1397 return VectorIndex.Val < 4;
1398 }
1399 bool isVectorIndex32() const {
1400 if (Kind != k_VectorIndex) return false;
1401 return VectorIndex.Val < 2;
1402 }
1403
Jim Grosbach741cd732011-10-17 22:26:03 +00001404 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001405 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001406 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1407 // Must be a constant.
1408 if (!CE) return false;
1409 int64_t Value = CE->getValue();
1410 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1411 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001412 return Value >= 0 && Value < 256;
1413 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001414
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001415 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001416 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001417 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1418 // Must be a constant.
1419 if (!CE) return false;
1420 int64_t Value = CE->getValue();
1421 // i16 value in the range [0,255] or [0x0100, 0xff00]
1422 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1423 }
1424
Jim Grosbach8211c052011-10-18 00:22:00 +00001425 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001426 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001427 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1428 // Must be a constant.
1429 if (!CE) return false;
1430 int64_t Value = CE->getValue();
1431 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1432 return (Value >= 0 && Value < 256) ||
1433 (Value >= 0x0100 && Value <= 0xff00) ||
1434 (Value >= 0x010000 && Value <= 0xff0000) ||
1435 (Value >= 0x01000000 && Value <= 0xff000000);
1436 }
1437
1438 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001439 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001440 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1441 // Must be a constant.
1442 if (!CE) return false;
1443 int64_t Value = CE->getValue();
1444 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1445 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1446 return (Value >= 0 && Value < 256) ||
1447 (Value >= 0x0100 && Value <= 0xff00) ||
1448 (Value >= 0x010000 && Value <= 0xff0000) ||
1449 (Value >= 0x01000000 && Value <= 0xff000000) ||
1450 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1451 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1452 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001453 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001454 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001455 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1456 // Must be a constant.
1457 if (!CE) return false;
1458 int64_t Value = ~CE->getValue();
1459 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1460 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1461 return (Value >= 0 && Value < 256) ||
1462 (Value >= 0x0100 && Value <= 0xff00) ||
1463 (Value >= 0x010000 && Value <= 0xff0000) ||
1464 (Value >= 0x01000000 && Value <= 0xff000000) ||
1465 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1466 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1467 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001468
Jim Grosbache4454e02011-10-18 16:18:11 +00001469 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001470 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001471 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1472 // Must be a constant.
1473 if (!CE) return false;
1474 uint64_t Value = CE->getValue();
1475 // i64 value with each byte being either 0 or 0xff.
1476 for (unsigned i = 0; i < 8; ++i)
1477 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1478 return true;
1479 }
1480
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001481 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001482 // Add as immediates when possible. Null MCExpr = 0.
1483 if (Expr == 0)
1484 Inst.addOperand(MCOperand::CreateImm(0));
1485 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001486 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1487 else
1488 Inst.addOperand(MCOperand::CreateExpr(Expr));
1489 }
1490
Daniel Dunbard8042b72010-08-11 06:36:53 +00001491 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001492 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001493 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001494 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1495 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001496 }
1497
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001498 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1499 assert(N == 1 && "Invalid number of operands!");
1500 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1501 }
1502
Jim Grosbach48399582011-10-12 17:34:41 +00001503 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1504 assert(N == 1 && "Invalid number of operands!");
1505 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1506 }
1507
1508 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1509 assert(N == 1 && "Invalid number of operands!");
1510 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1511 }
1512
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001513 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1514 assert(N == 1 && "Invalid number of operands!");
1515 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1516 }
1517
1518 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1519 assert(N == 1 && "Invalid number of operands!");
1520 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1521 }
1522
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001523 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1524 assert(N == 1 && "Invalid number of operands!");
1525 Inst.addOperand(MCOperand::CreateReg(getReg()));
1526 }
1527
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001528 void addRegOperands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 Inst.addOperand(MCOperand::CreateReg(getReg()));
1531 }
1532
Jim Grosbachac798e12011-07-25 20:49:51 +00001533 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001534 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001535 assert(isRegShiftedReg() &&
1536 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001537 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1538 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001539 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001540 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001541 }
1542
Jim Grosbachac798e12011-07-25 20:49:51 +00001543 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001544 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001545 assert(isRegShiftedImm() &&
1546 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001547 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001548 // Shift of #32 is encoded as 0 where permitted
1549 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001550 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001551 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001552 }
1553
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001554 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001555 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001556 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1557 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001558 }
1559
Bill Wendling8d2aa032010-11-08 23:49:57 +00001560 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001561 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001562 const SmallVectorImpl<unsigned> &RegList = getRegList();
1563 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001564 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1565 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001566 }
1567
Bill Wendling9898ac92010-11-17 04:32:08 +00001568 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1569 addRegListOperands(Inst, N);
1570 }
1571
1572 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1573 addRegListOperands(Inst, N);
1574 }
1575
Jim Grosbach833b9d32011-07-27 20:15:40 +00001576 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1577 assert(N == 1 && "Invalid number of operands!");
1578 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1579 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1580 }
1581
Jim Grosbach864b6092011-07-28 21:34:26 +00001582 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1583 assert(N == 1 && "Invalid number of operands!");
1584 // Munge the lsb/width into a bitfield mask.
1585 unsigned lsb = Bitfield.LSB;
1586 unsigned width = Bitfield.Width;
1587 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1588 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1589 (32 - (lsb + width)));
1590 Inst.addOperand(MCOperand::CreateImm(Mask));
1591 }
1592
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001593 void addImmOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
1595 addExpr(Inst, getImm());
1596 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001597
Jim Grosbachea231912011-12-22 22:19:05 +00001598 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1599 assert(N == 1 && "Invalid number of operands!");
1600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1601 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1602 }
1603
1604 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1605 assert(N == 1 && "Invalid number of operands!");
1606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1608 }
1609
Jim Grosbache7fbce72011-10-03 23:38:36 +00001610 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1614 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001615 }
1616
Jim Grosbach7db8d692011-09-08 22:07:06 +00001617 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 // FIXME: We really want to scale the value here, but the LDRD/STRD
1620 // instruction don't encode operands that way yet.
1621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1622 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1623 }
1624
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001625 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1626 assert(N == 1 && "Invalid number of operands!");
1627 // The immediate is scaled by four in the encoding and is stored
1628 // in the MCInst as such. Lop off the low two bits here.
1629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1630 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1631 }
1632
Jim Grosbach930f2f62012-04-05 20:57:13 +00001633 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 // The immediate is scaled by four in the encoding and is stored
1636 // in the MCInst as such. Lop off the low two bits here.
1637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1639 }
1640
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001641 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1642 assert(N == 1 && "Invalid number of operands!");
1643 // The immediate is scaled by four in the encoding and is stored
1644 // in the MCInst as such. Lop off the low two bits here.
1645 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1646 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1647 }
1648
Jim Grosbach475c6db2011-07-25 23:09:14 +00001649 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1650 assert(N == 1 && "Invalid number of operands!");
1651 // The constant encodes as the immediate-1, and we store in the instruction
1652 // the bits as encoded, so subtract off one here.
1653 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1654 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1655 }
1656
Jim Grosbach801e0a32011-07-22 23:16:18 +00001657 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 // The constant encodes as the immediate-1, and we store in the instruction
1660 // the bits as encoded, so subtract off one here.
1661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1662 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1663 }
1664
Jim Grosbach46dd4132011-08-17 21:51:27 +00001665 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1666 assert(N == 1 && "Invalid number of operands!");
1667 // The constant encodes as the immediate, except for 32, which encodes as
1668 // zero.
1669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1670 unsigned Imm = CE->getValue();
1671 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1672 }
1673
Jim Grosbach27c1e252011-07-21 17:23:04 +00001674 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1677 // the instruction as well.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 int Val = CE->getValue();
1680 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1681 }
1682
Jim Grosbachb009a872011-10-28 22:36:30 +00001683 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1684 assert(N == 1 && "Invalid number of operands!");
1685 // The operand is actually a t2_so_imm, but we have its bitwise
1686 // negation in the assembly source, so twiddle it here.
1687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1688 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1689 }
1690
Jim Grosbach30506252011-12-08 00:31:07 +00001691 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // The operand is actually a t2_so_imm, but we have its
1694 // negation in the assembly source, so twiddle it here.
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1697 }
1698
Jim Grosbach930f2f62012-04-05 20:57:13 +00001699 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1700 assert(N == 1 && "Invalid number of operands!");
1701 // The operand is actually an imm0_4095, but we have its
1702 // negation in the assembly source, so twiddle it here.
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1705 }
1706
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001707 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 // The operand is actually a so_imm, but we have its bitwise
1710 // negation in the assembly source, so twiddle it here.
1711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1712 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1713 }
1714
Jim Grosbach30506252011-12-08 00:31:07 +00001715 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1716 assert(N == 1 && "Invalid number of operands!");
1717 // The operand is actually a so_imm, but we have its
1718 // negation in the assembly source, so twiddle it here.
1719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1720 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1721 }
1722
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001723 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1724 assert(N == 1 && "Invalid number of operands!");
1725 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1726 }
1727
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001728 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1729 assert(N == 1 && "Invalid number of operands!");
1730 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1731 }
1732
Jim Grosbachd3595712011-08-03 23:50:40 +00001733 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1734 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001735 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001736 }
1737
Jim Grosbach94298a92012-01-18 22:46:46 +00001738 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1739 assert(N == 1 && "Invalid number of operands!");
1740 int32_t Imm = Memory.OffsetImm->getValue();
1741 // FIXME: Handle #-0
1742 if (Imm == INT32_MIN) Imm = 0;
1743 Inst.addOperand(MCOperand::CreateImm(Imm));
1744 }
1745
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001746 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1747 assert(N == 1 && "Invalid number of operands!");
1748 assert(isImm() && "Not an immediate!");
1749
1750 // If we have an immediate that's not a constant, treat it as a label
1751 // reference needing a fixup.
1752 if (!isa<MCConstantExpr>(getImm())) {
1753 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1754 return;
1755 }
1756
1757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1758 int Val = CE->getValue();
1759 Inst.addOperand(MCOperand::CreateImm(Val));
1760 }
1761
Jim Grosbacha95ec992011-10-11 17:29:55 +00001762 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1763 assert(N == 2 && "Invalid number of operands!");
1764 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1765 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1766 }
1767
Jim Grosbachd3595712011-08-03 23:50:40 +00001768 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1769 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001770 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1771 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001772 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1773 // Special case for #-0
1774 if (Val == INT32_MIN) Val = 0;
1775 if (Val < 0) Val = -Val;
1776 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1777 } else {
1778 // For register offset, we encode the shift type and negation flag
1779 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001780 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1781 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001782 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001783 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1784 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001785 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001786 }
1787
Jim Grosbachcd17c122011-08-04 23:01:30 +00001788 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 2 && "Invalid number of operands!");
1790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1791 assert(CE && "non-constant AM2OffsetImm operand!");
1792 int32_t Val = CE->getValue();
1793 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1794 // Special case for #-0
1795 if (Val == INT32_MIN) Val = 0;
1796 if (Val < 0) Val = -Val;
1797 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1798 Inst.addOperand(MCOperand::CreateReg(0));
1799 Inst.addOperand(MCOperand::CreateImm(Val));
1800 }
1801
Jim Grosbach5b96b802011-08-10 20:29:19 +00001802 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1803 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001804 // If we have an immediate that's not a constant, treat it as a label
1805 // reference needing a fixup. If it is a constant, it's something else
1806 // and we reject it.
1807 if (isImm()) {
1808 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1809 Inst.addOperand(MCOperand::CreateReg(0));
1810 Inst.addOperand(MCOperand::CreateImm(0));
1811 return;
1812 }
1813
Jim Grosbach871dff72011-10-11 15:59:20 +00001814 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1815 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001816 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1817 // Special case for #-0
1818 if (Val == INT32_MIN) Val = 0;
1819 if (Val < 0) Val = -Val;
1820 Val = ARM_AM::getAM3Opc(AddSub, Val);
1821 } else {
1822 // For register offset, we encode the shift type and negation flag
1823 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001824 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001825 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001826 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1827 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001828 Inst.addOperand(MCOperand::CreateImm(Val));
1829 }
1830
1831 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1832 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001833 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001834 int32_t Val =
1835 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1836 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1837 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001838 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001839 }
1840
1841 // Constant offset.
1842 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1843 int32_t Val = CE->getValue();
1844 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1845 // Special case for #-0
1846 if (Val == INT32_MIN) Val = 0;
1847 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001848 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001849 Inst.addOperand(MCOperand::CreateReg(0));
1850 Inst.addOperand(MCOperand::CreateImm(Val));
1851 }
1852
Jim Grosbachd3595712011-08-03 23:50:40 +00001853 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1854 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001855 // If we have an immediate that's not a constant, treat it as a label
1856 // reference needing a fixup. If it is a constant, it's something else
1857 // and we reject it.
1858 if (isImm()) {
1859 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1860 Inst.addOperand(MCOperand::CreateImm(0));
1861 return;
1862 }
1863
Jim Grosbachd3595712011-08-03 23:50:40 +00001864 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001865 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001866 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1867 // Special case for #-0
1868 if (Val == INT32_MIN) Val = 0;
1869 if (Val < 0) Val = -Val;
1870 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001871 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001872 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001873 }
1874
Jim Grosbach7db8d692011-09-08 22:07:06 +00001875 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001877 // If we have an immediate that's not a constant, treat it as a label
1878 // reference needing a fixup. If it is a constant, it's something else
1879 // and we reject it.
1880 if (isImm()) {
1881 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1882 Inst.addOperand(MCOperand::CreateImm(0));
1883 return;
1884 }
1885
Jim Grosbach871dff72011-10-11 15:59:20 +00001886 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1887 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001888 Inst.addOperand(MCOperand::CreateImm(Val));
1889 }
1890
Jim Grosbacha05627e2011-09-09 18:37:27 +00001891 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1892 assert(N == 2 && "Invalid number of operands!");
1893 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001894 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1895 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001896 Inst.addOperand(MCOperand::CreateImm(Val));
1897 }
1898
Jim Grosbachd3595712011-08-03 23:50:40 +00001899 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1900 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001901 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1902 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001903 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001904 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001905
Jim Grosbach2392c532011-09-07 23:39:14 +00001906 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1907 addMemImm8OffsetOperands(Inst, N);
1908 }
1909
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001910 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001911 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001912 }
1913
1914 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1915 assert(N == 2 && "Invalid number of operands!");
1916 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001917 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001918 addExpr(Inst, getImm());
1919 Inst.addOperand(MCOperand::CreateImm(0));
1920 return;
1921 }
1922
1923 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001924 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1925 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001926 Inst.addOperand(MCOperand::CreateImm(Val));
1927 }
1928
Jim Grosbachd3595712011-08-03 23:50:40 +00001929 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1930 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001931 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001932 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001933 addExpr(Inst, getImm());
1934 Inst.addOperand(MCOperand::CreateImm(0));
1935 return;
1936 }
1937
1938 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001939 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1940 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001941 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001942 }
Bill Wendling811c9362010-11-30 07:44:32 +00001943
Jim Grosbach05541f42011-09-19 22:21:13 +00001944 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001946 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1947 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001948 }
1949
1950 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1951 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001952 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1953 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001954 }
1955
Jim Grosbachd3595712011-08-03 23:50:40 +00001956 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1957 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001958 unsigned Val =
1959 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1960 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001961 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1962 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001963 Inst.addOperand(MCOperand::CreateImm(Val));
1964 }
1965
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001966 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1969 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1970 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001971 }
1972
Jim Grosbachd3595712011-08-03 23:50:40 +00001973 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001975 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1976 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001977 }
1978
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001979 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1980 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001981 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1982 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001983 Inst.addOperand(MCOperand::CreateImm(Val));
1984 }
1985
Jim Grosbach26d35872011-08-19 18:55:51 +00001986 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1987 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001988 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001990 Inst.addOperand(MCOperand::CreateImm(Val));
1991 }
1992
Jim Grosbacha32c7532011-08-19 18:49:59 +00001993 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001995 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1996 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001997 Inst.addOperand(MCOperand::CreateImm(Val));
1998 }
1999
Jim Grosbach23983d62011-08-19 18:13:48 +00002000 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2001 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002002 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2003 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002004 Inst.addOperand(MCOperand::CreateImm(Val));
2005 }
2006
Jim Grosbachd3595712011-08-03 23:50:40 +00002007 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2008 assert(N == 1 && "Invalid number of operands!");
2009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2010 assert(CE && "non-constant post-idx-imm8 operand!");
2011 int Imm = CE->getValue();
2012 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002013 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002014 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2015 Inst.addOperand(MCOperand::CreateImm(Imm));
2016 }
2017
Jim Grosbach93981412011-10-11 21:55:36 +00002018 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2019 assert(N == 1 && "Invalid number of operands!");
2020 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2021 assert(CE && "non-constant post-idx-imm8s4 operand!");
2022 int Imm = CE->getValue();
2023 bool isAdd = Imm >= 0;
2024 if (Imm == INT32_MIN) Imm = 0;
2025 // Immediate is scaled by 4.
2026 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2027 Inst.addOperand(MCOperand::CreateImm(Imm));
2028 }
2029
Jim Grosbachd3595712011-08-03 23:50:40 +00002030 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 2 && "Invalid number of operands!");
2032 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002033 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2034 }
2035
2036 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 2 && "Invalid number of operands!");
2038 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2039 // The sign, shift type, and shift amount are encoded in a single operand
2040 // using the AM2 encoding helpers.
2041 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2042 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2043 PostIdxReg.ShiftTy);
2044 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002045 }
2046
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002047 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2048 assert(N == 1 && "Invalid number of operands!");
2049 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2050 }
2051
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002052 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2055 }
2056
Jim Grosbach182b6a02011-11-29 23:51:09 +00002057 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002058 assert(N == 1 && "Invalid number of operands!");
2059 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2060 }
2061
Jim Grosbach04945c42011-12-02 00:35:16 +00002062 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2063 assert(N == 2 && "Invalid number of operands!");
2064 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2065 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2066 }
2067
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002068 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2069 assert(N == 1 && "Invalid number of operands!");
2070 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2071 }
2072
2073 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2074 assert(N == 1 && "Invalid number of operands!");
2075 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2076 }
2077
2078 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2079 assert(N == 1 && "Invalid number of operands!");
2080 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2081 }
2082
Jim Grosbach741cd732011-10-17 22:26:03 +00002083 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2084 assert(N == 1 && "Invalid number of operands!");
2085 // The immediate encodes the type of constant as well as the value.
2086 // Mask in that this is an i8 splat.
2087 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2088 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2089 }
2090
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002091 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2092 assert(N == 1 && "Invalid number of operands!");
2093 // The immediate encodes the type of constant as well as the value.
2094 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2095 unsigned Value = CE->getValue();
2096 if (Value >= 256)
2097 Value = (Value >> 8) | 0xa00;
2098 else
2099 Value |= 0x800;
2100 Inst.addOperand(MCOperand::CreateImm(Value));
2101 }
2102
Jim Grosbach8211c052011-10-18 00:22:00 +00002103 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2104 assert(N == 1 && "Invalid number of operands!");
2105 // The immediate encodes the type of constant as well as the value.
2106 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2107 unsigned Value = CE->getValue();
2108 if (Value >= 256 && Value <= 0xff00)
2109 Value = (Value >> 8) | 0x200;
2110 else if (Value > 0xffff && Value <= 0xff0000)
2111 Value = (Value >> 16) | 0x400;
2112 else if (Value > 0xffffff)
2113 Value = (Value >> 24) | 0x600;
2114 Inst.addOperand(MCOperand::CreateImm(Value));
2115 }
2116
2117 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2118 assert(N == 1 && "Invalid number of operands!");
2119 // The immediate encodes the type of constant as well as the value.
2120 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2121 unsigned Value = CE->getValue();
2122 if (Value >= 256 && Value <= 0xffff)
2123 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2124 else if (Value > 0xffff && Value <= 0xffffff)
2125 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2126 else if (Value > 0xffffff)
2127 Value = (Value >> 24) | 0x600;
2128 Inst.addOperand(MCOperand::CreateImm(Value));
2129 }
2130
Jim Grosbach045b6c72011-12-19 23:51:07 +00002131 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2132 assert(N == 1 && "Invalid number of operands!");
2133 // The immediate encodes the type of constant as well as the value.
2134 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2135 unsigned Value = ~CE->getValue();
2136 if (Value >= 256 && Value <= 0xffff)
2137 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2138 else if (Value > 0xffff && Value <= 0xffffff)
2139 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2140 else if (Value > 0xffffff)
2141 Value = (Value >> 24) | 0x600;
2142 Inst.addOperand(MCOperand::CreateImm(Value));
2143 }
2144
Jim Grosbache4454e02011-10-18 16:18:11 +00002145 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 // The immediate encodes the type of constant as well as the value.
2148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2149 uint64_t Value = CE->getValue();
2150 unsigned Imm = 0;
2151 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2152 Imm |= (Value & 1) << i;
2153 }
2154 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2155 }
2156
Jim Grosbach602aa902011-07-13 15:34:57 +00002157 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002158
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002159 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002160 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002161 Op->ITMask.Mask = Mask;
2162 Op->StartLoc = S;
2163 Op->EndLoc = S;
2164 return Op;
2165 }
2166
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002167 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002168 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002169 Op->CC.Val = CC;
2170 Op->StartLoc = S;
2171 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002172 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002173 }
2174
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002175 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002176 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002177 Op->Cop.Val = CopVal;
2178 Op->StartLoc = S;
2179 Op->EndLoc = S;
2180 return Op;
2181 }
2182
2183 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002184 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002185 Op->Cop.Val = CopVal;
2186 Op->StartLoc = S;
2187 Op->EndLoc = S;
2188 return Op;
2189 }
2190
Jim Grosbach48399582011-10-12 17:34:41 +00002191 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2192 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2193 Op->Cop.Val = Val;
2194 Op->StartLoc = S;
2195 Op->EndLoc = E;
2196 return Op;
2197 }
2198
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002199 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002200 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002201 Op->Reg.RegNum = RegNum;
2202 Op->StartLoc = S;
2203 Op->EndLoc = S;
2204 return Op;
2205 }
2206
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002207 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002208 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002209 Op->Tok.Data = Str.data();
2210 Op->Tok.Length = Str.size();
2211 Op->StartLoc = S;
2212 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002213 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002214 }
2215
Bill Wendling2063b842010-11-18 23:43:05 +00002216 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002217 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002218 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002219 Op->StartLoc = S;
2220 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002221 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002222 }
2223
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002224 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2225 unsigned SrcReg,
2226 unsigned ShiftReg,
2227 unsigned ShiftImm,
2228 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002229 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002230 Op->RegShiftedReg.ShiftTy = ShTy;
2231 Op->RegShiftedReg.SrcReg = SrcReg;
2232 Op->RegShiftedReg.ShiftReg = ShiftReg;
2233 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002234 Op->StartLoc = S;
2235 Op->EndLoc = E;
2236 return Op;
2237 }
2238
Owen Andersonb595ed02011-07-21 18:54:16 +00002239 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2240 unsigned SrcReg,
2241 unsigned ShiftImm,
2242 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002243 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002244 Op->RegShiftedImm.ShiftTy = ShTy;
2245 Op->RegShiftedImm.SrcReg = SrcReg;
2246 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002247 Op->StartLoc = S;
2248 Op->EndLoc = E;
2249 return Op;
2250 }
2251
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002252 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002253 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002254 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002255 Op->ShifterImm.isASR = isASR;
2256 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002257 Op->StartLoc = S;
2258 Op->EndLoc = E;
2259 return Op;
2260 }
2261
Jim Grosbach833b9d32011-07-27 20:15:40 +00002262 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002263 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002264 Op->RotImm.Imm = Imm;
2265 Op->StartLoc = S;
2266 Op->EndLoc = E;
2267 return Op;
2268 }
2269
Jim Grosbach864b6092011-07-28 21:34:26 +00002270 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2271 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002272 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002273 Op->Bitfield.LSB = LSB;
2274 Op->Bitfield.Width = Width;
2275 Op->StartLoc = S;
2276 Op->EndLoc = E;
2277 return Op;
2278 }
2279
Bill Wendling2cae3272010-11-09 22:44:22 +00002280 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002281 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002282 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002283 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002284
Jim Grosbach75461af2011-09-13 22:56:44 +00002285 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002286 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002287 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002288 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002289 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002290
2291 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002292 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002293 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002294 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002295 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002296 Op->StartLoc = StartLoc;
2297 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002298 return Op;
2299 }
2300
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002301 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002302 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002303 ARMOperand *Op = new ARMOperand(k_VectorList);
2304 Op->VectorList.RegNum = RegNum;
2305 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002306 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002307 Op->StartLoc = S;
2308 Op->EndLoc = E;
2309 return Op;
2310 }
2311
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002312 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002313 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002314 SMLoc S, SMLoc E) {
2315 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2316 Op->VectorList.RegNum = RegNum;
2317 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002318 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002319 Op->StartLoc = S;
2320 Op->EndLoc = E;
2321 return Op;
2322 }
2323
Jim Grosbach04945c42011-12-02 00:35:16 +00002324 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002325 unsigned Index,
2326 bool isDoubleSpaced,
2327 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002328 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2329 Op->VectorList.RegNum = RegNum;
2330 Op->VectorList.Count = Count;
2331 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002332 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002333 Op->StartLoc = S;
2334 Op->EndLoc = E;
2335 return Op;
2336 }
2337
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002338 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2339 MCContext &Ctx) {
2340 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2341 Op->VectorIndex.Val = Idx;
2342 Op->StartLoc = S;
2343 Op->EndLoc = E;
2344 return Op;
2345 }
2346
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002347 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002348 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002349 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002350 Op->StartLoc = S;
2351 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002352 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002353 }
2354
Jim Grosbachd3595712011-08-03 23:50:40 +00002355 static ARMOperand *CreateMem(unsigned BaseRegNum,
2356 const MCConstantExpr *OffsetImm,
2357 unsigned OffsetRegNum,
2358 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002359 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002360 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002361 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002362 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002363 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002364 Op->Memory.BaseRegNum = BaseRegNum;
2365 Op->Memory.OffsetImm = OffsetImm;
2366 Op->Memory.OffsetRegNum = OffsetRegNum;
2367 Op->Memory.ShiftType = ShiftType;
2368 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002369 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002370 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002371 Op->StartLoc = S;
2372 Op->EndLoc = E;
2373 return Op;
2374 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002375
Jim Grosbachc320c852011-08-05 21:28:30 +00002376 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2377 ARM_AM::ShiftOpc ShiftTy,
2378 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002379 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002380 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002381 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002382 Op->PostIdxReg.isAdd = isAdd;
2383 Op->PostIdxReg.ShiftTy = ShiftTy;
2384 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002385 Op->StartLoc = S;
2386 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002387 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002388 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002389
2390 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002391 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002392 Op->MBOpt.Val = Opt;
2393 Op->StartLoc = S;
2394 Op->EndLoc = S;
2395 return Op;
2396 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002397
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002398 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2399 SMLoc S) {
2400 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2401 Op->ISBOpt.Val = Opt;
2402 Op->StartLoc = S;
2403 Op->EndLoc = S;
2404 return Op;
2405 }
2406
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002407 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002408 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002409 Op->IFlags.Val = IFlags;
2410 Op->StartLoc = S;
2411 Op->EndLoc = S;
2412 return Op;
2413 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002414
2415 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002416 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002417 Op->MMask.Val = MMask;
2418 Op->StartLoc = S;
2419 Op->EndLoc = S;
2420 return Op;
2421 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002422};
2423
2424} // end anonymous namespace.
2425
Jim Grosbach602aa902011-07-13 15:34:57 +00002426void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002427 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002428 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002429 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002430 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002431 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002432 OS << "<ccout " << getReg() << ">";
2433 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002434 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002435 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002436 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2437 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2438 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002439 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2440 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2441 break;
2442 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002443 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002444 OS << "<coprocessor number: " << getCoproc() << ">";
2445 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002447 OS << "<coprocessor register: " << getCoproc() << ">";
2448 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002449 case k_CoprocOption:
2450 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2451 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002452 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002453 OS << "<mask: " << getMSRMask() << ">";
2454 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002455 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002456 getImm()->print(OS);
2457 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002458 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002459 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2460 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002461 case k_InstSyncBarrierOpt:
2462 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002464 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002465 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002466 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002467 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002469 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002470 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2471 << PostIdxReg.RegNum;
2472 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2473 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2474 << PostIdxReg.ShiftImm;
2475 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002476 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002477 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002478 OS << "<ARM_PROC::";
2479 unsigned IFlags = getProcIFlags();
2480 for (int i=2; i >= 0; --i)
2481 if (IFlags & (1 << i))
2482 OS << ARM_PROC::IFlagsToString(1 << i);
2483 OS << ">";
2484 break;
2485 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002486 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002487 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002489 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002490 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2491 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002492 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002493 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002494 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002495 << RegShiftedReg.SrcReg << " "
2496 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2497 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002499 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002500 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002501 << RegShiftedImm.SrcReg << " "
2502 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2503 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002505 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002506 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002508 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002509 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2510 << ", width: " << Bitfield.Width << ">";
2511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002512 case k_RegisterList:
2513 case k_DPRRegisterList:
2514 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002515 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002516
Bill Wendlingbed94652010-11-09 23:28:44 +00002517 const SmallVectorImpl<unsigned> &RegList = getRegList();
2518 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002519 I = RegList.begin(), E = RegList.end(); I != E; ) {
2520 OS << *I;
2521 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002522 }
2523
2524 OS << ">";
2525 break;
2526 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002527 case k_VectorList:
2528 OS << "<vector_list " << VectorList.Count << " * "
2529 << VectorList.RegNum << ">";
2530 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002531 case k_VectorListAllLanes:
2532 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2533 << VectorList.RegNum << ">";
2534 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002535 case k_VectorListIndexed:
2536 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2537 << VectorList.Count << " * " << VectorList.RegNum << ">";
2538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002539 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002540 OS << "'" << getToken() << "'";
2541 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002542 case k_VectorIndex:
2543 OS << "<vectorindex " << getVectorIndex() << ">";
2544 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002545 }
2546}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002547
2548/// @name Auto-generated Match Functions
2549/// {
2550
2551static unsigned MatchRegisterName(StringRef Name);
2552
2553/// }
2554
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002555bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2556 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002557 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002558 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002559 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002560
2561 return (RegNo == (unsigned)-1);
2562}
2563
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002564/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002565/// and if it is a register name the token is eaten and the register number is
2566/// returned. Otherwise return -1.
2567///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002568int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002569 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002570 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002571
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002572 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002573 unsigned RegNum = MatchRegisterName(lowerCase);
2574 if (!RegNum) {
2575 RegNum = StringSwitch<unsigned>(lowerCase)
2576 .Case("r13", ARM::SP)
2577 .Case("r14", ARM::LR)
2578 .Case("r15", ARM::PC)
2579 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002580 // Additional register name aliases for 'gas' compatibility.
2581 .Case("a1", ARM::R0)
2582 .Case("a2", ARM::R1)
2583 .Case("a3", ARM::R2)
2584 .Case("a4", ARM::R3)
2585 .Case("v1", ARM::R4)
2586 .Case("v2", ARM::R5)
2587 .Case("v3", ARM::R6)
2588 .Case("v4", ARM::R7)
2589 .Case("v5", ARM::R8)
2590 .Case("v6", ARM::R9)
2591 .Case("v7", ARM::R10)
2592 .Case("v8", ARM::R11)
2593 .Case("sb", ARM::R9)
2594 .Case("sl", ARM::R10)
2595 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002596 .Default(0);
2597 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002598 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002599 // Check for aliases registered via .req. Canonicalize to lower case.
2600 // That's more consistent since register names are case insensitive, and
2601 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2602 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002603 // If no match, return failure.
2604 if (Entry == RegisterReqs.end())
2605 return -1;
2606 Parser.Lex(); // Eat identifier token.
2607 return Entry->getValue();
2608 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002609
Chris Lattner44e5981c2010-10-30 04:09:10 +00002610 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002611
Chris Lattner44e5981c2010-10-30 04:09:10 +00002612 return RegNum;
2613}
Jim Grosbach99710a82010-11-01 16:44:21 +00002614
Jim Grosbachbb24c592011-07-13 18:49:30 +00002615// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2616// If a recoverable error occurs, return 1. If an irrecoverable error
2617// occurs, return -1. An irrecoverable error is one where tokens have been
2618// consumed in the process of trying to parse the shifter (i.e., when it is
2619// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002620int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002621 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2622 SMLoc S = Parser.getTok().getLoc();
2623 const AsmToken &Tok = Parser.getTok();
2624 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2625
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002626 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002627 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002628 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002629 .Case("lsl", ARM_AM::lsl)
2630 .Case("lsr", ARM_AM::lsr)
2631 .Case("asr", ARM_AM::asr)
2632 .Case("ror", ARM_AM::ror)
2633 .Case("rrx", ARM_AM::rrx)
2634 .Default(ARM_AM::no_shift);
2635
2636 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002637 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002638
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002639 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002640
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002641 // The source register for the shift has already been added to the
2642 // operand list, so we need to pop it off and combine it into the shifted
2643 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002644 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002645 if (!PrevOp->isReg())
2646 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2647 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002648
2649 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002650 int64_t Imm = 0;
2651 int ShiftReg = 0;
2652 if (ShiftTy == ARM_AM::rrx) {
2653 // RRX Doesn't have an explicit shift amount. The encoder expects
2654 // the shift register to be the same as the source register. Seems odd,
2655 // but OK.
2656 ShiftReg = SrcReg;
2657 } else {
2658 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002659 if (Parser.getTok().is(AsmToken::Hash) ||
2660 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002661 Parser.Lex(); // Eat hash.
2662 SMLoc ImmLoc = Parser.getTok().getLoc();
2663 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002664 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002665 Error(ImmLoc, "invalid immediate shift value");
2666 return -1;
2667 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002668 // The expression must be evaluatable as an immediate.
2669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002670 if (!CE) {
2671 Error(ImmLoc, "invalid immediate shift value");
2672 return -1;
2673 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002674 // Range check the immediate.
2675 // lsl, ror: 0 <= imm <= 31
2676 // lsr, asr: 0 <= imm <= 32
2677 Imm = CE->getValue();
2678 if (Imm < 0 ||
2679 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2680 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002681 Error(ImmLoc, "immediate shift value out of range");
2682 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002683 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002684 // shift by zero is a nop. Always send it through as lsl.
2685 // ('as' compatibility)
2686 if (Imm == 0)
2687 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002688 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002689 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002690 EndLoc = Parser.getTok().getEndLoc();
2691 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002692 if (ShiftReg == -1) {
2693 Error (L, "expected immediate or register in shift operand");
2694 return -1;
2695 }
2696 } else {
2697 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002698 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002699 return -1;
2700 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002701 }
2702
Owen Andersonb595ed02011-07-21 18:54:16 +00002703 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2704 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002705 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002706 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002707 else
2708 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002709 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002710
Jim Grosbachbb24c592011-07-13 18:49:30 +00002711 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002712}
2713
2714
Bill Wendling2063b842010-11-18 23:43:05 +00002715/// Try to parse a register name. The token must be an Identifier when called.
2716/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2717/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002718///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002719/// TODO this is likely to change to allow different register types and or to
2720/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002721bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002722tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002723 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002724 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002725 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002726 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002727
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002728 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2729 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002730
Chris Lattner44e5981c2010-10-30 04:09:10 +00002731 const AsmToken &ExclaimTok = Parser.getTok();
2732 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002733 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2734 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002735 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002736 return false;
2737 }
2738
2739 // Also check for an index operand. This is only legal for vector registers,
2740 // but that'll get caught OK in operand matching, so we don't need to
2741 // explicitly filter everything else out here.
2742 if (Parser.getTok().is(AsmToken::LBrac)) {
2743 SMLoc SIdx = Parser.getTok().getLoc();
2744 Parser.Lex(); // Eat left bracket token.
2745
2746 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002747 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002748 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002749 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002750 if (!MCE)
2751 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002752
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002753 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002754 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002755
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002756 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002757 Parser.Lex(); // Eat right bracket token.
2758
2759 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2760 SIdx, E,
2761 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002762 }
2763
Bill Wendling2063b842010-11-18 23:43:05 +00002764 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002765}
2766
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002767/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2768/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2769/// "c5", ...
2770static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002771 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2772 // but efficient.
2773 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002774 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002775 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002776 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002777 return -1;
2778 switch (Name[1]) {
2779 default: return -1;
2780 case '0': return 0;
2781 case '1': return 1;
2782 case '2': return 2;
2783 case '3': return 3;
2784 case '4': return 4;
2785 case '5': return 5;
2786 case '6': return 6;
2787 case '7': return 7;
2788 case '8': return 8;
2789 case '9': return 9;
2790 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002791 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002792 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002793 return -1;
2794 switch (Name[2]) {
2795 default: return -1;
2796 case '0': return 10;
2797 case '1': return 11;
2798 case '2': return 12;
2799 case '3': return 13;
2800 case '4': return 14;
2801 case '5': return 15;
2802 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002803 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002804}
2805
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002806/// parseITCondCode - Try to parse a condition code for an IT instruction.
2807ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2808parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2809 SMLoc S = Parser.getTok().getLoc();
2810 const AsmToken &Tok = Parser.getTok();
2811 if (!Tok.is(AsmToken::Identifier))
2812 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002813 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002814 .Case("eq", ARMCC::EQ)
2815 .Case("ne", ARMCC::NE)
2816 .Case("hs", ARMCC::HS)
2817 .Case("cs", ARMCC::HS)
2818 .Case("lo", ARMCC::LO)
2819 .Case("cc", ARMCC::LO)
2820 .Case("mi", ARMCC::MI)
2821 .Case("pl", ARMCC::PL)
2822 .Case("vs", ARMCC::VS)
2823 .Case("vc", ARMCC::VC)
2824 .Case("hi", ARMCC::HI)
2825 .Case("ls", ARMCC::LS)
2826 .Case("ge", ARMCC::GE)
2827 .Case("lt", ARMCC::LT)
2828 .Case("gt", ARMCC::GT)
2829 .Case("le", ARMCC::LE)
2830 .Case("al", ARMCC::AL)
2831 .Default(~0U);
2832 if (CC == ~0U)
2833 return MatchOperand_NoMatch;
2834 Parser.Lex(); // Eat the token.
2835
2836 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2837
2838 return MatchOperand_Success;
2839}
2840
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002841/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002842/// token must be an Identifier when called, and if it is a coprocessor
2843/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002844ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002845parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002846 SMLoc S = Parser.getTok().getLoc();
2847 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002848 if (Tok.isNot(AsmToken::Identifier))
2849 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002850
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002851 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002852 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002853 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002854
2855 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002856 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002857 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002858}
2859
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002860/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002861/// token must be an Identifier when called, and if it is a coprocessor
2862/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002863ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002864parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002865 SMLoc S = Parser.getTok().getLoc();
2866 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002867 if (Tok.isNot(AsmToken::Identifier))
2868 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002869
2870 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2871 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002872 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002873
2874 Parser.Lex(); // Eat identifier token.
2875 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002876 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002877}
2878
Jim Grosbach48399582011-10-12 17:34:41 +00002879/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2880/// coproc_option : '{' imm0_255 '}'
2881ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2882parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2883 SMLoc S = Parser.getTok().getLoc();
2884
2885 // If this isn't a '{', this isn't a coprocessor immediate operand.
2886 if (Parser.getTok().isNot(AsmToken::LCurly))
2887 return MatchOperand_NoMatch;
2888 Parser.Lex(); // Eat the '{'
2889
2890 const MCExpr *Expr;
2891 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002892 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002893 Error(Loc, "illegal expression");
2894 return MatchOperand_ParseFail;
2895 }
2896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2897 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2898 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2899 return MatchOperand_ParseFail;
2900 }
2901 int Val = CE->getValue();
2902
2903 // Check for and consume the closing '}'
2904 if (Parser.getTok().isNot(AsmToken::RCurly))
2905 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002906 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002907 Parser.Lex(); // Eat the '}'
2908
2909 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2910 return MatchOperand_Success;
2911}
2912
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002913// For register list parsing, we need to map from raw GPR register numbering
2914// to the enumeration values. The enumeration values aren't sorted by
2915// register number due to our using "sp", "lr" and "pc" as canonical names.
2916static unsigned getNextRegister(unsigned Reg) {
2917 // If this is a GPR, we need to do it manually, otherwise we can rely
2918 // on the sort ordering of the enumeration since the other reg-classes
2919 // are sane.
2920 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2921 return Reg + 1;
2922 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002923 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002924 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2925 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2926 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2927 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2928 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2929 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2930 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2931 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2932 }
2933}
2934
Jim Grosbach85a23432011-11-11 21:27:40 +00002935// Return the low-subreg of a given Q register.
2936static unsigned getDRegFromQReg(unsigned QReg) {
2937 switch (QReg) {
2938 default: llvm_unreachable("expected a Q register!");
2939 case ARM::Q0: return ARM::D0;
2940 case ARM::Q1: return ARM::D2;
2941 case ARM::Q2: return ARM::D4;
2942 case ARM::Q3: return ARM::D6;
2943 case ARM::Q4: return ARM::D8;
2944 case ARM::Q5: return ARM::D10;
2945 case ARM::Q6: return ARM::D12;
2946 case ARM::Q7: return ARM::D14;
2947 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002948 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002949 case ARM::Q10: return ARM::D20;
2950 case ARM::Q11: return ARM::D22;
2951 case ARM::Q12: return ARM::D24;
2952 case ARM::Q13: return ARM::D26;
2953 case ARM::Q14: return ARM::D28;
2954 case ARM::Q15: return ARM::D30;
2955 }
2956}
2957
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002958/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002959bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002960parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002961 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002962 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002963 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002964 Parser.Lex(); // Eat '{' token.
2965 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002966
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002967 // Check the first register in the list to see what register class
2968 // this is a list of.
2969 int Reg = tryParseRegister();
2970 if (Reg == -1)
2971 return Error(RegLoc, "register expected");
2972
Jim Grosbach85a23432011-11-11 21:27:40 +00002973 // The reglist instructions have at most 16 registers, so reserve
2974 // space for that many.
2975 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2976
2977 // Allow Q regs and just interpret them as the two D sub-registers.
2978 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2979 Reg = getDRegFromQReg(Reg);
2980 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2981 ++Reg;
2982 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002983 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002984 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2985 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2986 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2987 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2988 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2989 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2990 else
2991 return Error(RegLoc, "invalid register in register list");
2992
Jim Grosbach85a23432011-11-11 21:27:40 +00002993 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002994 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002995
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002996 // This starts immediately after the first register token in the list,
2997 // so we can see either a comma or a minus (range separator) as a legal
2998 // next token.
2999 while (Parser.getTok().is(AsmToken::Comma) ||
3000 Parser.getTok().is(AsmToken::Minus)) {
3001 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003002 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003003 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003004 int EndReg = tryParseRegister();
3005 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003006 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003007 // Allow Q regs and just interpret them as the two D sub-registers.
3008 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3009 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003010 // If the register is the same as the start reg, there's nothing
3011 // more to do.
3012 if (Reg == EndReg)
3013 continue;
3014 // The register must be in the same register class as the first.
3015 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003016 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003017 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003018 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003019 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003020
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003021 // Add all the registers in the range to the register list.
3022 while (Reg != EndReg) {
3023 Reg = getNextRegister(Reg);
3024 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
3025 }
3026 continue;
3027 }
3028 Parser.Lex(); // Eat the comma.
3029 RegLoc = Parser.getTok().getLoc();
3030 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003031 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003032 Reg = tryParseRegister();
3033 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003034 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003035 // Allow Q regs and just interpret them as the two D sub-registers.
3036 bool isQReg = false;
3037 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3038 Reg = getDRegFromQReg(Reg);
3039 isQReg = true;
3040 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003041 // The register must be in the same register class as the first.
3042 if (!RC->contains(Reg))
3043 return Error(RegLoc, "invalid register in register list");
3044 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003045 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003046 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3047 Warning(RegLoc, "register list not in ascending order");
3048 else
3049 return Error(RegLoc, "register list not in ascending order");
3050 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003051 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003052 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3053 ") in register list");
3054 continue;
3055 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003056 // VFP register lists must also be contiguous.
3057 // It's OK to use the enumeration values directly here rather, as the
3058 // VFP register classes have the enum sorted properly.
3059 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3060 Reg != OldReg + 1)
3061 return Error(RegLoc, "non-contiguous register range");
3062 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00003063 if (isQReg)
3064 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00003065 }
3066
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003067 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003068 return Error(Parser.getTok().getLoc(), "'}' expected");
3069 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003070 Parser.Lex(); // Eat '}' token.
3071
Jim Grosbach18bf3632011-12-13 21:48:29 +00003072 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003073 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003074
3075 // The ARM system instruction variants for LDM/STM have a '^' token here.
3076 if (Parser.getTok().is(AsmToken::Caret)) {
3077 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3078 Parser.Lex(); // Eat '^' token.
3079 }
3080
Bill Wendling2063b842010-11-18 23:43:05 +00003081 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003082}
3083
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003084// Helper function to parse the lane index for vector lists.
3085ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003086parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003087 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003088 if (Parser.getTok().is(AsmToken::LBrac)) {
3089 Parser.Lex(); // Eat the '['.
3090 if (Parser.getTok().is(AsmToken::RBrac)) {
3091 // "Dn[]" is the 'all lanes' syntax.
3092 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003093 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003094 Parser.Lex(); // Eat the ']'.
3095 return MatchOperand_Success;
3096 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003097
3098 // There's an optional '#' token here. Normally there wouldn't be, but
3099 // inline assemble puts one in, and it's friendly to accept that.
3100 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003101 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003102
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003103 const MCExpr *LaneIndex;
3104 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003105 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003106 Error(Loc, "illegal expression");
3107 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003108 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003109 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3110 if (!CE) {
3111 Error(Loc, "lane index must be empty or an integer");
3112 return MatchOperand_ParseFail;
3113 }
3114 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3115 Error(Parser.getTok().getLoc(), "']' expected");
3116 return MatchOperand_ParseFail;
3117 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003118 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003119 Parser.Lex(); // Eat the ']'.
3120 int64_t Val = CE->getValue();
3121
3122 // FIXME: Make this range check context sensitive for .8, .16, .32.
3123 if (Val < 0 || Val > 7) {
3124 Error(Parser.getTok().getLoc(), "lane index out of range");
3125 return MatchOperand_ParseFail;
3126 }
3127 Index = Val;
3128 LaneKind = IndexedLane;
3129 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003130 }
3131 LaneKind = NoLanes;
3132 return MatchOperand_Success;
3133}
3134
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003135// parse a vector register list
3136ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3137parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003138 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003139 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003140 SMLoc S = Parser.getTok().getLoc();
3141 // As an extension (to match gas), support a plain D register or Q register
3142 // (without encosing curly braces) as a single or double entry list,
3143 // respectively.
3144 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003145 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003146 int Reg = tryParseRegister();
3147 if (Reg == -1)
3148 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003149 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003150 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003151 if (Res != MatchOperand_Success)
3152 return Res;
3153 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003154 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003155 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156 break;
3157 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003158 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3159 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003160 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003161 case IndexedLane:
3162 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003163 LaneIndex,
3164 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003165 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003166 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003167 return MatchOperand_Success;
3168 }
3169 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3170 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003171 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003172 if (Res != MatchOperand_Success)
3173 return Res;
3174 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003175 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003176 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003177 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003178 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003179 break;
3180 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003181 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3182 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003183 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3184 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003185 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003186 case IndexedLane:
3187 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003188 LaneIndex,
3189 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003190 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003191 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003192 return MatchOperand_Success;
3193 }
3194 Error(S, "vector register expected");
3195 return MatchOperand_ParseFail;
3196 }
3197
3198 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003199 return MatchOperand_NoMatch;
3200
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003201 Parser.Lex(); // Eat '{' token.
3202 SMLoc RegLoc = Parser.getTok().getLoc();
3203
3204 int Reg = tryParseRegister();
3205 if (Reg == -1) {
3206 Error(RegLoc, "register expected");
3207 return MatchOperand_ParseFail;
3208 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003209 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003210 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003211 unsigned FirstReg = Reg;
3212 // The list is of D registers, but we also allow Q regs and just interpret
3213 // them as the two D sub-registers.
3214 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3215 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003216 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3217 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003218 ++Reg;
3219 ++Count;
3220 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003221
3222 SMLoc E;
3223 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003224 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003225
Jim Grosbache891fe82011-11-15 23:19:15 +00003226 while (Parser.getTok().is(AsmToken::Comma) ||
3227 Parser.getTok().is(AsmToken::Minus)) {
3228 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003229 if (!Spacing)
3230 Spacing = 1; // Register range implies a single spaced list.
3231 else if (Spacing == 2) {
3232 Error(Parser.getTok().getLoc(),
3233 "sequential registers in double spaced list");
3234 return MatchOperand_ParseFail;
3235 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003236 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003237 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003238 int EndReg = tryParseRegister();
3239 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003240 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003241 return MatchOperand_ParseFail;
3242 }
3243 // Allow Q regs and just interpret them as the two D sub-registers.
3244 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3245 EndReg = getDRegFromQReg(EndReg) + 1;
3246 // If the register is the same as the start reg, there's nothing
3247 // more to do.
3248 if (Reg == EndReg)
3249 continue;
3250 // The register must be in the same register class as the first.
3251 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003252 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003253 return MatchOperand_ParseFail;
3254 }
3255 // Ranges must go from low to high.
3256 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003257 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003258 return MatchOperand_ParseFail;
3259 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003260 // Parse the lane specifier if present.
3261 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003262 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003263 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3264 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003265 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003266 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003267 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003268 return MatchOperand_ParseFail;
3269 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003270
3271 // Add all the registers in the range to the register list.
3272 Count += EndReg - Reg;
3273 Reg = EndReg;
3274 continue;
3275 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003276 Parser.Lex(); // Eat the comma.
3277 RegLoc = Parser.getTok().getLoc();
3278 int OldReg = Reg;
3279 Reg = tryParseRegister();
3280 if (Reg == -1) {
3281 Error(RegLoc, "register expected");
3282 return MatchOperand_ParseFail;
3283 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003284 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003285 // It's OK to use the enumeration values directly here rather, as the
3286 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003287 //
3288 // The list is of D registers, but we also allow Q regs and just interpret
3289 // them as the two D sub-registers.
3290 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003291 if (!Spacing)
3292 Spacing = 1; // Register range implies a single spaced list.
3293 else if (Spacing == 2) {
3294 Error(RegLoc,
3295 "invalid register in double-spaced list (must be 'D' register')");
3296 return MatchOperand_ParseFail;
3297 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003298 Reg = getDRegFromQReg(Reg);
3299 if (Reg != OldReg + 1) {
3300 Error(RegLoc, "non-contiguous register range");
3301 return MatchOperand_ParseFail;
3302 }
3303 ++Reg;
3304 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003305 // Parse the lane specifier if present.
3306 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003307 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003308 SMLoc LaneLoc = Parser.getTok().getLoc();
3309 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3310 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003311 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003312 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003313 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003314 return MatchOperand_ParseFail;
3315 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003316 continue;
3317 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003318 // Normal D register.
3319 // Figure out the register spacing (single or double) of the list if
3320 // we don't know it already.
3321 if (!Spacing)
3322 Spacing = 1 + (Reg == OldReg + 2);
3323
3324 // Just check that it's contiguous and keep going.
3325 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003326 Error(RegLoc, "non-contiguous register range");
3327 return MatchOperand_ParseFail;
3328 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003329 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003330 // Parse the lane specifier if present.
3331 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003332 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003333 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003334 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003335 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003336 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003337 Error(EndLoc, "mismatched lane index in register list");
3338 return MatchOperand_ParseFail;
3339 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003340 }
3341
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003342 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003343 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003344 return MatchOperand_ParseFail;
3345 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003346 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003347 Parser.Lex(); // Eat '}' token.
3348
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003349 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003350 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003351 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003352 // composite register classes.
3353 if (Count == 2) {
3354 const MCRegisterClass *RC = (Spacing == 1) ?
3355 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3356 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3357 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3358 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003359
Jim Grosbach2f50e922011-12-15 21:44:33 +00003360 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3361 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003362 break;
3363 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003364 // Two-register operands have been converted to the
3365 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003366 if (Count == 2) {
3367 const MCRegisterClass *RC = (Spacing == 1) ?
3368 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3369 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003370 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3371 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003372 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003373 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003374 S, E));
3375 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003376 case IndexedLane:
3377 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003378 LaneIndex,
3379 (Spacing == 2),
3380 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003381 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003382 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003383 return MatchOperand_Success;
3384}
3385
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003386/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003387ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003388parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003389 SMLoc S = Parser.getTok().getLoc();
3390 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003391 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003392
Jiangning Liu288e1af2012-08-02 08:21:27 +00003393 if (Tok.is(AsmToken::Identifier)) {
3394 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003395
Jiangning Liu288e1af2012-08-02 08:21:27 +00003396 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3397 .Case("sy", ARM_MB::SY)
3398 .Case("st", ARM_MB::ST)
3399 .Case("sh", ARM_MB::ISH)
3400 .Case("ish", ARM_MB::ISH)
3401 .Case("shst", ARM_MB::ISHST)
3402 .Case("ishst", ARM_MB::ISHST)
3403 .Case("nsh", ARM_MB::NSH)
3404 .Case("un", ARM_MB::NSH)
3405 .Case("nshst", ARM_MB::NSHST)
3406 .Case("unst", ARM_MB::NSHST)
3407 .Case("osh", ARM_MB::OSH)
3408 .Case("oshst", ARM_MB::OSHST)
3409 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003410
Jiangning Liu288e1af2012-08-02 08:21:27 +00003411 if (Opt == ~0U)
3412 return MatchOperand_NoMatch;
3413
3414 Parser.Lex(); // Eat identifier token.
3415 } else if (Tok.is(AsmToken::Hash) ||
3416 Tok.is(AsmToken::Dollar) ||
3417 Tok.is(AsmToken::Integer)) {
3418 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003419 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003420 SMLoc Loc = Parser.getTok().getLoc();
3421
3422 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003423 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003424 Error(Loc, "illegal expression");
3425 return MatchOperand_ParseFail;
3426 }
3427
3428 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3429 if (!CE) {
3430 Error(Loc, "constant expression expected");
3431 return MatchOperand_ParseFail;
3432 }
3433
3434 int Val = CE->getValue();
3435 if (Val & ~0xf) {
3436 Error(Loc, "immediate value out of range");
3437 return MatchOperand_ParseFail;
3438 }
3439
3440 Opt = ARM_MB::RESERVED_0 + Val;
3441 } else
3442 return MatchOperand_ParseFail;
3443
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003444 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003445 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003446}
3447
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003448/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3449ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3450parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3451 SMLoc S = Parser.getTok().getLoc();
3452 const AsmToken &Tok = Parser.getTok();
3453 unsigned Opt;
3454
3455 if (Tok.is(AsmToken::Identifier)) {
3456 StringRef OptStr = Tok.getString();
3457
3458 if (OptStr.lower() == "sy")
3459 Opt = ARM_ISB::SY;
3460 else
3461 return MatchOperand_NoMatch;
3462
3463 Parser.Lex(); // Eat identifier token.
3464 } else if (Tok.is(AsmToken::Hash) ||
3465 Tok.is(AsmToken::Dollar) ||
3466 Tok.is(AsmToken::Integer)) {
3467 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003468 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003469 SMLoc Loc = Parser.getTok().getLoc();
3470
3471 const MCExpr *ISBarrierID;
3472 if (getParser().parseExpression(ISBarrierID)) {
3473 Error(Loc, "illegal expression");
3474 return MatchOperand_ParseFail;
3475 }
3476
3477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3478 if (!CE) {
3479 Error(Loc, "constant expression expected");
3480 return MatchOperand_ParseFail;
3481 }
3482
3483 int Val = CE->getValue();
3484 if (Val & ~0xf) {
3485 Error(Loc, "immediate value out of range");
3486 return MatchOperand_ParseFail;
3487 }
3488
3489 Opt = ARM_ISB::RESERVED_0 + Val;
3490 } else
3491 return MatchOperand_ParseFail;
3492
3493 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3494 (ARM_ISB::InstSyncBOpt)Opt, S));
3495 return MatchOperand_Success;
3496}
3497
3498
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003499/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003500ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003501parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003502 SMLoc S = Parser.getTok().getLoc();
3503 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003504 if (!Tok.is(AsmToken::Identifier))
3505 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003506 StringRef IFlagsStr = Tok.getString();
3507
Owen Anderson10c5b122011-10-05 17:16:40 +00003508 // An iflags string of "none" is interpreted to mean that none of the AIF
3509 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003510 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003511 if (IFlagsStr != "none") {
3512 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3513 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3514 .Case("a", ARM_PROC::A)
3515 .Case("i", ARM_PROC::I)
3516 .Case("f", ARM_PROC::F)
3517 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003518
Owen Anderson10c5b122011-10-05 17:16:40 +00003519 // If some specific iflag is already set, it means that some letter is
3520 // present more than once, this is not acceptable.
3521 if (Flag == ~0U || (IFlags & Flag))
3522 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003523
Owen Anderson10c5b122011-10-05 17:16:40 +00003524 IFlags |= Flag;
3525 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003526 }
3527
3528 Parser.Lex(); // Eat identifier token.
3529 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3530 return MatchOperand_Success;
3531}
3532
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003533/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003534ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003535parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003536 SMLoc S = Parser.getTok().getLoc();
3537 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003538 if (!Tok.is(AsmToken::Identifier))
3539 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003540 StringRef Mask = Tok.getString();
3541
James Molloy21efa7d2011-09-28 14:21:38 +00003542 if (isMClass()) {
3543 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003544 std::string Name = Mask.lower();
3545 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003546 // Note: in the documentation:
3547 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3548 // for MSR APSR_nzcvq.
3549 // but we do make it an alias here. This is so to get the "mask encoding"
3550 // bits correct on MSR APSR writes.
3551 //
3552 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3553 // should really only be allowed when writing a special register. Note
3554 // they get dropped in the MRS instruction reading a special register as
3555 // the SYSm field is only 8 bits.
3556 //
3557 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3558 // includes the DSP extension but that is not checked.
3559 .Case("apsr", 0x800)
3560 .Case("apsr_nzcvq", 0x800)
3561 .Case("apsr_g", 0x400)
3562 .Case("apsr_nzcvqg", 0xc00)
3563 .Case("iapsr", 0x801)
3564 .Case("iapsr_nzcvq", 0x801)
3565 .Case("iapsr_g", 0x401)
3566 .Case("iapsr_nzcvqg", 0xc01)
3567 .Case("eapsr", 0x802)
3568 .Case("eapsr_nzcvq", 0x802)
3569 .Case("eapsr_g", 0x402)
3570 .Case("eapsr_nzcvqg", 0xc02)
3571 .Case("xpsr", 0x803)
3572 .Case("xpsr_nzcvq", 0x803)
3573 .Case("xpsr_g", 0x403)
3574 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003575 .Case("ipsr", 0x805)
3576 .Case("epsr", 0x806)
3577 .Case("iepsr", 0x807)
3578 .Case("msp", 0x808)
3579 .Case("psp", 0x809)
3580 .Case("primask", 0x810)
3581 .Case("basepri", 0x811)
3582 .Case("basepri_max", 0x812)
3583 .Case("faultmask", 0x813)
3584 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003585 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003586
James Molloy21efa7d2011-09-28 14:21:38 +00003587 if (FlagsVal == ~0U)
3588 return MatchOperand_NoMatch;
3589
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003590 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003591 // basepri, basepri_max and faultmask only valid for V7m.
3592 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003593
James Molloy21efa7d2011-09-28 14:21:38 +00003594 Parser.Lex(); // Eat identifier token.
3595 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3596 return MatchOperand_Success;
3597 }
3598
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003599 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3600 size_t Start = 0, Next = Mask.find('_');
3601 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003602 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003603 if (Next != StringRef::npos)
3604 Flags = Mask.slice(Next+1, Mask.size());
3605
3606 // FlagsVal contains the complete mask:
3607 // 3-0: Mask
3608 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3609 unsigned FlagsVal = 0;
3610
3611 if (SpecReg == "apsr") {
3612 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003613 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003614 .Case("g", 0x4) // same as CPSR_s
3615 .Case("nzcvqg", 0xc) // same as CPSR_fs
3616 .Default(~0U);
3617
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003618 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003619 if (!Flags.empty())
3620 return MatchOperand_NoMatch;
3621 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003622 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003623 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003624 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003625 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3626 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003627 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003628 for (int i = 0, e = Flags.size(); i != e; ++i) {
3629 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3630 .Case("c", 1)
3631 .Case("x", 2)
3632 .Case("s", 4)
3633 .Case("f", 8)
3634 .Default(~0U);
3635
3636 // If some specific flag is already set, it means that some letter is
3637 // present more than once, this is not acceptable.
3638 if (FlagsVal == ~0U || (FlagsVal & Flag))
3639 return MatchOperand_NoMatch;
3640 FlagsVal |= Flag;
3641 }
3642 } else // No match for special register.
3643 return MatchOperand_NoMatch;
3644
Owen Anderson03a173e2011-10-21 18:43:28 +00003645 // Special register without flags is NOT equivalent to "fc" flags.
3646 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3647 // two lines would enable gas compatibility at the expense of breaking
3648 // round-tripping.
3649 //
3650 // if (!FlagsVal)
3651 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003652
3653 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3654 if (SpecReg == "spsr")
3655 FlagsVal |= 16;
3656
3657 Parser.Lex(); // Eat identifier token.
3658 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3659 return MatchOperand_Success;
3660}
3661
Jim Grosbach27c1e252011-07-21 17:23:04 +00003662ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3663parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3664 int Low, int High) {
3665 const AsmToken &Tok = Parser.getTok();
3666 if (Tok.isNot(AsmToken::Identifier)) {
3667 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3668 return MatchOperand_ParseFail;
3669 }
3670 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003671 std::string LowerOp = Op.lower();
3672 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003673 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3674 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3675 return MatchOperand_ParseFail;
3676 }
3677 Parser.Lex(); // Eat shift type token.
3678
3679 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003680 if (Parser.getTok().isNot(AsmToken::Hash) &&
3681 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003682 Error(Parser.getTok().getLoc(), "'#' expected");
3683 return MatchOperand_ParseFail;
3684 }
3685 Parser.Lex(); // Eat hash token.
3686
3687 const MCExpr *ShiftAmount;
3688 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003689 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003690 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003691 Error(Loc, "illegal expression");
3692 return MatchOperand_ParseFail;
3693 }
3694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3695 if (!CE) {
3696 Error(Loc, "constant expression expected");
3697 return MatchOperand_ParseFail;
3698 }
3699 int Val = CE->getValue();
3700 if (Val < Low || Val > High) {
3701 Error(Loc, "immediate value out of range");
3702 return MatchOperand_ParseFail;
3703 }
3704
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003705 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003706
3707 return MatchOperand_Success;
3708}
3709
Jim Grosbach0a547702011-07-22 17:44:50 +00003710ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3711parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3712 const AsmToken &Tok = Parser.getTok();
3713 SMLoc S = Tok.getLoc();
3714 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003715 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003716 return MatchOperand_ParseFail;
3717 }
Tim Northover4d141442013-05-31 15:58:45 +00003718 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003719 .Case("be", 1)
3720 .Case("le", 0)
3721 .Default(-1);
3722 Parser.Lex(); // Eat the token.
3723
3724 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003725 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003726 return MatchOperand_ParseFail;
3727 }
3728 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3729 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003730 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003731 return MatchOperand_Success;
3732}
3733
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003734/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3735/// instructions. Legal values are:
3736/// lsl #n 'n' in [0,31]
3737/// asr #n 'n' in [1,32]
3738/// n == 32 encoded as n == 0.
3739ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3740parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3741 const AsmToken &Tok = Parser.getTok();
3742 SMLoc S = Tok.getLoc();
3743 if (Tok.isNot(AsmToken::Identifier)) {
3744 Error(S, "shift operator 'asr' or 'lsl' expected");
3745 return MatchOperand_ParseFail;
3746 }
3747 StringRef ShiftName = Tok.getString();
3748 bool isASR;
3749 if (ShiftName == "lsl" || ShiftName == "LSL")
3750 isASR = false;
3751 else if (ShiftName == "asr" || ShiftName == "ASR")
3752 isASR = true;
3753 else {
3754 Error(S, "shift operator 'asr' or 'lsl' expected");
3755 return MatchOperand_ParseFail;
3756 }
3757 Parser.Lex(); // Eat the operator.
3758
3759 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003760 if (Parser.getTok().isNot(AsmToken::Hash) &&
3761 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003762 Error(Parser.getTok().getLoc(), "'#' expected");
3763 return MatchOperand_ParseFail;
3764 }
3765 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003766 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003767
3768 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003769 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003770 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003771 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003772 return MatchOperand_ParseFail;
3773 }
3774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3775 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003776 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003777 return MatchOperand_ParseFail;
3778 }
3779
3780 int64_t Val = CE->getValue();
3781 if (isASR) {
3782 // Shift amount must be in [1,32]
3783 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003784 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003785 return MatchOperand_ParseFail;
3786 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003787 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3788 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003789 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003790 return MatchOperand_ParseFail;
3791 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003792 if (Val == 32) Val = 0;
3793 } else {
3794 // Shift amount must be in [1,32]
3795 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003796 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003797 return MatchOperand_ParseFail;
3798 }
3799 }
3800
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003801 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003802
3803 return MatchOperand_Success;
3804}
3805
Jim Grosbach833b9d32011-07-27 20:15:40 +00003806/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3807/// of instructions. Legal values are:
3808/// ror #n 'n' in {0, 8, 16, 24}
3809ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3810parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3811 const AsmToken &Tok = Parser.getTok();
3812 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003813 if (Tok.isNot(AsmToken::Identifier))
3814 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003815 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003816 if (ShiftName != "ror" && ShiftName != "ROR")
3817 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003818 Parser.Lex(); // Eat the operator.
3819
3820 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003821 if (Parser.getTok().isNot(AsmToken::Hash) &&
3822 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003823 Error(Parser.getTok().getLoc(), "'#' expected");
3824 return MatchOperand_ParseFail;
3825 }
3826 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003827 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003828
3829 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003830 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003831 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003832 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003833 return MatchOperand_ParseFail;
3834 }
3835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3836 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003837 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003838 return MatchOperand_ParseFail;
3839 }
3840
3841 int64_t Val = CE->getValue();
3842 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3843 // normally, zero is represented in asm by omitting the rotate operand
3844 // entirely.
3845 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003846 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003847 return MatchOperand_ParseFail;
3848 }
3849
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003850 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003851
3852 return MatchOperand_Success;
3853}
3854
Jim Grosbach864b6092011-07-28 21:34:26 +00003855ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3856parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3857 SMLoc S = Parser.getTok().getLoc();
3858 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003859 if (Parser.getTok().isNot(AsmToken::Hash) &&
3860 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003861 Error(Parser.getTok().getLoc(), "'#' expected");
3862 return MatchOperand_ParseFail;
3863 }
3864 Parser.Lex(); // Eat hash token.
3865
3866 const MCExpr *LSBExpr;
3867 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003868 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003869 Error(E, "malformed immediate expression");
3870 return MatchOperand_ParseFail;
3871 }
3872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3873 if (!CE) {
3874 Error(E, "'lsb' operand must be an immediate");
3875 return MatchOperand_ParseFail;
3876 }
3877
3878 int64_t LSB = CE->getValue();
3879 // The LSB must be in the range [0,31]
3880 if (LSB < 0 || LSB > 31) {
3881 Error(E, "'lsb' operand must be in the range [0,31]");
3882 return MatchOperand_ParseFail;
3883 }
3884 E = Parser.getTok().getLoc();
3885
3886 // Expect another immediate operand.
3887 if (Parser.getTok().isNot(AsmToken::Comma)) {
3888 Error(Parser.getTok().getLoc(), "too few operands");
3889 return MatchOperand_ParseFail;
3890 }
3891 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003892 if (Parser.getTok().isNot(AsmToken::Hash) &&
3893 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003894 Error(Parser.getTok().getLoc(), "'#' expected");
3895 return MatchOperand_ParseFail;
3896 }
3897 Parser.Lex(); // Eat hash token.
3898
3899 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003900 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003901 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003902 Error(E, "malformed immediate expression");
3903 return MatchOperand_ParseFail;
3904 }
3905 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3906 if (!CE) {
3907 Error(E, "'width' operand must be an immediate");
3908 return MatchOperand_ParseFail;
3909 }
3910
3911 int64_t Width = CE->getValue();
3912 // The LSB must be in the range [1,32-lsb]
3913 if (Width < 1 || Width > 32 - LSB) {
3914 Error(E, "'width' operand must be in the range [1,32-lsb]");
3915 return MatchOperand_ParseFail;
3916 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003917
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003918 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003919
3920 return MatchOperand_Success;
3921}
3922
Jim Grosbachd3595712011-08-03 23:50:40 +00003923ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3924parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3925 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003926 // postidx_reg := '+' register {, shift}
3927 // | '-' register {, shift}
3928 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003929
3930 // This method must return MatchOperand_NoMatch without consuming any tokens
3931 // in the case where there is no match, as other alternatives take other
3932 // parse methods.
3933 AsmToken Tok = Parser.getTok();
3934 SMLoc S = Tok.getLoc();
3935 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003936 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003937 if (Tok.is(AsmToken::Plus)) {
3938 Parser.Lex(); // Eat the '+' token.
3939 haveEaten = true;
3940 } else if (Tok.is(AsmToken::Minus)) {
3941 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003942 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003943 haveEaten = true;
3944 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003945
3946 SMLoc E = Parser.getTok().getEndLoc();
3947 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003948 if (Reg == -1) {
3949 if (!haveEaten)
3950 return MatchOperand_NoMatch;
3951 Error(Parser.getTok().getLoc(), "register expected");
3952 return MatchOperand_ParseFail;
3953 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003954
Jim Grosbachc320c852011-08-05 21:28:30 +00003955 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3956 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003957 if (Parser.getTok().is(AsmToken::Comma)) {
3958 Parser.Lex(); // Eat the ','.
3959 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3960 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003961
3962 // FIXME: Only approximates end...may include intervening whitespace.
3963 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003964 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003965
3966 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3967 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003968
3969 return MatchOperand_Success;
3970}
3971
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003972ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3973parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3974 // Check for a post-index addressing register operand. Specifically:
3975 // am3offset := '+' register
3976 // | '-' register
3977 // | register
3978 // | # imm
3979 // | # + imm
3980 // | # - imm
3981
3982 // This method must return MatchOperand_NoMatch without consuming any tokens
3983 // in the case where there is no match, as other alternatives take other
3984 // parse methods.
3985 AsmToken Tok = Parser.getTok();
3986 SMLoc S = Tok.getLoc();
3987
3988 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003989 if (Parser.getTok().is(AsmToken::Hash) ||
3990 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003991 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003992 // Explicitly look for a '-', as we need to encode negative zero
3993 // differently.
3994 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3995 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003996 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003997 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003998 return MatchOperand_ParseFail;
3999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4000 if (!CE) {
4001 Error(S, "constant expression expected");
4002 return MatchOperand_ParseFail;
4003 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004004 // Negative zero is encoded as the flag value INT32_MIN.
4005 int32_t Val = CE->getValue();
4006 if (isNegative && Val == 0)
4007 Val = INT32_MIN;
4008
4009 Operands.push_back(
4010 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4011
4012 return MatchOperand_Success;
4013 }
4014
4015
4016 bool haveEaten = false;
4017 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004018 if (Tok.is(AsmToken::Plus)) {
4019 Parser.Lex(); // Eat the '+' token.
4020 haveEaten = true;
4021 } else if (Tok.is(AsmToken::Minus)) {
4022 Parser.Lex(); // Eat the '-' token.
4023 isAdd = false;
4024 haveEaten = true;
4025 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004026
4027 Tok = Parser.getTok();
4028 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004029 if (Reg == -1) {
4030 if (!haveEaten)
4031 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004032 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004033 return MatchOperand_ParseFail;
4034 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004035
4036 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004037 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004038
4039 return MatchOperand_Success;
4040}
4041
Jim Grosbach7db8d692011-09-08 22:07:06 +00004042/// cvtT2LdrdPre - Convert parsed operands to MCInst.
4043/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4044/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004045void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004046cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00004047 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4048 // Rt, Rt2
4049 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4050 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4051 // Create a writeback register dummy placeholder.
4052 Inst.addOperand(MCOperand::CreateReg(0));
4053 // addr
4054 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4055 // pred
4056 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00004057}
4058
4059/// cvtT2StrdPre - Convert parsed operands to MCInst.
4060/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4061/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004062void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004063cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00004064 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4065 // Create a writeback register dummy placeholder.
4066 Inst.addOperand(MCOperand::CreateReg(0));
4067 // Rt, Rt2
4068 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4069 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4070 // addr
4071 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4072 // pred
4073 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00004074}
4075
Jim Grosbachc086f682011-09-08 00:39:19 +00004076/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4077/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4078/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004079void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004080cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00004081 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4082 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4083
4084 // Create a writeback register dummy placeholder.
4085 Inst.addOperand(MCOperand::CreateImm(0));
4086
4087 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4088 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00004089}
4090
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004091/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4092/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4093/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004094void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004095cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004096 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4097 // Create a writeback register dummy placeholder.
4098 Inst.addOperand(MCOperand::CreateImm(0));
4099 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4100 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4101 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004102}
4103
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004104/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004105/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4106/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004107void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004108cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004109 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4110 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4111
4112 // Create a writeback register dummy placeholder.
4113 Inst.addOperand(MCOperand::CreateImm(0));
4114
Jim Grosbachd3595712011-08-03 23:50:40 +00004115 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004116 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004117}
4118
Owen Anderson16d33f32011-08-26 20:43:14 +00004119/// cvtLdWriteBackRegAddrModeImm12 - 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 +00004123cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00004124 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4125 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4126
4127 // Create a writeback register dummy placeholder.
4128 Inst.addOperand(MCOperand::CreateImm(0));
4129
4130 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4131 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00004132}
4133
4134
Jim Grosbachd564bf32011-08-11 19:22:40 +00004135/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4136/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4137/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004138void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004139cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00004140 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4141 // Create a writeback register dummy placeholder.
4142 Inst.addOperand(MCOperand::CreateImm(0));
4143 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4144 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4145 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00004146}
4147
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004148/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004149/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4150/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004151void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004152cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004153 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4154 // Create a writeback register dummy placeholder.
4155 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00004156 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4157 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4158 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004159}
4160
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004161/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4162/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4163/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004164void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004165cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004166 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4167 // Create a writeback register dummy placeholder.
4168 Inst.addOperand(MCOperand::CreateImm(0));
4169 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4170 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4171 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004172}
4173
Jim Grosbachd3595712011-08-03 23:50:40 +00004174/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4175/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4176/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004177void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004178cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004179 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4180 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004181 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004182 // Create a writeback register dummy placeholder.
4183 Inst.addOperand(MCOperand::CreateImm(0));
4184 // addr
4185 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4186 // offset
4187 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4188 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004189 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004190}
4191
Jim Grosbachd3595712011-08-03 23:50:40 +00004192/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004193/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4194/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004195void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004196cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004197 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4198 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004199 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004200 // Create a writeback register dummy placeholder.
4201 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004202 // addr
4203 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4204 // offset
4205 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4206 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004207 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004208}
4209
Jim Grosbachd3595712011-08-03 23:50:40 +00004210/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004211/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4212/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004213void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004214cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004215 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004216 // Create a writeback register dummy placeholder.
4217 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004218 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004219 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004220 // addr
4221 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4222 // offset
4223 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4224 // pred
4225 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004226}
4227
4228/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4229/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4230/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004231void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004232cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004233 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4234 // Create a writeback register dummy placeholder.
4235 Inst.addOperand(MCOperand::CreateImm(0));
4236 // Rt
4237 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4238 // addr
4239 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4240 // offset
4241 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4242 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004243 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004244}
4245
Jim Grosbach5b96b802011-08-10 20:29:19 +00004246/// cvtLdrdPre - Convert parsed operands to MCInst.
4247/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4248/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004249void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004250cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004251 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4252 // Rt, Rt2
4253 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4254 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4255 // Create a writeback register dummy placeholder.
4256 Inst.addOperand(MCOperand::CreateImm(0));
4257 // addr
4258 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4259 // pred
4260 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004261}
4262
Jim Grosbacheb09f492011-08-11 20:28:23 +00004263/// cvtStrdPre - Convert parsed operands to MCInst.
4264/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4265/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004266void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004267cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004268 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4269 // Create a writeback register dummy placeholder.
4270 Inst.addOperand(MCOperand::CreateImm(0));
4271 // Rt, Rt2
4272 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4273 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4274 // addr
4275 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4276 // pred
4277 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004278}
4279
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004280/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4281/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4282/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004283void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004284cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004285 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4286 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4287 // Create a writeback register dummy placeholder.
4288 Inst.addOperand(MCOperand::CreateImm(0));
4289 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4290 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004291}
4292
Chad Rosier5eec49f2012-08-30 23:00:00 +00004293/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004294/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4295/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004296void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004297cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004298 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004299 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4300 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004301 // If we have a three-operand form, make sure to set Rn to be the operand
4302 // that isn't the same as Rd.
4303 unsigned RegOp = 4;
4304 if (Operands.size() == 6 &&
4305 ((ARMOperand*)Operands[4])->getReg() ==
4306 ((ARMOperand*)Operands[3])->getReg())
4307 RegOp = 5;
4308 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4309 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004310 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004311}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004312
Chad Rosier98cfa102012-08-31 00:03:31 +00004313void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004314cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004315 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4316 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004317 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004318 // Create a writeback register dummy placeholder.
4319 Inst.addOperand(MCOperand::CreateImm(0));
4320 // Vn
4321 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4322 // pred
4323 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004324}
4325
Chad Rosier98cfa102012-08-31 00:03:31 +00004326void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004327cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004328 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4329 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004330 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004331 // Create a writeback register dummy placeholder.
4332 Inst.addOperand(MCOperand::CreateImm(0));
4333 // Vn
4334 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4335 // Vm
4336 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4337 // pred
4338 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004339}
4340
Chad Rosier98cfa102012-08-31 00:03:31 +00004341void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004342cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004343 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4344 // Create a writeback register dummy placeholder.
4345 Inst.addOperand(MCOperand::CreateImm(0));
4346 // Vn
4347 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4348 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004349 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004350 // pred
4351 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004352}
4353
Chad Rosier98cfa102012-08-31 00:03:31 +00004354void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004355cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004356 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4357 // Create a writeback register dummy placeholder.
4358 Inst.addOperand(MCOperand::CreateImm(0));
4359 // Vn
4360 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4361 // Vm
4362 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4363 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004364 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004365 // pred
4366 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004367}
4368
Bill Wendlinge18980a2010-11-06 22:36:58 +00004369/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004370/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004371bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004372parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004373 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004374 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004375 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004376 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004377 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004378
Sean Callanan936b0d32010-01-19 21:44:56 +00004379 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004380 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004381 if (BaseRegNum == -1)
4382 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004383
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004384 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004385 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004386 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4387 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004388 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004389
Jim Grosbachd3595712011-08-03 23:50:40 +00004390 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004391 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004392 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004393
Jim Grosbachd3595712011-08-03 23:50:40 +00004394 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004395 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004396
Jim Grosbach40700e02011-09-19 18:42:21 +00004397 // If there's a pre-indexing writeback marker, '!', just add it as a token
4398 // operand. It's rather odd, but syntactically valid.
4399 if (Parser.getTok().is(AsmToken::Exclaim)) {
4400 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4401 Parser.Lex(); // Eat the '!'.
4402 }
4403
Jim Grosbachd3595712011-08-03 23:50:40 +00004404 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004405 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004406
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004407 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4408 "Lost colon or comma in memory operand?!");
4409 if (Tok.is(AsmToken::Comma)) {
4410 Parser.Lex(); // Eat the comma.
4411 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004412
Jim Grosbacha95ec992011-10-11 17:29:55 +00004413 // If we have a ':', it's an alignment specifier.
4414 if (Parser.getTok().is(AsmToken::Colon)) {
4415 Parser.Lex(); // Eat the ':'.
4416 E = Parser.getTok().getLoc();
4417
4418 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004419 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004420 return true;
4421
4422 // The expression has to be a constant. Memory references with relocations
4423 // don't come through here, as they use the <label> forms of the relevant
4424 // instructions.
4425 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4426 if (!CE)
4427 return Error (E, "constant expression expected");
4428
4429 unsigned Align = 0;
4430 switch (CE->getValue()) {
4431 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004432 return Error(E,
4433 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4434 case 16: Align = 2; break;
4435 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004436 case 64: Align = 8; break;
4437 case 128: Align = 16; break;
4438 case 256: Align = 32; break;
4439 }
4440
4441 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004442 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004443 return Error(Parser.getTok().getLoc(), "']' expected");
4444 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004445 Parser.Lex(); // Eat right bracket token.
4446
4447 // Don't worry about range checking the value here. That's handled by
4448 // the is*() predicates.
4449 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4450 ARM_AM::no_shift, 0, Align,
4451 false, S, E));
4452
4453 // If there's a pre-indexing writeback marker, '!', just add it as a token
4454 // operand.
4455 if (Parser.getTok().is(AsmToken::Exclaim)) {
4456 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4457 Parser.Lex(); // Eat the '!'.
4458 }
4459
4460 return false;
4461 }
4462
4463 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004464 // offset. Be friendly and also accept a plain integer (without a leading
4465 // hash) for gas compatibility.
4466 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004467 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004468 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004469 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004470 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004471 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004472
Owen Anderson967674d2011-08-29 19:36:44 +00004473 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004474 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004475 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004476 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004477
4478 // The expression has to be a constant. Memory references with relocations
4479 // don't come through here, as they use the <label> forms of the relevant
4480 // instructions.
4481 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4482 if (!CE)
4483 return Error (E, "constant expression expected");
4484
Owen Anderson967674d2011-08-29 19:36:44 +00004485 // If the constant was #-0, represent it as INT32_MIN.
4486 int32_t Val = CE->getValue();
4487 if (isNegative && Val == 0)
4488 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4489
Jim Grosbachd3595712011-08-03 23:50:40 +00004490 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004491 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004492 return Error(Parser.getTok().getLoc(), "']' expected");
4493 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004494 Parser.Lex(); // Eat right bracket token.
4495
4496 // Don't worry about range checking the value here. That's handled by
4497 // the is*() predicates.
4498 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004499 ARM_AM::no_shift, 0, 0,
4500 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004501
4502 // If there's a pre-indexing writeback marker, '!', just add it as a token
4503 // operand.
4504 if (Parser.getTok().is(AsmToken::Exclaim)) {
4505 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4506 Parser.Lex(); // Eat the '!'.
4507 }
4508
4509 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004510 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004511
4512 // The register offset is optionally preceded by a '+' or '-'
4513 bool isNegative = false;
4514 if (Parser.getTok().is(AsmToken::Minus)) {
4515 isNegative = true;
4516 Parser.Lex(); // Eat the '-'.
4517 } else if (Parser.getTok().is(AsmToken::Plus)) {
4518 // Nothing to do.
4519 Parser.Lex(); // Eat the '+'.
4520 }
4521
4522 E = Parser.getTok().getLoc();
4523 int OffsetRegNum = tryParseRegister();
4524 if (OffsetRegNum == -1)
4525 return Error(E, "register expected");
4526
4527 // If there's a shift operator, handle it.
4528 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004529 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004530 if (Parser.getTok().is(AsmToken::Comma)) {
4531 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004532 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004533 return true;
4534 }
4535
4536 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004537 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004538 return Error(Parser.getTok().getLoc(), "']' expected");
4539 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004540 Parser.Lex(); // Eat right bracket token.
4541
4542 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004543 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004544 S, E));
4545
Jim Grosbachc320c852011-08-05 21:28:30 +00004546 // If there's a pre-indexing writeback marker, '!', just add it as a token
4547 // operand.
4548 if (Parser.getTok().is(AsmToken::Exclaim)) {
4549 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4550 Parser.Lex(); // Eat the '!'.
4551 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004552
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004553 return false;
4554}
4555
Jim Grosbachd3595712011-08-03 23:50:40 +00004556/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004557/// ( lsl | lsr | asr | ror ) , # shift_amount
4558/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004559/// return true if it parses a shift otherwise it returns false.
4560bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4561 unsigned &Amount) {
4562 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004563 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004564 if (Tok.isNot(AsmToken::Identifier))
4565 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004566 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004567 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4568 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004569 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004570 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004571 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004572 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004573 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004574 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004575 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004576 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004577 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004578 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004579 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004580 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004581
Jim Grosbachd3595712011-08-03 23:50:40 +00004582 // rrx stands alone.
4583 Amount = 0;
4584 if (St != ARM_AM::rrx) {
4585 Loc = Parser.getTok().getLoc();
4586 // A '#' and a shift amount.
4587 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004588 if (HashTok.isNot(AsmToken::Hash) &&
4589 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004590 return Error(HashTok.getLoc(), "'#' expected");
4591 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004592
Jim Grosbachd3595712011-08-03 23:50:40 +00004593 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004594 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004595 return true;
4596 // Range check the immediate.
4597 // lsl, ror: 0 <= imm <= 31
4598 // lsr, asr: 0 <= imm <= 32
4599 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4600 if (!CE)
4601 return Error(Loc, "shift amount must be an immediate");
4602 int64_t Imm = CE->getValue();
4603 if (Imm < 0 ||
4604 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4605 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4606 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004607 // If <ShiftTy> #0, turn it into a no_shift.
4608 if (Imm == 0)
4609 St = ARM_AM::lsl;
4610 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4611 if (Imm == 32)
4612 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004613 Amount = Imm;
4614 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004615
4616 return false;
4617}
4618
Jim Grosbache7fbce72011-10-03 23:38:36 +00004619/// parseFPImm - A floating point immediate expression operand.
4620ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4621parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004622 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004623 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004624 // integer only.
4625 //
4626 // This routine still creates a generic Immediate operand, containing
4627 // a bitcast of the 64-bit floating point value. The various operands
4628 // that accept floats can check whether the value is valid for them
4629 // via the standard is*() predicates.
4630
Jim Grosbache7fbce72011-10-03 23:38:36 +00004631 SMLoc S = Parser.getTok().getLoc();
4632
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004633 if (Parser.getTok().isNot(AsmToken::Hash) &&
4634 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004635 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004636
4637 // Disambiguate the VMOV forms that can accept an FP immediate.
4638 // vmov.f32 <sreg>, #imm
4639 // vmov.f64 <dreg>, #imm
4640 // vmov.f32 <dreg>, #imm @ vector f32x2
4641 // vmov.f32 <qreg>, #imm @ vector f32x4
4642 //
4643 // There are also the NEON VMOV instructions which expect an
4644 // integer constant. Make sure we don't try to parse an FPImm
4645 // for these:
4646 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4647 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4648 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4649 TyOp->getToken() != ".f64"))
4650 return MatchOperand_NoMatch;
4651
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004652 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004653
4654 // Handle negation, as that still comes through as a separate token.
4655 bool isNegative = false;
4656 if (Parser.getTok().is(AsmToken::Minus)) {
4657 isNegative = true;
4658 Parser.Lex();
4659 }
4660 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004661 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004662 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004663 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004664 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4665 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004666 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004667 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004668 Operands.push_back(ARMOperand::CreateImm(
4669 MCConstantExpr::Create(IntVal, getContext()),
4670 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004671 return MatchOperand_Success;
4672 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004673 // Also handle plain integers. Instructions which allow floating point
4674 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004675 if (Tok.is(AsmToken::Integer)) {
4676 int64_t Val = Tok.getIntVal();
4677 Parser.Lex(); // Eat the token.
4678 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004679 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004680 return MatchOperand_ParseFail;
4681 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004682 double RealVal = ARM_AM::getFPImmFloat(Val);
4683 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4684 Operands.push_back(ARMOperand::CreateImm(
4685 MCConstantExpr::Create(Val, getContext()), S,
4686 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004687 return MatchOperand_Success;
4688 }
4689
Jim Grosbach235c8d22012-01-19 02:47:30 +00004690 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004691 return MatchOperand_ParseFail;
4692}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004693
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004694/// Parse a arm instruction operand. For now this parses the operand regardless
4695/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004696bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004697 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004698 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004699
4700 // Check if the current operand has a custom associated parser, if so, try to
4701 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004702 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4703 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004704 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004705 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4706 // there was a match, but an error occurred, in which case, just return that
4707 // the operand parsing failed.
4708 if (ResTy == MatchOperand_ParseFail)
4709 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004710
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004711 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004712 default:
4713 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004714 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004715 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004716 // If we've seen a branch mnemonic, the next operand must be a label. This
4717 // is true even if the label is a register name. So "br r1" means branch to
4718 // label "r1".
4719 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4720 if (!ExpectLabel) {
4721 if (!tryParseRegisterWithWriteBack(Operands))
4722 return false;
4723 int Res = tryParseShiftRegister(Operands);
4724 if (Res == 0) // success
4725 return false;
4726 else if (Res == -1) // irrecoverable error
4727 return true;
4728 // If this is VMRS, check for the apsr_nzcv operand.
4729 if (Mnemonic == "vmrs" &&
4730 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4731 S = Parser.getTok().getLoc();
4732 Parser.Lex();
4733 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4734 return false;
4735 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004736 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004737
4738 // Fall though for the Identifier case that is not a register or a
4739 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004740 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004741 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004742 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004743 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004744 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004745 // This was not a register so parse other operands that start with an
4746 // identifier (like labels) as expressions and create them as immediates.
4747 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004748 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004749 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004750 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004751 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004752 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4753 return false;
4754 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004755 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004756 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004757 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004758 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004759 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004760 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004761 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004762 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004763 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004764
4765 if (Parser.getTok().isNot(AsmToken::Colon)) {
4766 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4767 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004768 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004769 return true;
4770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4771 if (CE) {
4772 int32_t Val = CE->getValue();
4773 if (isNegative && Val == 0)
4774 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4775 }
4776 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4777 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004778
4779 // There can be a trailing '!' on operands that we want as a separate
4780 // '!' Token operand. Handle that here. For example, the compatibilty
4781 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4782 if (Parser.getTok().is(AsmToken::Exclaim)) {
4783 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4784 Parser.getTok().getLoc()));
4785 Parser.Lex(); // Eat exclaim token
4786 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004787 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004788 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004789 // w/ a ':' after the '#', it's just like a plain ':'.
4790 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004791 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004792 case AsmToken::Colon: {
4793 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004794 // FIXME: Check it's an expression prefix,
4795 // e.g. (FOO - :lower16:BAR) isn't legal.
4796 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004797 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004798 return true;
4799
Evan Cheng965b3c72011-01-13 07:58:56 +00004800 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004801 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004802 return true;
4803
Evan Cheng965b3c72011-01-13 07:58:56 +00004804 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004805 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004806 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004807 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004808 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004809 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004810 }
4811}
4812
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004813// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004814// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004815bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004816 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004817
4818 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004819 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004820 Parser.Lex(); // Eat ':'
4821
4822 if (getLexer().isNot(AsmToken::Identifier)) {
4823 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4824 return true;
4825 }
4826
4827 StringRef IDVal = Parser.getTok().getIdentifier();
4828 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004829 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004830 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004831 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004832 } else {
4833 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4834 return true;
4835 }
4836 Parser.Lex();
4837
4838 if (getLexer().isNot(AsmToken::Colon)) {
4839 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4840 return true;
4841 }
4842 Parser.Lex(); // Eat the last ':'
4843 return false;
4844}
4845
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004846/// \brief Given a mnemonic, split out possible predication code and carry
4847/// setting letters to form a canonical mnemonic and flags.
4848//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004849// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004850// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004851StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004852 unsigned &PredicationCode,
4853 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004854 unsigned &ProcessorIMod,
4855 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004856 PredicationCode = ARMCC::AL;
4857 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004858 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004859
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004860 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004861 //
4862 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004863 if ((Mnemonic == "movs" && isThumb()) ||
4864 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4865 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4866 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4867 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004868 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004869 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4870 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004871 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4872 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004873 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004874
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004875 // First, split out any predication code. Ignore mnemonics we know aren't
4876 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004877 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004878 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004879 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004880 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004881 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4882 .Case("eq", ARMCC::EQ)
4883 .Case("ne", ARMCC::NE)
4884 .Case("hs", ARMCC::HS)
4885 .Case("cs", ARMCC::HS)
4886 .Case("lo", ARMCC::LO)
4887 .Case("cc", ARMCC::LO)
4888 .Case("mi", ARMCC::MI)
4889 .Case("pl", ARMCC::PL)
4890 .Case("vs", ARMCC::VS)
4891 .Case("vc", ARMCC::VC)
4892 .Case("hi", ARMCC::HI)
4893 .Case("ls", ARMCC::LS)
4894 .Case("ge", ARMCC::GE)
4895 .Case("lt", ARMCC::LT)
4896 .Case("gt", ARMCC::GT)
4897 .Case("le", ARMCC::LE)
4898 .Case("al", ARMCC::AL)
4899 .Default(~0U);
4900 if (CC != ~0U) {
4901 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4902 PredicationCode = CC;
4903 }
Bill Wendling193961b2010-10-29 23:50:21 +00004904 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004905
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004906 // Next, determine if we have a carry setting bit. We explicitly ignore all
4907 // the instructions we know end in 's'.
4908 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004909 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004910 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4911 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4912 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004913 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004914 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004915 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004916 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004917 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004918 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004919 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4920 CarrySetting = true;
4921 }
4922
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004923 // The "cps" instruction can have a interrupt mode operand which is glued into
4924 // the mnemonic. Check if this is the case, split it and parse the imod op
4925 if (Mnemonic.startswith("cps")) {
4926 // Split out any imod code.
4927 unsigned IMod =
4928 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4929 .Case("ie", ARM_PROC::IE)
4930 .Case("id", ARM_PROC::ID)
4931 .Default(~0U);
4932 if (IMod != ~0U) {
4933 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4934 ProcessorIMod = IMod;
4935 }
4936 }
4937
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004938 // The "it" instruction has the condition mask on the end of the mnemonic.
4939 if (Mnemonic.startswith("it")) {
4940 ITMask = Mnemonic.slice(2, Mnemonic.size());
4941 Mnemonic = Mnemonic.slice(0, 2);
4942 }
4943
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004944 return Mnemonic;
4945}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004946
4947/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4948/// inclusion of carry set or predication code operands.
4949//
4950// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004951void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004952getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004953 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004954 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4955 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004956 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004957 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004958 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004959 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004960 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004961 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004962 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004963 Mnemonic == "mla" || Mnemonic == "smlal" ||
4964 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004965 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004966 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004967 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004968
Daniel Dunbar09264122011-01-11 19:06:29 +00004969 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4970 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4971 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4972 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004973 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4974 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004975 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004976 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4977 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4978 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004979 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4980 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004981 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004982 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004983 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004984 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004985
Jim Grosbach6c45b752011-09-16 16:39:25 +00004986 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004987 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004988 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004989 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004990 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004991}
4992
Jim Grosbach7283da92011-08-16 21:12:37 +00004993bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4994 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004995 // FIXME: This is all horribly hacky. We really need a better way to deal
4996 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004997
4998 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4999 // another does not. Specifically, the MOVW instruction does not. So we
5000 // special case it here and remove the defaulted (non-setting) cc_out
5001 // operand if that's the instruction we're trying to match.
5002 //
5003 // We do this as post-processing of the explicit operands rather than just
5004 // conditionally adding the cc_out in the first place because we need
5005 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005006 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00005007 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5008 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5009 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5010 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005011
5012 // Register-register 'add' for thumb does not have a cc_out operand
5013 // when there are only two register operands.
5014 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5015 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5016 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5017 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5018 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005019 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005020 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5021 // have to check the immediate range here since Thumb2 has a variant
5022 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005023 if (((isThumb() && Mnemonic == "add") ||
5024 (isThumbTwo() && Mnemonic == "sub")) &&
5025 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005026 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5027 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5028 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005029 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005030 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005031 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005032 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005033 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5034 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005035 // selecting via the generic "add" mnemonic, so to know that we
5036 // should remove the cc_out operand, we have to explicitly check that
5037 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005038 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5039 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005040 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5041 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5042 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5043 // Nest conditions rather than one big 'if' statement for readability.
5044 //
5045 // If either register is a high reg, it's either one of the SP
5046 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00005047 // check against T3. If the second register is the PC, this is an
5048 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005049 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5050 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00005051 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005052 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5053 return false;
5054 // If both registers are low, we're in an IT block, and the immediate is
5055 // in range, we should use encoding T1 instead, which has a cc_out.
5056 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005057 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005058 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5059 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5060 return false;
5061
5062 // Otherwise, we use encoding T4, which does not have a cc_out
5063 // operand.
5064 return true;
5065 }
5066
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005067 // The thumb2 multiply instruction doesn't have a CCOut register, so
5068 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5069 // use the 16-bit encoding or not.
5070 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5071 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5072 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5073 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5074 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5075 // If the registers aren't low regs, the destination reg isn't the
5076 // same as one of the source regs, or the cc_out operand is zero
5077 // outside of an IT block, we have to use the 32-bit encoding, so
5078 // remove the cc_out operand.
5079 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5080 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005081 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005082 !inITBlock() ||
5083 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5084 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5085 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5086 static_cast<ARMOperand*>(Operands[4])->getReg())))
5087 return true;
5088
Jim Grosbachefa7e952011-11-15 19:55:16 +00005089 // Also check the 'mul' syntax variant that doesn't specify an explicit
5090 // destination register.
5091 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5092 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5093 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5094 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5095 // If the registers aren't low regs or the cc_out operand is zero
5096 // outside of an IT block, we have to use the 32-bit encoding, so
5097 // remove the cc_out operand.
5098 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5099 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5100 !inITBlock()))
5101 return true;
5102
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005103
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005104
Jim Grosbach4b701af2011-08-24 21:42:27 +00005105 // Register-register 'add/sub' for thumb does not have a cc_out operand
5106 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5107 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5108 // right, this will result in better diagnostics (which operand is off)
5109 // anyway.
5110 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5111 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005112 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5113 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005114 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5115 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5116 (Operands.size() == 6 &&
5117 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005118 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005119
Jim Grosbach7283da92011-08-16 21:12:37 +00005120 return false;
5121}
5122
Jim Grosbach12952fe2011-11-11 23:08:10 +00005123static bool isDataTypeToken(StringRef Tok) {
5124 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5125 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5126 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5127 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5128 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5129 Tok == ".f" || Tok == ".d";
5130}
5131
5132// FIXME: This bit should probably be handled via an explicit match class
5133// in the .td files that matches the suffix instead of having it be
5134// a literal string token the way it is now.
5135static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5136 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5137}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005138static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5139 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005140/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005141bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5142 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005143 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005144 // Apply mnemonic aliases before doing anything else, as the destination
5145 // mnemnonic may include suffices and we want to handle them normally.
5146 // The generic tblgen'erated code does this later, at the start of
5147 // MatchInstructionImpl(), but that's too late for aliases that include
5148 // any sort of suffix.
5149 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005150 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5151 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005152
Jim Grosbachab5830e2011-12-14 02:16:11 +00005153 // First check for the ARM-specific .req directive.
5154 if (Parser.getTok().is(AsmToken::Identifier) &&
5155 Parser.getTok().getIdentifier() == ".req") {
5156 parseDirectiveReq(Name, NameLoc);
5157 // We always return 'error' for this, as we're done with this
5158 // statement and don't need to match the 'instruction."
5159 return true;
5160 }
5161
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005162 // Create the leading tokens for the mnemonic, split by '.' characters.
5163 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005164 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005165
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005166 // Split out the predication code and carry setting flag from the mnemonic.
5167 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005168 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005169 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005170 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005171 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005172 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005173
Jim Grosbach1c171b12011-08-25 17:23:55 +00005174 // In Thumb1, only the branch (B) instruction can be predicated.
5175 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005176 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005177 return Error(NameLoc, "conditional execution not supported in Thumb1");
5178 }
5179
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005180 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5181
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005182 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5183 // is the mask as it will be for the IT encoding if the conditional
5184 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5185 // where the conditional bit0 is zero, the instruction post-processing
5186 // will adjust the mask accordingly.
5187 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005188 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5189 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005190 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005191 return Error(Loc, "too many conditions on IT instruction");
5192 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005193 unsigned Mask = 8;
5194 for (unsigned i = ITMask.size(); i != 0; --i) {
5195 char pos = ITMask[i - 1];
5196 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005197 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005198 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005199 }
5200 Mask >>= 1;
5201 if (ITMask[i - 1] == 't')
5202 Mask |= 8;
5203 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005204 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005205 }
5206
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005207 // FIXME: This is all a pretty gross hack. We should automatically handle
5208 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005209
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005210 // Next, add the CCOut and ConditionCode operands, if needed.
5211 //
5212 // For mnemonics which can ever incorporate a carry setting bit or predication
5213 // code, our matching model involves us always generating CCOut and
5214 // ConditionCode operands to match the mnemonic "as written" and then we let
5215 // the matcher deal with finding the right instruction or generating an
5216 // appropriate error.
5217 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005218 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005219
Jim Grosbach03a8a162011-07-14 22:04:21 +00005220 // If we had a carry-set on an instruction that can't do that, issue an
5221 // error.
5222 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005223 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005224 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005225 "' can not set flags, but 's' suffix specified");
5226 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005227 // If we had a predication code on an instruction that can't do that, issue an
5228 // error.
5229 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005230 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005231 return Error(NameLoc, "instruction '" + Mnemonic +
5232 "' is not predicable, but condition code specified");
5233 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005234
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005235 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005236 if (CanAcceptCarrySet) {
5237 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005238 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005239 Loc));
5240 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005241
5242 // Add the predication code operand, if necessary.
5243 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005244 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5245 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005246 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005247 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005248 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005249
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005250 // Add the processor imod operand, if necessary.
5251 if (ProcessorIMod) {
5252 Operands.push_back(ARMOperand::CreateImm(
5253 MCConstantExpr::Create(ProcessorIMod, getContext()),
5254 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005255 }
5256
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005257 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005258 while (Next != StringRef::npos) {
5259 Start = Next;
5260 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005261 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005262
Jim Grosbach12952fe2011-11-11 23:08:10 +00005263 // Some NEON instructions have an optional datatype suffix that is
5264 // completely ignored. Check for that.
5265 if (isDataTypeToken(ExtraToken) &&
5266 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5267 continue;
5268
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005269 if (ExtraToken != ".n") {
5270 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5271 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5272 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005273 }
5274
5275 // Read the remaining operands.
5276 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005277 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005278 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005279 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005280 return true;
5281 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005282
5283 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005284 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005285
5286 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005287 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005288 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005289 return true;
5290 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005291 }
5292 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005293
Chris Lattnera2a9d162010-09-11 16:18:25 +00005294 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005295 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005296 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005297 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005298 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005299
Chris Lattner91689c12010-09-08 05:10:46 +00005300 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005301
Jim Grosbach7283da92011-08-16 21:12:37 +00005302 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5303 // do and don't have a cc_out optional-def operand. With some spot-checks
5304 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005305 // parse and adjust accordingly before actually matching. We shouldn't ever
5306 // try to remove a cc_out operand that was explicitly set on the the
5307 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5308 // table driven matcher doesn't fit well with the ARM instruction set.
5309 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005310 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5311 Operands.erase(Operands.begin() + 1);
5312 delete Op;
5313 }
5314
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005315 // ARM mode 'blx' need special handling, as the register operand version
5316 // is predicable, but the label operand version is not. So, we can't rely
5317 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005318 // a k_CondCode operand in the list. If we're trying to match the label
5319 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005320 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5321 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5322 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5323 Operands.erase(Operands.begin() + 1);
5324 delete Op;
5325 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005326
Weiming Zhao8f56f882012-11-16 21:55:34 +00005327 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5328 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5329 // a single GPRPair reg operand is used in the .td file to replace the two
5330 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5331 // expressed as a GPRPair, so we have to manually merge them.
5332 // FIXME: We would really like to be able to tablegen'erate this.
5333 if (!isThumb() && Operands.size() > 4 &&
5334 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5335 bool isLoad = (Mnemonic == "ldrexd");
5336 unsigned Idx = isLoad ? 2 : 3;
5337 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5338 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5339
5340 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5341 // Adjust only if Op1 and Op2 are GPRs.
5342 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5343 MRC.contains(Op2->getReg())) {
5344 unsigned Reg1 = Op1->getReg();
5345 unsigned Reg2 = Op2->getReg();
5346 unsigned Rt = MRI->getEncodingValue(Reg1);
5347 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5348
5349 // Rt2 must be Rt + 1 and Rt must be even.
5350 if (Rt + 1 != Rt2 || (Rt & 1)) {
5351 Error(Op2->getStartLoc(), isLoad ?
5352 "destination operands must be sequential" :
5353 "source operands must be sequential");
5354 return true;
5355 }
5356 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5357 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5358 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5359 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5360 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5361 delete Op1;
5362 delete Op2;
5363 }
5364 }
5365
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005366 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005367}
5368
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005369// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005370
5371// return 'true' if register list contains non-low GPR registers,
5372// 'false' otherwise. If Reg is in the register list or is HiReg, set
5373// 'containsReg' to true.
5374static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5375 unsigned HiReg, bool &containsReg) {
5376 containsReg = false;
5377 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5378 unsigned OpReg = Inst.getOperand(i).getReg();
5379 if (OpReg == Reg)
5380 containsReg = true;
5381 // Anything other than a low register isn't legal here.
5382 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5383 return true;
5384 }
5385 return false;
5386}
5387
Jim Grosbacha31f2232011-09-07 18:05:34 +00005388// Check if the specified regisgter is in the register list of the inst,
5389// starting at the indicated operand number.
5390static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5391 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5392 unsigned OpReg = Inst.getOperand(i).getReg();
5393 if (OpReg == Reg)
5394 return true;
5395 }
5396 return false;
5397}
5398
Jim Grosbached16ec42011-08-29 22:24:09 +00005399// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5400// the ARMInsts array) instead. Getting that here requires awkward
5401// API changes, though. Better way?
5402namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005403extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005404}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005405static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005406 return ARMInsts[Opcode];
5407}
5408
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005409// FIXME: We would really like to be able to tablegen'erate this.
5410bool ARMAsmParser::
5411validateInstruction(MCInst &Inst,
5412 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005413 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005414 SMLoc Loc = Operands[0]->getStartLoc();
5415 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005416 // NOTE: BKPT instruction has the interesting property of being
5417 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005418 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005419 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5420 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005421 unsigned bit = 1;
5422 if (ITState.FirstCond)
5423 ITState.FirstCond = false;
5424 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005425 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005426 // The instruction must be predicable.
5427 if (!MCID.isPredicable())
5428 return Error(Loc, "instructions in IT block must be predicable");
5429 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5430 unsigned ITCond = bit ? ITState.Cond :
5431 ARMCC::getOppositeCondition(ITState.Cond);
5432 if (Cond != ITCond) {
5433 // Find the condition code Operand to get its SMLoc information.
5434 SMLoc CondLoc;
5435 for (unsigned i = 1; i < Operands.size(); ++i)
5436 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5437 CondLoc = Operands[i]->getStartLoc();
5438 return Error(CondLoc, "incorrect condition in IT block; got '" +
5439 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5440 "', but expected '" +
5441 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5442 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005443 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005444 } else if (isThumbTwo() && MCID.isPredicable() &&
5445 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005446 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5447 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005448 return Error(Loc, "predicated instructions must be in IT block");
5449
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005450 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005451 case ARM::LDRD:
5452 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005453 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005454 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005455 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5456 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005457 if (Rt2 != Rt + 1)
5458 return Error(Operands[3]->getStartLoc(),
5459 "destination operands must be sequential");
5460 return false;
5461 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005462 case ARM::STRD: {
5463 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005464 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5465 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005466 if (Rt2 != Rt + 1)
5467 return Error(Operands[3]->getStartLoc(),
5468 "source operands must be sequential");
5469 return false;
5470 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005471 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005472 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005473 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005474 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5475 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005476 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005477 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005478 "source operands must be sequential");
5479 return false;
5480 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005481 case ARM::SBFX:
5482 case ARM::UBFX: {
5483 // width must be in range [1, 32-lsb]
5484 unsigned lsb = Inst.getOperand(2).getImm();
5485 unsigned widthm1 = Inst.getOperand(3).getImm();
5486 if (widthm1 >= 32 - lsb)
5487 return Error(Operands[5]->getStartLoc(),
5488 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005489 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005490 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005491 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005492 // If we're parsing Thumb2, the .w variant is available and handles
5493 // most cases that are normally illegal for a Thumb1 LDM
5494 // instruction. We'll make the transformation in processInstruction()
5495 // if necessary.
5496 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005497 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005498 // in the register list.
5499 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005500 bool hasWritebackToken =
5501 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5502 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005503 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005504 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005505 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5506 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005507 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005508 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005509 return Error(Operands[2]->getStartLoc(),
5510 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005511 // If we should not have writeback, there must not be a '!'. This is
5512 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005513 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005514 return Error(Operands[3]->getStartLoc(),
5515 "writeback operator '!' not allowed when base register "
5516 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005517
5518 break;
5519 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005520 case ARM::t2LDMIA_UPD: {
5521 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5522 return Error(Operands[4]->getStartLoc(),
5523 "writeback operator '!' not allowed when base register "
5524 "in register list");
5525 break;
5526 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005527 case ARM::tMUL: {
5528 // The second source operand must be the same register as the destination
5529 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005530 //
5531 // In this case, we must directly check the parsed operands because the
5532 // cvtThumbMultiply() function is written in such a way that it guarantees
5533 // this first statement is always true for the new Inst. Essentially, the
5534 // destination is unconditionally copied into the second source operand
5535 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005536 if (Operands.size() == 6 &&
5537 (((ARMOperand*)Operands[3])->getReg() !=
5538 ((ARMOperand*)Operands[5])->getReg()) &&
5539 (((ARMOperand*)Operands[3])->getReg() !=
5540 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005541 return Error(Operands[3]->getStartLoc(),
5542 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005543 }
5544 break;
5545 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005546 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5547 // so only issue a diagnostic for thumb1. The instructions will be
5548 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005549 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005550 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005551 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5552 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005553 return Error(Operands[2]->getStartLoc(),
5554 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005555 break;
5556 }
5557 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005558 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005559 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5560 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005561 return Error(Operands[2]->getStartLoc(),
5562 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005563 break;
5564 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005565 case ARM::tSTMIA_UPD: {
5566 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005567 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005568 return Error(Operands[4]->getStartLoc(),
5569 "registers must be in range r0-r7");
5570 break;
5571 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005572 case ARM::tADDrSP: {
5573 // If the non-SP source operand and the destination operand are not the
5574 // same, we need thumb2 (for the wide encoding), or we have an error.
5575 if (!isThumbTwo() &&
5576 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5577 return Error(Operands[4]->getStartLoc(),
5578 "source register must be the same as destination");
5579 }
5580 break;
5581 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005582 }
5583
5584 return false;
5585}
5586
Jim Grosbach1a747242012-01-23 23:45:44 +00005587static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005588 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005589 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005590 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005591 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5592 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5593 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5594 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5595 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5596 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5597 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5598 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5599 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005600
5601 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005602 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5603 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5604 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5605 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5606 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005607
Jim Grosbach1e946a42012-01-24 00:43:12 +00005608 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5609 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5610 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5611 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5612 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005613
Jim Grosbach1e946a42012-01-24 00:43:12 +00005614 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5615 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5616 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5617 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5618 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005619
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005620 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005621 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5622 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5623 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5624 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5625 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5626 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5627 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5628 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5629 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5630 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5631 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5632 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5633 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5634 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5635 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005636
Jim Grosbach1a747242012-01-23 23:45:44 +00005637 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005638 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5639 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5640 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5641 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5642 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5643 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5644 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5645 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5646 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5647 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5648 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5649 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5650 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5651 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5652 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5653 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5654 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5655 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005656
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005657 // VST4LN
5658 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5659 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5660 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5661 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5662 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5663 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5664 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5665 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5666 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5667 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5668 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5669 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5670 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5671 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5672 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5673
Jim Grosbachda70eac2012-01-24 00:58:13 +00005674 // VST4
5675 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5676 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5677 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5678 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5679 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5680 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5681 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5682 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5683 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5684 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5685 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5686 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5687 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5688 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5689 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5690 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5691 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5692 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005693 }
5694}
5695
Jim Grosbach1a747242012-01-23 23:45:44 +00005696static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005697 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005698 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005699 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005700 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5701 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5702 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5703 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5704 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5705 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5706 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5707 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5708 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005709
5710 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005711 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5712 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5713 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5714 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5715 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5716 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5717 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5718 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5719 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5720 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5721 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5722 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5723 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5724 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5725 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005726
Jim Grosbachb78403c2012-01-24 23:47:04 +00005727 // VLD3DUP
5728 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5729 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5730 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5731 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5732 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5733 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5734 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5735 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5736 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5737 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5738 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5739 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5740 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5741 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5742 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5743 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5744 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5745 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5746
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005747 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005748 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5749 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5750 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5751 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5752 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5753 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5754 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5755 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5756 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5757 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5758 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5759 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5760 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5761 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5762 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005763
5764 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005765 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5766 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5767 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5768 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5769 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5770 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5771 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5772 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5773 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5774 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5775 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5776 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5777 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5778 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5779 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5780 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5781 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5782 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005783
Jim Grosbach14952a02012-01-24 18:37:25 +00005784 // VLD4LN
5785 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5786 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5787 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5788 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5789 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5790 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5791 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5792 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5793 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5794 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5795 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5796 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5797 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5798 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5799 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5800
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005801 // VLD4DUP
5802 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5803 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5804 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5805 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5806 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5807 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5808 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5809 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5810 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5811 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5812 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5813 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5814 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5815 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5816 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5817 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5818 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5819 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5820
Jim Grosbached561fc2012-01-24 00:43:17 +00005821 // VLD4
5822 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5823 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5824 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5825 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5826 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5827 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5828 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5829 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5830 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5831 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5832 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5833 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5834 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5835 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5836 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5837 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5838 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5839 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005840 }
5841}
5842
Jim Grosbachafad0532011-11-10 23:42:14 +00005843bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005844processInstruction(MCInst &Inst,
5845 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5846 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005847 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5848 case ARM::ADDri: {
5849 if (Inst.getOperand(1).getReg() != ARM::PC ||
5850 Inst.getOperand(5).getReg() != 0)
5851 return false;
5852 MCInst TmpInst;
5853 TmpInst.setOpcode(ARM::ADR);
5854 TmpInst.addOperand(Inst.getOperand(0));
5855 TmpInst.addOperand(Inst.getOperand(2));
5856 TmpInst.addOperand(Inst.getOperand(3));
5857 TmpInst.addOperand(Inst.getOperand(4));
5858 Inst = TmpInst;
5859 return true;
5860 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005861 // Aliases for alternate PC+imm syntax of LDR instructions.
5862 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005863 // Select the narrow version if the immediate will fit.
5864 if (Inst.getOperand(1).getImm() > 0 &&
5865 Inst.getOperand(1).getImm() <= 0xff)
5866 Inst.setOpcode(ARM::tLDRpci);
5867 else
5868 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005869 return true;
5870 case ARM::t2LDRBpcrel:
5871 Inst.setOpcode(ARM::t2LDRBpci);
5872 return true;
5873 case ARM::t2LDRHpcrel:
5874 Inst.setOpcode(ARM::t2LDRHpci);
5875 return true;
5876 case ARM::t2LDRSBpcrel:
5877 Inst.setOpcode(ARM::t2LDRSBpci);
5878 return true;
5879 case ARM::t2LDRSHpcrel:
5880 Inst.setOpcode(ARM::t2LDRSHpci);
5881 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005882 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005883 case ARM::VST1LNdWB_register_Asm_8:
5884 case ARM::VST1LNdWB_register_Asm_16:
5885 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005886 MCInst TmpInst;
5887 // Shuffle the operands around so the lane index operand is in the
5888 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005889 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005890 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005891 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5892 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5893 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5894 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5895 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5896 TmpInst.addOperand(Inst.getOperand(1)); // lane
5897 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5898 TmpInst.addOperand(Inst.getOperand(6));
5899 Inst = TmpInst;
5900 return true;
5901 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005902
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005903 case ARM::VST2LNdWB_register_Asm_8:
5904 case ARM::VST2LNdWB_register_Asm_16:
5905 case ARM::VST2LNdWB_register_Asm_32:
5906 case ARM::VST2LNqWB_register_Asm_16:
5907 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005908 MCInst TmpInst;
5909 // Shuffle the operands around so the lane index operand is in the
5910 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005911 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005912 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005913 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5914 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5915 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5916 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5917 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5919 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005920 TmpInst.addOperand(Inst.getOperand(1)); // lane
5921 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5922 TmpInst.addOperand(Inst.getOperand(6));
5923 Inst = TmpInst;
5924 return true;
5925 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005926
5927 case ARM::VST3LNdWB_register_Asm_8:
5928 case ARM::VST3LNdWB_register_Asm_16:
5929 case ARM::VST3LNdWB_register_Asm_32:
5930 case ARM::VST3LNqWB_register_Asm_16:
5931 case ARM::VST3LNqWB_register_Asm_32: {
5932 MCInst TmpInst;
5933 // Shuffle the operands around so the lane index operand is in the
5934 // right place.
5935 unsigned Spacing;
5936 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5937 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5938 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5939 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5940 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5941 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5942 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5943 Spacing));
5944 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5945 Spacing * 2));
5946 TmpInst.addOperand(Inst.getOperand(1)); // lane
5947 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5948 TmpInst.addOperand(Inst.getOperand(6));
5949 Inst = TmpInst;
5950 return true;
5951 }
5952
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005953 case ARM::VST4LNdWB_register_Asm_8:
5954 case ARM::VST4LNdWB_register_Asm_16:
5955 case ARM::VST4LNdWB_register_Asm_32:
5956 case ARM::VST4LNqWB_register_Asm_16:
5957 case ARM::VST4LNqWB_register_Asm_32: {
5958 MCInst TmpInst;
5959 // Shuffle the operands around so the lane index operand is in the
5960 // right place.
5961 unsigned Spacing;
5962 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5963 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5964 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5965 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5966 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5967 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5968 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5969 Spacing));
5970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5971 Spacing * 2));
5972 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5973 Spacing * 3));
5974 TmpInst.addOperand(Inst.getOperand(1)); // lane
5975 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5976 TmpInst.addOperand(Inst.getOperand(6));
5977 Inst = TmpInst;
5978 return true;
5979 }
5980
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005981 case ARM::VST1LNdWB_fixed_Asm_8:
5982 case ARM::VST1LNdWB_fixed_Asm_16:
5983 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005984 MCInst TmpInst;
5985 // Shuffle the operands around so the lane index operand is in the
5986 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005987 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005988 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005989 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5990 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5991 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5992 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5994 TmpInst.addOperand(Inst.getOperand(1)); // lane
5995 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5996 TmpInst.addOperand(Inst.getOperand(5));
5997 Inst = TmpInst;
5998 return true;
5999 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006000
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006001 case ARM::VST2LNdWB_fixed_Asm_8:
6002 case ARM::VST2LNdWB_fixed_Asm_16:
6003 case ARM::VST2LNdWB_fixed_Asm_32:
6004 case ARM::VST2LNqWB_fixed_Asm_16:
6005 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006006 MCInst TmpInst;
6007 // Shuffle the operands around so the lane index operand is in the
6008 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006009 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006010 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006011 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6012 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6013 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6014 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6015 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006018 TmpInst.addOperand(Inst.getOperand(1)); // lane
6019 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6020 TmpInst.addOperand(Inst.getOperand(5));
6021 Inst = TmpInst;
6022 return true;
6023 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006024
6025 case ARM::VST3LNdWB_fixed_Asm_8:
6026 case ARM::VST3LNdWB_fixed_Asm_16:
6027 case ARM::VST3LNdWB_fixed_Asm_32:
6028 case ARM::VST3LNqWB_fixed_Asm_16:
6029 case ARM::VST3LNqWB_fixed_Asm_32: {
6030 MCInst TmpInst;
6031 // Shuffle the operands around so the lane index operand is in the
6032 // right place.
6033 unsigned Spacing;
6034 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6035 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6036 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6037 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6038 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6039 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6041 Spacing));
6042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6043 Spacing * 2));
6044 TmpInst.addOperand(Inst.getOperand(1)); // lane
6045 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6046 TmpInst.addOperand(Inst.getOperand(5));
6047 Inst = TmpInst;
6048 return true;
6049 }
6050
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006051 case ARM::VST4LNdWB_fixed_Asm_8:
6052 case ARM::VST4LNdWB_fixed_Asm_16:
6053 case ARM::VST4LNdWB_fixed_Asm_32:
6054 case ARM::VST4LNqWB_fixed_Asm_16:
6055 case ARM::VST4LNqWB_fixed_Asm_32: {
6056 MCInst TmpInst;
6057 // Shuffle the operands around so the lane index operand is in the
6058 // right place.
6059 unsigned Spacing;
6060 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6061 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6062 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6063 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6064 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6065 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6066 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6067 Spacing));
6068 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6069 Spacing * 2));
6070 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6071 Spacing * 3));
6072 TmpInst.addOperand(Inst.getOperand(1)); // lane
6073 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6074 TmpInst.addOperand(Inst.getOperand(5));
6075 Inst = TmpInst;
6076 return true;
6077 }
6078
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006079 case ARM::VST1LNdAsm_8:
6080 case ARM::VST1LNdAsm_16:
6081 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006082 MCInst TmpInst;
6083 // Shuffle the operands around so the lane index operand is in the
6084 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006085 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006086 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006087 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6088 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6089 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6090 TmpInst.addOperand(Inst.getOperand(1)); // lane
6091 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6092 TmpInst.addOperand(Inst.getOperand(5));
6093 Inst = TmpInst;
6094 return true;
6095 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006096
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006097 case ARM::VST2LNdAsm_8:
6098 case ARM::VST2LNdAsm_16:
6099 case ARM::VST2LNdAsm_32:
6100 case ARM::VST2LNqAsm_16:
6101 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006102 MCInst TmpInst;
6103 // Shuffle the operands around so the lane index operand is in the
6104 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006105 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006106 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006107 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6108 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6109 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6111 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006112 TmpInst.addOperand(Inst.getOperand(1)); // lane
6113 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6114 TmpInst.addOperand(Inst.getOperand(5));
6115 Inst = TmpInst;
6116 return true;
6117 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006118
6119 case ARM::VST3LNdAsm_8:
6120 case ARM::VST3LNdAsm_16:
6121 case ARM::VST3LNdAsm_32:
6122 case ARM::VST3LNqAsm_16:
6123 case ARM::VST3LNqAsm_32: {
6124 MCInst TmpInst;
6125 // Shuffle the operands around so the lane index operand is in the
6126 // right place.
6127 unsigned Spacing;
6128 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6129 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6130 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6131 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6132 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 Spacing));
6134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6135 Spacing * 2));
6136 TmpInst.addOperand(Inst.getOperand(1)); // lane
6137 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6138 TmpInst.addOperand(Inst.getOperand(5));
6139 Inst = TmpInst;
6140 return true;
6141 }
6142
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006143 case ARM::VST4LNdAsm_8:
6144 case ARM::VST4LNdAsm_16:
6145 case ARM::VST4LNdAsm_32:
6146 case ARM::VST4LNqAsm_16:
6147 case ARM::VST4LNqAsm_32: {
6148 MCInst TmpInst;
6149 // Shuffle the operands around so the lane index operand is in the
6150 // right place.
6151 unsigned Spacing;
6152 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6153 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6154 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6155 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6156 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6157 Spacing));
6158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6159 Spacing * 2));
6160 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6161 Spacing * 3));
6162 TmpInst.addOperand(Inst.getOperand(1)); // lane
6163 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6164 TmpInst.addOperand(Inst.getOperand(5));
6165 Inst = TmpInst;
6166 return true;
6167 }
6168
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006169 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006170 case ARM::VLD1LNdWB_register_Asm_8:
6171 case ARM::VLD1LNdWB_register_Asm_16:
6172 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006173 MCInst TmpInst;
6174 // Shuffle the operands around so the lane index operand is in the
6175 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006176 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006177 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006178 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6179 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6180 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6181 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6182 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6183 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6184 TmpInst.addOperand(Inst.getOperand(1)); // lane
6185 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6186 TmpInst.addOperand(Inst.getOperand(6));
6187 Inst = TmpInst;
6188 return true;
6189 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006190
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006191 case ARM::VLD2LNdWB_register_Asm_8:
6192 case ARM::VLD2LNdWB_register_Asm_16:
6193 case ARM::VLD2LNdWB_register_Asm_32:
6194 case ARM::VLD2LNqWB_register_Asm_16:
6195 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006196 MCInst TmpInst;
6197 // Shuffle the operands around so the lane index operand is in the
6198 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006199 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006200 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006201 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006204 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6205 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6206 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6207 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6208 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006211 TmpInst.addOperand(Inst.getOperand(1)); // lane
6212 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6213 TmpInst.addOperand(Inst.getOperand(6));
6214 Inst = TmpInst;
6215 return true;
6216 }
6217
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006218 case ARM::VLD3LNdWB_register_Asm_8:
6219 case ARM::VLD3LNdWB_register_Asm_16:
6220 case ARM::VLD3LNdWB_register_Asm_32:
6221 case ARM::VLD3LNqWB_register_Asm_16:
6222 case ARM::VLD3LNqWB_register_Asm_32: {
6223 MCInst TmpInst;
6224 // Shuffle the operands around so the lane index operand is in the
6225 // right place.
6226 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006227 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006228 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6229 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6230 Spacing));
6231 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006232 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006233 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6234 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6235 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6236 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6237 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6238 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6239 Spacing));
6240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006241 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006242 TmpInst.addOperand(Inst.getOperand(1)); // lane
6243 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6244 TmpInst.addOperand(Inst.getOperand(6));
6245 Inst = TmpInst;
6246 return true;
6247 }
6248
Jim Grosbach14952a02012-01-24 18:37:25 +00006249 case ARM::VLD4LNdWB_register_Asm_8:
6250 case ARM::VLD4LNdWB_register_Asm_16:
6251 case ARM::VLD4LNdWB_register_Asm_32:
6252 case ARM::VLD4LNqWB_register_Asm_16:
6253 case ARM::VLD4LNqWB_register_Asm_32: {
6254 MCInst TmpInst;
6255 // Shuffle the operands around so the lane index operand is in the
6256 // right place.
6257 unsigned Spacing;
6258 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6259 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 Spacing));
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6263 Spacing * 2));
6264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6265 Spacing * 3));
6266 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6267 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6268 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6269 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6270 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6272 Spacing));
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6274 Spacing * 2));
6275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6276 Spacing * 3));
6277 TmpInst.addOperand(Inst.getOperand(1)); // lane
6278 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6279 TmpInst.addOperand(Inst.getOperand(6));
6280 Inst = TmpInst;
6281 return true;
6282 }
6283
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006284 case ARM::VLD1LNdWB_fixed_Asm_8:
6285 case ARM::VLD1LNdWB_fixed_Asm_16:
6286 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006287 MCInst TmpInst;
6288 // Shuffle the operands around so the lane index operand is in the
6289 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006290 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006291 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006292 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6293 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6294 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6295 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6296 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6297 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6298 TmpInst.addOperand(Inst.getOperand(1)); // lane
6299 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6300 TmpInst.addOperand(Inst.getOperand(5));
6301 Inst = TmpInst;
6302 return true;
6303 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006304
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006305 case ARM::VLD2LNdWB_fixed_Asm_8:
6306 case ARM::VLD2LNdWB_fixed_Asm_16:
6307 case ARM::VLD2LNdWB_fixed_Asm_32:
6308 case ARM::VLD2LNqWB_fixed_Asm_16:
6309 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006310 MCInst TmpInst;
6311 // Shuffle the operands around so the lane index operand is in the
6312 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006313 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006314 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006315 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006318 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6319 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6320 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6321 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6322 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006325 TmpInst.addOperand(Inst.getOperand(1)); // lane
6326 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6327 TmpInst.addOperand(Inst.getOperand(5));
6328 Inst = TmpInst;
6329 return true;
6330 }
6331
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006332 case ARM::VLD3LNdWB_fixed_Asm_8:
6333 case ARM::VLD3LNdWB_fixed_Asm_16:
6334 case ARM::VLD3LNdWB_fixed_Asm_32:
6335 case ARM::VLD3LNqWB_fixed_Asm_16:
6336 case ARM::VLD3LNqWB_fixed_Asm_32: {
6337 MCInst TmpInst;
6338 // Shuffle the operands around so the lane index operand is in the
6339 // right place.
6340 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006341 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006342 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6344 Spacing));
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006346 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006347 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6348 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6349 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6350 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6351 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6353 Spacing));
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006355 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006356 TmpInst.addOperand(Inst.getOperand(1)); // lane
6357 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6358 TmpInst.addOperand(Inst.getOperand(5));
6359 Inst = TmpInst;
6360 return true;
6361 }
6362
Jim Grosbach14952a02012-01-24 18:37:25 +00006363 case ARM::VLD4LNdWB_fixed_Asm_8:
6364 case ARM::VLD4LNdWB_fixed_Asm_16:
6365 case ARM::VLD4LNdWB_fixed_Asm_32:
6366 case ARM::VLD4LNqWB_fixed_Asm_16:
6367 case ARM::VLD4LNqWB_fixed_Asm_32: {
6368 MCInst TmpInst;
6369 // Shuffle the operands around so the lane index operand is in the
6370 // right place.
6371 unsigned Spacing;
6372 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6373 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 Spacing));
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6377 Spacing * 2));
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6379 Spacing * 3));
6380 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6381 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6382 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6383 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6384 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6386 Spacing));
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6388 Spacing * 2));
6389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6390 Spacing * 3));
6391 TmpInst.addOperand(Inst.getOperand(1)); // lane
6392 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6393 TmpInst.addOperand(Inst.getOperand(5));
6394 Inst = TmpInst;
6395 return true;
6396 }
6397
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006398 case ARM::VLD1LNdAsm_8:
6399 case ARM::VLD1LNdAsm_16:
6400 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006401 MCInst TmpInst;
6402 // Shuffle the operands around so the lane index operand is in the
6403 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006404 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006405 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006406 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6407 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6408 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6409 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6410 TmpInst.addOperand(Inst.getOperand(1)); // lane
6411 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6412 TmpInst.addOperand(Inst.getOperand(5));
6413 Inst = TmpInst;
6414 return true;
6415 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006416
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006417 case ARM::VLD2LNdAsm_8:
6418 case ARM::VLD2LNdAsm_16:
6419 case ARM::VLD2LNdAsm_32:
6420 case ARM::VLD2LNqAsm_16:
6421 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006422 MCInst TmpInst;
6423 // Shuffle the operands around so the lane index operand is in the
6424 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006425 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6429 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006430 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6431 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6432 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6434 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006435 TmpInst.addOperand(Inst.getOperand(1)); // lane
6436 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6437 TmpInst.addOperand(Inst.getOperand(5));
6438 Inst = TmpInst;
6439 return true;
6440 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006441
6442 case ARM::VLD3LNdAsm_8:
6443 case ARM::VLD3LNdAsm_16:
6444 case ARM::VLD3LNdAsm_32:
6445 case ARM::VLD3LNqAsm_16:
6446 case ARM::VLD3LNqAsm_32: {
6447 MCInst TmpInst;
6448 // Shuffle the operands around so the lane index operand is in the
6449 // right place.
6450 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006451 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 Spacing));
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006456 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006457 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6458 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6459 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6460 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6461 Spacing));
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006463 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006464 TmpInst.addOperand(Inst.getOperand(1)); // lane
6465 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6466 TmpInst.addOperand(Inst.getOperand(5));
6467 Inst = TmpInst;
6468 return true;
6469 }
6470
Jim Grosbach14952a02012-01-24 18:37:25 +00006471 case ARM::VLD4LNdAsm_8:
6472 case ARM::VLD4LNdAsm_16:
6473 case ARM::VLD4LNdAsm_32:
6474 case ARM::VLD4LNqAsm_16:
6475 case ARM::VLD4LNqAsm_32: {
6476 MCInst TmpInst;
6477 // Shuffle the operands around so the lane index operand is in the
6478 // right place.
6479 unsigned Spacing;
6480 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6481 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6482 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6483 Spacing));
6484 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6485 Spacing * 2));
6486 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6487 Spacing * 3));
6488 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6489 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6490 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing));
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 Spacing * 2));
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing * 3));
6497 TmpInst.addOperand(Inst.getOperand(1)); // lane
6498 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6499 TmpInst.addOperand(Inst.getOperand(5));
6500 Inst = TmpInst;
6501 return true;
6502 }
6503
Jim Grosbachb78403c2012-01-24 23:47:04 +00006504 // VLD3DUP single 3-element structure to all lanes instructions.
6505 case ARM::VLD3DUPdAsm_8:
6506 case ARM::VLD3DUPdAsm_16:
6507 case ARM::VLD3DUPdAsm_32:
6508 case ARM::VLD3DUPqAsm_8:
6509 case ARM::VLD3DUPqAsm_16:
6510 case ARM::VLD3DUPqAsm_32: {
6511 MCInst TmpInst;
6512 unsigned Spacing;
6513 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6514 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6515 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6516 Spacing));
6517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6518 Spacing * 2));
6519 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6520 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6521 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6522 TmpInst.addOperand(Inst.getOperand(4));
6523 Inst = TmpInst;
6524 return true;
6525 }
6526
6527 case ARM::VLD3DUPdWB_fixed_Asm_8:
6528 case ARM::VLD3DUPdWB_fixed_Asm_16:
6529 case ARM::VLD3DUPdWB_fixed_Asm_32:
6530 case ARM::VLD3DUPqWB_fixed_Asm_8:
6531 case ARM::VLD3DUPqWB_fixed_Asm_16:
6532 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6533 MCInst TmpInst;
6534 unsigned Spacing;
6535 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6536 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing));
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing * 2));
6541 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6542 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6543 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6544 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6545 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6546 TmpInst.addOperand(Inst.getOperand(4));
6547 Inst = TmpInst;
6548 return true;
6549 }
6550
6551 case ARM::VLD3DUPdWB_register_Asm_8:
6552 case ARM::VLD3DUPdWB_register_Asm_16:
6553 case ARM::VLD3DUPdWB_register_Asm_32:
6554 case ARM::VLD3DUPqWB_register_Asm_8:
6555 case ARM::VLD3DUPqWB_register_Asm_16:
6556 case ARM::VLD3DUPqWB_register_Asm_32: {
6557 MCInst TmpInst;
6558 unsigned Spacing;
6559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 2));
6565 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6566 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6567 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6568 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6569 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6570 TmpInst.addOperand(Inst.getOperand(5));
6571 Inst = TmpInst;
6572 return true;
6573 }
6574
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006575 // VLD3 multiple 3-element structure instructions.
6576 case ARM::VLD3dAsm_8:
6577 case ARM::VLD3dAsm_16:
6578 case ARM::VLD3dAsm_32:
6579 case ARM::VLD3qAsm_8:
6580 case ARM::VLD3qAsm_16:
6581 case ARM::VLD3qAsm_32: {
6582 MCInst TmpInst;
6583 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006584 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006585 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6587 Spacing));
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6589 Spacing * 2));
6590 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6591 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6592 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6593 TmpInst.addOperand(Inst.getOperand(4));
6594 Inst = TmpInst;
6595 return true;
6596 }
6597
6598 case ARM::VLD3dWB_fixed_Asm_8:
6599 case ARM::VLD3dWB_fixed_Asm_16:
6600 case ARM::VLD3dWB_fixed_Asm_32:
6601 case ARM::VLD3qWB_fixed_Asm_8:
6602 case ARM::VLD3qWB_fixed_Asm_16:
6603 case ARM::VLD3qWB_fixed_Asm_32: {
6604 MCInst TmpInst;
6605 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006606 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006607 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6608 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 Spacing));
6610 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 Spacing * 2));
6612 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6613 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6614 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6615 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6616 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6617 TmpInst.addOperand(Inst.getOperand(4));
6618 Inst = TmpInst;
6619 return true;
6620 }
6621
6622 case ARM::VLD3dWB_register_Asm_8:
6623 case ARM::VLD3dWB_register_Asm_16:
6624 case ARM::VLD3dWB_register_Asm_32:
6625 case ARM::VLD3qWB_register_Asm_8:
6626 case ARM::VLD3qWB_register_Asm_16:
6627 case ARM::VLD3qWB_register_Asm_32: {
6628 MCInst TmpInst;
6629 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006630 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006631 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 Spacing * 2));
6636 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6637 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6638 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6639 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6640 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6641 TmpInst.addOperand(Inst.getOperand(5));
6642 Inst = TmpInst;
6643 return true;
6644 }
6645
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006646 // VLD4DUP single 3-element structure to all lanes instructions.
6647 case ARM::VLD4DUPdAsm_8:
6648 case ARM::VLD4DUPdAsm_16:
6649 case ARM::VLD4DUPdAsm_32:
6650 case ARM::VLD4DUPqAsm_8:
6651 case ARM::VLD4DUPqAsm_16:
6652 case ARM::VLD4DUPqAsm_32: {
6653 MCInst TmpInst;
6654 unsigned Spacing;
6655 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6656 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6658 Spacing));
6659 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6660 Spacing * 2));
6661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6662 Spacing * 3));
6663 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6664 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6665 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6666 TmpInst.addOperand(Inst.getOperand(4));
6667 Inst = TmpInst;
6668 return true;
6669 }
6670
6671 case ARM::VLD4DUPdWB_fixed_Asm_8:
6672 case ARM::VLD4DUPdWB_fixed_Asm_16:
6673 case ARM::VLD4DUPdWB_fixed_Asm_32:
6674 case ARM::VLD4DUPqWB_fixed_Asm_8:
6675 case ARM::VLD4DUPqWB_fixed_Asm_16:
6676 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6677 MCInst TmpInst;
6678 unsigned Spacing;
6679 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6680 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6682 Spacing));
6683 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6684 Spacing * 2));
6685 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6686 Spacing * 3));
6687 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6688 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6689 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6690 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6691 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6692 TmpInst.addOperand(Inst.getOperand(4));
6693 Inst = TmpInst;
6694 return true;
6695 }
6696
6697 case ARM::VLD4DUPdWB_register_Asm_8:
6698 case ARM::VLD4DUPdWB_register_Asm_16:
6699 case ARM::VLD4DUPdWB_register_Asm_32:
6700 case ARM::VLD4DUPqWB_register_Asm_8:
6701 case ARM::VLD4DUPqWB_register_Asm_16:
6702 case ARM::VLD4DUPqWB_register_Asm_32: {
6703 MCInst TmpInst;
6704 unsigned Spacing;
6705 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6706 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 Spacing));
6709 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6710 Spacing * 2));
6711 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6712 Spacing * 3));
6713 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6714 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6715 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6716 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6717 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6718 TmpInst.addOperand(Inst.getOperand(5));
6719 Inst = TmpInst;
6720 return true;
6721 }
6722
6723 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006724 case ARM::VLD4dAsm_8:
6725 case ARM::VLD4dAsm_16:
6726 case ARM::VLD4dAsm_32:
6727 case ARM::VLD4qAsm_8:
6728 case ARM::VLD4qAsm_16:
6729 case ARM::VLD4qAsm_32: {
6730 MCInst TmpInst;
6731 unsigned Spacing;
6732 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6733 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 Spacing));
6736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 Spacing * 2));
6738 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6739 Spacing * 3));
6740 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6742 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6743 TmpInst.addOperand(Inst.getOperand(4));
6744 Inst = TmpInst;
6745 return true;
6746 }
6747
6748 case ARM::VLD4dWB_fixed_Asm_8:
6749 case ARM::VLD4dWB_fixed_Asm_16:
6750 case ARM::VLD4dWB_fixed_Asm_32:
6751 case ARM::VLD4qWB_fixed_Asm_8:
6752 case ARM::VLD4qWB_fixed_Asm_16:
6753 case ARM::VLD4qWB_fixed_Asm_32: {
6754 MCInst TmpInst;
6755 unsigned Spacing;
6756 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6757 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6758 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6759 Spacing));
6760 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6761 Spacing * 2));
6762 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6763 Spacing * 3));
6764 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6765 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6766 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6767 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6768 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6769 TmpInst.addOperand(Inst.getOperand(4));
6770 Inst = TmpInst;
6771 return true;
6772 }
6773
6774 case ARM::VLD4dWB_register_Asm_8:
6775 case ARM::VLD4dWB_register_Asm_16:
6776 case ARM::VLD4dWB_register_Asm_32:
6777 case ARM::VLD4qWB_register_Asm_8:
6778 case ARM::VLD4qWB_register_Asm_16:
6779 case ARM::VLD4qWB_register_Asm_32: {
6780 MCInst TmpInst;
6781 unsigned Spacing;
6782 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6783 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6784 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6785 Spacing));
6786 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6787 Spacing * 2));
6788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6789 Spacing * 3));
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6791 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6792 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6793 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6794 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6795 TmpInst.addOperand(Inst.getOperand(5));
6796 Inst = TmpInst;
6797 return true;
6798 }
6799
Jim Grosbach1a747242012-01-23 23:45:44 +00006800 // VST3 multiple 3-element structure instructions.
6801 case ARM::VST3dAsm_8:
6802 case ARM::VST3dAsm_16:
6803 case ARM::VST3dAsm_32:
6804 case ARM::VST3qAsm_8:
6805 case ARM::VST3qAsm_16:
6806 case ARM::VST3qAsm_32: {
6807 MCInst TmpInst;
6808 unsigned Spacing;
6809 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6810 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6811 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6812 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6813 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6814 Spacing));
6815 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6816 Spacing * 2));
6817 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6818 TmpInst.addOperand(Inst.getOperand(4));
6819 Inst = TmpInst;
6820 return true;
6821 }
6822
6823 case ARM::VST3dWB_fixed_Asm_8:
6824 case ARM::VST3dWB_fixed_Asm_16:
6825 case ARM::VST3dWB_fixed_Asm_32:
6826 case ARM::VST3qWB_fixed_Asm_8:
6827 case ARM::VST3qWB_fixed_Asm_16:
6828 case ARM::VST3qWB_fixed_Asm_32: {
6829 MCInst TmpInst;
6830 unsigned Spacing;
6831 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6832 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6833 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6834 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6835 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6836 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6837 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6838 Spacing));
6839 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6840 Spacing * 2));
6841 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6842 TmpInst.addOperand(Inst.getOperand(4));
6843 Inst = TmpInst;
6844 return true;
6845 }
6846
6847 case ARM::VST3dWB_register_Asm_8:
6848 case ARM::VST3dWB_register_Asm_16:
6849 case ARM::VST3dWB_register_Asm_32:
6850 case ARM::VST3qWB_register_Asm_8:
6851 case ARM::VST3qWB_register_Asm_16:
6852 case ARM::VST3qWB_register_Asm_32: {
6853 MCInst TmpInst;
6854 unsigned Spacing;
6855 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6856 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6857 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6858 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6859 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6860 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 Spacing));
6863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing * 2));
6865 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6866 TmpInst.addOperand(Inst.getOperand(5));
6867 Inst = TmpInst;
6868 return true;
6869 }
6870
Jim Grosbachda70eac2012-01-24 00:58:13 +00006871 // VST4 multiple 3-element structure instructions.
6872 case ARM::VST4dAsm_8:
6873 case ARM::VST4dAsm_16:
6874 case ARM::VST4dAsm_32:
6875 case ARM::VST4qAsm_8:
6876 case ARM::VST4qAsm_16:
6877 case ARM::VST4qAsm_32: {
6878 MCInst TmpInst;
6879 unsigned Spacing;
6880 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6881 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6882 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6883 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6885 Spacing));
6886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6887 Spacing * 2));
6888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6889 Spacing * 3));
6890 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6891 TmpInst.addOperand(Inst.getOperand(4));
6892 Inst = TmpInst;
6893 return true;
6894 }
6895
6896 case ARM::VST4dWB_fixed_Asm_8:
6897 case ARM::VST4dWB_fixed_Asm_16:
6898 case ARM::VST4dWB_fixed_Asm_32:
6899 case ARM::VST4qWB_fixed_Asm_8:
6900 case ARM::VST4qWB_fixed_Asm_16:
6901 case ARM::VST4qWB_fixed_Asm_32: {
6902 MCInst TmpInst;
6903 unsigned Spacing;
6904 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6905 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6906 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6907 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6908 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6909 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6910 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6911 Spacing));
6912 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6913 Spacing * 2));
6914 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6915 Spacing * 3));
6916 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6917 TmpInst.addOperand(Inst.getOperand(4));
6918 Inst = TmpInst;
6919 return true;
6920 }
6921
6922 case ARM::VST4dWB_register_Asm_8:
6923 case ARM::VST4dWB_register_Asm_16:
6924 case ARM::VST4dWB_register_Asm_32:
6925 case ARM::VST4qWB_register_Asm_8:
6926 case ARM::VST4qWB_register_Asm_16:
6927 case ARM::VST4qWB_register_Asm_32: {
6928 MCInst TmpInst;
6929 unsigned Spacing;
6930 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6931 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6932 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6933 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6934 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6935 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6936 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6937 Spacing));
6938 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6939 Spacing * 2));
6940 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 Spacing * 3));
6942 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6943 TmpInst.addOperand(Inst.getOperand(5));
6944 Inst = TmpInst;
6945 return true;
6946 }
6947
Jim Grosbachad66de12012-04-11 00:15:16 +00006948 // Handle encoding choice for the shift-immediate instructions.
6949 case ARM::t2LSLri:
6950 case ARM::t2LSRri:
6951 case ARM::t2ASRri: {
6952 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6953 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6954 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6955 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6956 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6957 unsigned NewOpc;
6958 switch (Inst.getOpcode()) {
6959 default: llvm_unreachable("unexpected opcode");
6960 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6961 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6962 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6963 }
6964 // The Thumb1 operands aren't in the same order. Awesome, eh?
6965 MCInst TmpInst;
6966 TmpInst.setOpcode(NewOpc);
6967 TmpInst.addOperand(Inst.getOperand(0));
6968 TmpInst.addOperand(Inst.getOperand(5));
6969 TmpInst.addOperand(Inst.getOperand(1));
6970 TmpInst.addOperand(Inst.getOperand(2));
6971 TmpInst.addOperand(Inst.getOperand(3));
6972 TmpInst.addOperand(Inst.getOperand(4));
6973 Inst = TmpInst;
6974 return true;
6975 }
6976 return false;
6977 }
6978
Jim Grosbach485e5622011-12-13 22:45:11 +00006979 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006980 case ARM::t2MOVsr:
6981 case ARM::t2MOVSsr: {
6982 // Which instruction to expand to depends on the CCOut operand and
6983 // whether we're in an IT block if the register operands are low
6984 // registers.
6985 bool isNarrow = false;
6986 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6987 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6988 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6989 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6990 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6991 isNarrow = true;
6992 MCInst TmpInst;
6993 unsigned newOpc;
6994 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6995 default: llvm_unreachable("unexpected opcode!");
6996 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6997 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6998 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6999 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7000 }
7001 TmpInst.setOpcode(newOpc);
7002 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7003 if (isNarrow)
7004 TmpInst.addOperand(MCOperand::CreateReg(
7005 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7006 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7007 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7008 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7009 TmpInst.addOperand(Inst.getOperand(5));
7010 if (!isNarrow)
7011 TmpInst.addOperand(MCOperand::CreateReg(
7012 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7013 Inst = TmpInst;
7014 return true;
7015 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007016 case ARM::t2MOVsi:
7017 case ARM::t2MOVSsi: {
7018 // Which instruction to expand to depends on the CCOut operand and
7019 // whether we're in an IT block if the register operands are low
7020 // registers.
7021 bool isNarrow = false;
7022 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7023 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7024 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7025 isNarrow = true;
7026 MCInst TmpInst;
7027 unsigned newOpc;
7028 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7029 default: llvm_unreachable("unexpected opcode!");
7030 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7031 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7032 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7033 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007034 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007035 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007036 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7037 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007038 TmpInst.setOpcode(newOpc);
7039 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7040 if (isNarrow)
7041 TmpInst.addOperand(MCOperand::CreateReg(
7042 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7043 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007044 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007045 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007046 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7047 TmpInst.addOperand(Inst.getOperand(4));
7048 if (!isNarrow)
7049 TmpInst.addOperand(MCOperand::CreateReg(
7050 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7051 Inst = TmpInst;
7052 return true;
7053 }
7054 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007055 case ARM::ASRr:
7056 case ARM::LSRr:
7057 case ARM::LSLr:
7058 case ARM::RORr: {
7059 ARM_AM::ShiftOpc ShiftTy;
7060 switch(Inst.getOpcode()) {
7061 default: llvm_unreachable("unexpected opcode!");
7062 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7063 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7064 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7065 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7066 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007067 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7068 MCInst TmpInst;
7069 TmpInst.setOpcode(ARM::MOVsr);
7070 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7071 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7072 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7073 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7074 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7075 TmpInst.addOperand(Inst.getOperand(4));
7076 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7077 Inst = TmpInst;
7078 return true;
7079 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007080 case ARM::ASRi:
7081 case ARM::LSRi:
7082 case ARM::LSLi:
7083 case ARM::RORi: {
7084 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007085 switch(Inst.getOpcode()) {
7086 default: llvm_unreachable("unexpected opcode!");
7087 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7088 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7089 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7090 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7091 }
7092 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007093 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007094 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007095 // A shift by 32 should be encoded as 0 when permitted
7096 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7097 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007098 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007099 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007100 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007101 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7102 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007103 if (Opc == ARM::MOVsi)
7104 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007105 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7106 TmpInst.addOperand(Inst.getOperand(4));
7107 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7108 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007109 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007110 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007111 case ARM::RRXi: {
7112 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7113 MCInst TmpInst;
7114 TmpInst.setOpcode(ARM::MOVsi);
7115 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7116 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7117 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7118 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7119 TmpInst.addOperand(Inst.getOperand(3));
7120 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7121 Inst = TmpInst;
7122 return true;
7123 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007124 case ARM::t2LDMIA_UPD: {
7125 // If this is a load of a single register, then we should use
7126 // a post-indexed LDR instruction instead, per the ARM ARM.
7127 if (Inst.getNumOperands() != 5)
7128 return false;
7129 MCInst TmpInst;
7130 TmpInst.setOpcode(ARM::t2LDR_POST);
7131 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7132 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7133 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7134 TmpInst.addOperand(MCOperand::CreateImm(4));
7135 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7136 TmpInst.addOperand(Inst.getOperand(3));
7137 Inst = TmpInst;
7138 return true;
7139 }
7140 case ARM::t2STMDB_UPD: {
7141 // If this is a store of a single register, then we should use
7142 // a pre-indexed STR instruction instead, per the ARM ARM.
7143 if (Inst.getNumOperands() != 5)
7144 return false;
7145 MCInst TmpInst;
7146 TmpInst.setOpcode(ARM::t2STR_PRE);
7147 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7148 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7149 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7150 TmpInst.addOperand(MCOperand::CreateImm(-4));
7151 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7152 TmpInst.addOperand(Inst.getOperand(3));
7153 Inst = TmpInst;
7154 return true;
7155 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007156 case ARM::LDMIA_UPD:
7157 // If this is a load of a single register via a 'pop', then we should use
7158 // a post-indexed LDR instruction instead, per the ARM ARM.
7159 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7160 Inst.getNumOperands() == 5) {
7161 MCInst TmpInst;
7162 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7163 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7164 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7165 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7166 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7167 TmpInst.addOperand(MCOperand::CreateImm(4));
7168 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7169 TmpInst.addOperand(Inst.getOperand(3));
7170 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007171 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007172 }
7173 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007174 case ARM::STMDB_UPD:
7175 // If this is a store of a single register via a 'push', then we should use
7176 // a pre-indexed STR instruction instead, per the ARM ARM.
7177 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7178 Inst.getNumOperands() == 5) {
7179 MCInst TmpInst;
7180 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7181 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7182 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7183 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7184 TmpInst.addOperand(MCOperand::CreateImm(-4));
7185 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7186 TmpInst.addOperand(Inst.getOperand(3));
7187 Inst = TmpInst;
7188 }
7189 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007190 case ARM::t2ADDri12:
7191 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7192 // mnemonic was used (not "addw"), encoding T3 is preferred.
7193 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7194 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7195 break;
7196 Inst.setOpcode(ARM::t2ADDri);
7197 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7198 break;
7199 case ARM::t2SUBri12:
7200 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7201 // mnemonic was used (not "subw"), encoding T3 is preferred.
7202 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7203 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7204 break;
7205 Inst.setOpcode(ARM::t2SUBri);
7206 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7207 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007208 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007209 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007210 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7211 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7212 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007213 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007214 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007215 return true;
7216 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007217 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007218 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007219 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007220 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7221 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7222 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007223 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007224 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007225 return true;
7226 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007227 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007228 case ARM::t2ADDri:
7229 case ARM::t2SUBri: {
7230 // If the destination and first source operand are the same, and
7231 // the flags are compatible with the current IT status, use encoding T2
7232 // instead of T3. For compatibility with the system 'as'. Make sure the
7233 // wide encoding wasn't explicit.
7234 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007235 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007236 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7237 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7238 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7239 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7240 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7241 break;
7242 MCInst TmpInst;
7243 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7244 ARM::tADDi8 : ARM::tSUBi8);
7245 TmpInst.addOperand(Inst.getOperand(0));
7246 TmpInst.addOperand(Inst.getOperand(5));
7247 TmpInst.addOperand(Inst.getOperand(0));
7248 TmpInst.addOperand(Inst.getOperand(2));
7249 TmpInst.addOperand(Inst.getOperand(3));
7250 TmpInst.addOperand(Inst.getOperand(4));
7251 Inst = TmpInst;
7252 return true;
7253 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007254 case ARM::t2ADDrr: {
7255 // If the destination and first source operand are the same, and
7256 // there's no setting of the flags, use encoding T2 instead of T3.
7257 // Note that this is only for ADD, not SUB. This mirrors the system
7258 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7259 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7260 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007261 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7262 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007263 break;
7264 MCInst TmpInst;
7265 TmpInst.setOpcode(ARM::tADDhirr);
7266 TmpInst.addOperand(Inst.getOperand(0));
7267 TmpInst.addOperand(Inst.getOperand(0));
7268 TmpInst.addOperand(Inst.getOperand(2));
7269 TmpInst.addOperand(Inst.getOperand(3));
7270 TmpInst.addOperand(Inst.getOperand(4));
7271 Inst = TmpInst;
7272 return true;
7273 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007274 case ARM::tADDrSP: {
7275 // If the non-SP source operand and the destination operand are not the
7276 // same, we need to use the 32-bit encoding if it's available.
7277 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7278 Inst.setOpcode(ARM::t2ADDrr);
7279 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7280 return true;
7281 }
7282 break;
7283 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007284 case ARM::tB:
7285 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007286 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007287 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007288 return true;
7289 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007290 break;
7291 case ARM::t2B:
7292 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007293 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007294 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007295 return true;
7296 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007297 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007298 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007299 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007300 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007301 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007302 return true;
7303 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007304 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007305 case ARM::tBcc:
7306 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007307 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007308 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007309 return true;
7310 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007311 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007312 case ARM::tLDMIA: {
7313 // If the register list contains any high registers, or if the writeback
7314 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7315 // instead if we're in Thumb2. Otherwise, this should have generated
7316 // an error in validateInstruction().
7317 unsigned Rn = Inst.getOperand(0).getReg();
7318 bool hasWritebackToken =
7319 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7320 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7321 bool listContainsBase;
7322 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7323 (!listContainsBase && !hasWritebackToken) ||
7324 (listContainsBase && hasWritebackToken)) {
7325 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7326 assert (isThumbTwo());
7327 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7328 // If we're switching to the updating version, we need to insert
7329 // the writeback tied operand.
7330 if (hasWritebackToken)
7331 Inst.insert(Inst.begin(),
7332 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007333 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007334 }
7335 break;
7336 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007337 case ARM::tSTMIA_UPD: {
7338 // If the register list contains any high registers, we need to use
7339 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7340 // should have generated an error in validateInstruction().
7341 unsigned Rn = Inst.getOperand(0).getReg();
7342 bool listContainsBase;
7343 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7344 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7345 assert (isThumbTwo());
7346 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007347 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007348 }
7349 break;
7350 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007351 case ARM::tPOP: {
7352 bool listContainsBase;
7353 // If the register list contains any high registers, we need to use
7354 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7355 // should have generated an error in validateInstruction().
7356 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007357 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007358 assert (isThumbTwo());
7359 Inst.setOpcode(ARM::t2LDMIA_UPD);
7360 // Add the base register and writeback operands.
7361 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7362 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007363 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007364 }
7365 case ARM::tPUSH: {
7366 bool listContainsBase;
7367 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007368 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007369 assert (isThumbTwo());
7370 Inst.setOpcode(ARM::t2STMDB_UPD);
7371 // Add the base register and writeback operands.
7372 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7373 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007374 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007375 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007376 case ARM::t2MOVi: {
7377 // If we can use the 16-bit encoding and the user didn't explicitly
7378 // request the 32-bit variant, transform it here.
7379 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007380 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007381 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7382 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7383 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007384 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7385 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7386 // The operands aren't in the same order for tMOVi8...
7387 MCInst TmpInst;
7388 TmpInst.setOpcode(ARM::tMOVi8);
7389 TmpInst.addOperand(Inst.getOperand(0));
7390 TmpInst.addOperand(Inst.getOperand(4));
7391 TmpInst.addOperand(Inst.getOperand(1));
7392 TmpInst.addOperand(Inst.getOperand(2));
7393 TmpInst.addOperand(Inst.getOperand(3));
7394 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007395 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007396 }
7397 break;
7398 }
7399 case ARM::t2MOVr: {
7400 // If we can use the 16-bit encoding and the user didn't explicitly
7401 // request the 32-bit variant, transform it here.
7402 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7403 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7404 Inst.getOperand(2).getImm() == ARMCC::AL &&
7405 Inst.getOperand(4).getReg() == ARM::CPSR &&
7406 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7407 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7408 // The operands aren't the same for tMOV[S]r... (no cc_out)
7409 MCInst TmpInst;
7410 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7411 TmpInst.addOperand(Inst.getOperand(0));
7412 TmpInst.addOperand(Inst.getOperand(1));
7413 TmpInst.addOperand(Inst.getOperand(2));
7414 TmpInst.addOperand(Inst.getOperand(3));
7415 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007416 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007417 }
7418 break;
7419 }
Jim Grosbach82213192011-09-19 20:29:33 +00007420 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007421 case ARM::t2SXTB:
7422 case ARM::t2UXTH:
7423 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007424 // If we can use the 16-bit encoding and the user didn't explicitly
7425 // request the 32-bit variant, transform it here.
7426 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7427 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7428 Inst.getOperand(2).getImm() == 0 &&
7429 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7430 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007431 unsigned NewOpc;
7432 switch (Inst.getOpcode()) {
7433 default: llvm_unreachable("Illegal opcode!");
7434 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7435 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7436 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7437 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7438 }
Jim Grosbach82213192011-09-19 20:29:33 +00007439 // The operands aren't the same for thumb1 (no rotate operand).
7440 MCInst TmpInst;
7441 TmpInst.setOpcode(NewOpc);
7442 TmpInst.addOperand(Inst.getOperand(0));
7443 TmpInst.addOperand(Inst.getOperand(1));
7444 TmpInst.addOperand(Inst.getOperand(3));
7445 TmpInst.addOperand(Inst.getOperand(4));
7446 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007447 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007448 }
7449 break;
7450 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007451 case ARM::MOVsi: {
7452 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007453 // rrx shifts and asr/lsr of #32 is encoded as 0
7454 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7455 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007456 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7457 // Shifting by zero is accepted as a vanilla 'MOVr'
7458 MCInst TmpInst;
7459 TmpInst.setOpcode(ARM::MOVr);
7460 TmpInst.addOperand(Inst.getOperand(0));
7461 TmpInst.addOperand(Inst.getOperand(1));
7462 TmpInst.addOperand(Inst.getOperand(3));
7463 TmpInst.addOperand(Inst.getOperand(4));
7464 TmpInst.addOperand(Inst.getOperand(5));
7465 Inst = TmpInst;
7466 return true;
7467 }
7468 return false;
7469 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007470 case ARM::ANDrsi:
7471 case ARM::ORRrsi:
7472 case ARM::EORrsi:
7473 case ARM::BICrsi:
7474 case ARM::SUBrsi:
7475 case ARM::ADDrsi: {
7476 unsigned newOpc;
7477 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7478 if (SOpc == ARM_AM::rrx) return false;
7479 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007480 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007481 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7482 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7483 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7484 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7485 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7486 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7487 }
7488 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007489 // The exception is for right shifts, where 0 == 32
7490 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7491 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007492 MCInst TmpInst;
7493 TmpInst.setOpcode(newOpc);
7494 TmpInst.addOperand(Inst.getOperand(0));
7495 TmpInst.addOperand(Inst.getOperand(1));
7496 TmpInst.addOperand(Inst.getOperand(2));
7497 TmpInst.addOperand(Inst.getOperand(4));
7498 TmpInst.addOperand(Inst.getOperand(5));
7499 TmpInst.addOperand(Inst.getOperand(6));
7500 Inst = TmpInst;
7501 return true;
7502 }
7503 return false;
7504 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007505 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007506 case ARM::t2IT: {
7507 // The mask bits for all but the first condition are represented as
7508 // the low bit of the condition code value implies 't'. We currently
7509 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007510 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007511 MCOperand &MO = Inst.getOperand(1);
7512 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007513 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007514 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007515 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007516 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007517 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007518 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007519 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007520
7521 // Set up the IT block state according to the IT instruction we just
7522 // matched.
7523 assert(!inITBlock() && "nested IT blocks?!");
7524 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7525 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7526 ITState.CurPosition = 0;
7527 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007528 break;
7529 }
Richard Bartona39625e2012-07-09 16:12:24 +00007530 case ARM::t2LSLrr:
7531 case ARM::t2LSRrr:
7532 case ARM::t2ASRrr:
7533 case ARM::t2SBCrr:
7534 case ARM::t2RORrr:
7535 case ARM::t2BICrr:
7536 {
Richard Bartond5660372012-07-09 16:14:28 +00007537 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007538 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7539 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7540 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007541 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7542 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007543 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7544 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7545 unsigned NewOpc;
7546 switch (Inst.getOpcode()) {
7547 default: llvm_unreachable("unexpected opcode");
7548 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7549 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7550 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7551 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7552 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7553 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7554 }
7555 MCInst TmpInst;
7556 TmpInst.setOpcode(NewOpc);
7557 TmpInst.addOperand(Inst.getOperand(0));
7558 TmpInst.addOperand(Inst.getOperand(5));
7559 TmpInst.addOperand(Inst.getOperand(1));
7560 TmpInst.addOperand(Inst.getOperand(2));
7561 TmpInst.addOperand(Inst.getOperand(3));
7562 TmpInst.addOperand(Inst.getOperand(4));
7563 Inst = TmpInst;
7564 return true;
7565 }
7566 return false;
7567 }
7568 case ARM::t2ANDrr:
7569 case ARM::t2EORrr:
7570 case ARM::t2ADCrr:
7571 case ARM::t2ORRrr:
7572 {
Richard Bartond5660372012-07-09 16:14:28 +00007573 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007574 // These instructions are special in that they are commutable, so shorter encodings
7575 // are available more often.
7576 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7577 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7578 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7579 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007580 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7581 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007582 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7583 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7584 unsigned NewOpc;
7585 switch (Inst.getOpcode()) {
7586 default: llvm_unreachable("unexpected opcode");
7587 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7588 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7589 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7590 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7591 }
7592 MCInst TmpInst;
7593 TmpInst.setOpcode(NewOpc);
7594 TmpInst.addOperand(Inst.getOperand(0));
7595 TmpInst.addOperand(Inst.getOperand(5));
7596 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7597 TmpInst.addOperand(Inst.getOperand(1));
7598 TmpInst.addOperand(Inst.getOperand(2));
7599 } else {
7600 TmpInst.addOperand(Inst.getOperand(2));
7601 TmpInst.addOperand(Inst.getOperand(1));
7602 }
7603 TmpInst.addOperand(Inst.getOperand(3));
7604 TmpInst.addOperand(Inst.getOperand(4));
7605 Inst = TmpInst;
7606 return true;
7607 }
7608 return false;
7609 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007610 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007611 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007612}
7613
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007614unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7615 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7616 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007617 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007618 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007619 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7620 assert(MCID.hasOptionalDef() &&
7621 "optionally flag setting instruction missing optional def operand");
7622 assert(MCID.NumOperands == Inst.getNumOperands() &&
7623 "operand count mismatch!");
7624 // Find the optional-def operand (cc_out).
7625 unsigned OpNo;
7626 for (OpNo = 0;
7627 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7628 ++OpNo)
7629 ;
7630 // If we're parsing Thumb1, reject it completely.
7631 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7632 return Match_MnemonicFail;
7633 // If we're parsing Thumb2, which form is legal depends on whether we're
7634 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007635 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7636 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007637 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007638 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7639 inITBlock())
7640 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007641 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007642 // Some high-register supporting Thumb1 encodings only allow both registers
7643 // to be from r0-r7 when in Thumb2.
7644 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7645 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7646 isARMLowRegister(Inst.getOperand(2).getReg()))
7647 return Match_RequiresThumb2;
7648 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007649 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007650 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7651 isARMLowRegister(Inst.getOperand(1).getReg()))
7652 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007653 return Match_Success;
7654}
7655
Jim Grosbach5117ef72012-04-24 22:40:08 +00007656static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007657bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007658MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007659 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007660 MCStreamer &Out, unsigned &ErrorInfo,
7661 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007662 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007663 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007664
Chad Rosier2f480a82012-10-12 22:53:36 +00007665 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007666 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007667 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007668 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007669 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007670 // Context sensitive operand constraints aren't handled by the matcher,
7671 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007672 if (validateInstruction(Inst, Operands)) {
7673 // Still progress the IT block, otherwise one wrong condition causes
7674 // nasty cascading errors.
7675 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007676 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007677 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007678
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007679 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007680 // encoding is selected. Loop on it while changes happen so the
7681 // individual transformations can chain off each other. E.g.,
7682 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7683 while (processInstruction(Inst, Operands))
7684 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007685
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007686 // Only move forward at the very end so that everything in validate
7687 // and process gets a consistent answer about whether we're in an IT
7688 // block.
7689 forwardITPosition();
7690
Jim Grosbach82f76d12012-01-25 19:52:01 +00007691 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7692 // doesn't actually encode.
7693 if (Inst.getOpcode() == ARM::ITasm)
7694 return false;
7695
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007696 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007697 Out.EmitInstruction(Inst);
7698 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007699 case Match_MissingFeature: {
7700 assert(ErrorInfo && "Unknown missing feature!");
7701 // Special case the error message for the very common case where only
7702 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7703 std::string Msg = "instruction requires:";
7704 unsigned Mask = 1;
7705 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7706 if (ErrorInfo & Mask) {
7707 Msg += " ";
7708 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7709 }
7710 Mask <<= 1;
7711 }
7712 return Error(IDLoc, Msg);
7713 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007714 case Match_InvalidOperand: {
7715 SMLoc ErrorLoc = IDLoc;
7716 if (ErrorInfo != ~0U) {
7717 if (ErrorInfo >= Operands.size())
7718 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007719
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007720 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7721 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7722 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007723
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007724 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007725 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007726 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007727 return Error(IDLoc, "invalid instruction",
7728 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007729 case Match_RequiresNotITBlock:
7730 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007731 case Match_RequiresITBlock:
7732 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007733 case Match_RequiresV6:
7734 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7735 case Match_RequiresThumb2:
7736 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007737 case Match_ImmRange0_4: {
7738 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7739 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7740 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7741 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007742 case Match_ImmRange0_15: {
7743 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7744 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7745 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7746 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007747 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007748
Eric Christopher91d7b902010-10-29 09:26:59 +00007749 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007750}
7751
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007752/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007753bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7754 StringRef IDVal = DirectiveID.getIdentifier();
7755 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007756 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007757 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007758 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007759 else if (IDVal == ".arm")
7760 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007761 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007762 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007763 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007764 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007765 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007766 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007767 else if (IDVal == ".unreq")
7768 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007769 else if (IDVal == ".arch")
7770 return parseDirectiveArch(DirectiveID.getLoc());
7771 else if (IDVal == ".eabi_attribute")
7772 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007773 else if (IDVal == ".fnstart")
7774 return parseDirectiveFnStart(DirectiveID.getLoc());
7775 else if (IDVal == ".fnend")
7776 return parseDirectiveFnEnd(DirectiveID.getLoc());
7777 else if (IDVal == ".cantunwind")
7778 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7779 else if (IDVal == ".personality")
7780 return parseDirectivePersonality(DirectiveID.getLoc());
7781 else if (IDVal == ".handlerdata")
7782 return parseDirectiveHandlerData(DirectiveID.getLoc());
7783 else if (IDVal == ".setfp")
7784 return parseDirectiveSetFP(DirectiveID.getLoc());
7785 else if (IDVal == ".pad")
7786 return parseDirectivePad(DirectiveID.getLoc());
7787 else if (IDVal == ".save")
7788 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7789 else if (IDVal == ".vsave")
7790 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007791 return true;
7792}
7793
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007794/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007795/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007796bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007797 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7798 for (;;) {
7799 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007800 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007801 return true;
7802
Eric Christopherbf7bc492013-01-09 03:52:05 +00007803 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007804
7805 if (getLexer().is(AsmToken::EndOfStatement))
7806 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007807
Kevin Enderbyccab3172009-09-15 00:27:25 +00007808 // FIXME: Improve diagnostic.
7809 if (getLexer().isNot(AsmToken::Comma))
7810 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007811 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007812 }
7813 }
7814
Sean Callanana83fd7d2010-01-19 20:27:46 +00007815 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007816 return false;
7817}
7818
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007819/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007820/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007821bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007822 if (getLexer().isNot(AsmToken::EndOfStatement))
7823 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007824 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007825
Tim Northovera2292d02013-06-10 23:20:58 +00007826 if (!hasThumb())
7827 return Error(L, "target does not support Thumb mode");
7828
Jim Grosbach7f882392011-12-07 18:04:19 +00007829 if (!isThumb())
7830 SwitchMode();
7831 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7832 return false;
7833}
7834
7835/// parseDirectiveARM
7836/// ::= .arm
7837bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7838 if (getLexer().isNot(AsmToken::EndOfStatement))
7839 return Error(L, "unexpected token in directive");
7840 Parser.Lex();
7841
Tim Northovera2292d02013-06-10 23:20:58 +00007842 if (!hasARM())
7843 return Error(L, "target does not support ARM mode");
7844
Jim Grosbach7f882392011-12-07 18:04:19 +00007845 if (isThumb())
7846 SwitchMode();
7847 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007848 return false;
7849}
7850
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007851/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007852/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007853bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007854 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7855 bool isMachO = MAI.hasSubsectionsViaSymbols();
7856 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007857 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007858
Jim Grosbach1152cc02011-12-21 22:30:16 +00007859 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007860 // ELF doesn't
7861 if (isMachO) {
7862 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007863 if (Tok.isNot(AsmToken::EndOfStatement)) {
7864 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7865 return Error(L, "unexpected token in .thumb_func directive");
7866 Name = Tok.getIdentifier();
7867 Parser.Lex(); // Consume the identifier token.
7868 needFuncName = false;
7869 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007870 }
7871
Jim Grosbach1152cc02011-12-21 22:30:16 +00007872 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007873 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007874
7875 // Eat the end of statement and any blank lines that follow.
7876 while (getLexer().is(AsmToken::EndOfStatement))
7877 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007878
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007879 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007880 // We really should be checking the next symbol definition even if there's
7881 // stuff in between.
7882 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007883 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007884 }
7885
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007886 // Mark symbol as a thumb symbol.
7887 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7888 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007889 return false;
7890}
7891
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007892/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007893/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007894bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007895 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007896 if (Tok.isNot(AsmToken::Identifier))
7897 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007898 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007899 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007900 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007901 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007902 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007903 else
7904 return Error(L, "unrecognized syntax mode in .syntax directive");
7905
7906 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007907 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007908 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007909
7910 // TODO tell the MC streamer the mode
7911 // getParser().getStreamer().Emit???();
7912 return false;
7913}
7914
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007915/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007916/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007917bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007918 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007919 if (Tok.isNot(AsmToken::Integer))
7920 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007921 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007922 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007923 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007924 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007925 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007926 else
7927 return Error(L, "invalid operand to .code directive");
7928
7929 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007930 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007931 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007932
Evan Cheng284b4672011-07-08 22:36:29 +00007933 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007934 if (!hasThumb())
7935 return Error(L, "target does not support Thumb mode");
7936
Jim Grosbachf471ac32011-09-06 18:46:23 +00007937 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007938 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007939 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007940 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007941 if (!hasARM())
7942 return Error(L, "target does not support ARM mode");
7943
Jim Grosbachf471ac32011-09-06 18:46:23 +00007944 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007945 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007946 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007947 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007948
Kevin Enderby146dcf22009-10-15 20:48:48 +00007949 return false;
7950}
7951
Jim Grosbachab5830e2011-12-14 02:16:11 +00007952/// parseDirectiveReq
7953/// ::= name .req registername
7954bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7955 Parser.Lex(); // Eat the '.req' token.
7956 unsigned Reg;
7957 SMLoc SRegLoc, ERegLoc;
7958 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007959 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007960 return Error(SRegLoc, "register name expected");
7961 }
7962
7963 // Shouldn't be anything else.
7964 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007965 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007966 return Error(Parser.getTok().getLoc(),
7967 "unexpected input in .req directive.");
7968 }
7969
7970 Parser.Lex(); // Consume the EndOfStatement
7971
7972 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7973 return Error(SRegLoc, "redefinition of '" + Name +
7974 "' does not match original.");
7975
7976 return false;
7977}
7978
7979/// parseDirectiveUneq
7980/// ::= .unreq registername
7981bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7982 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007983 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007984 return Error(L, "unexpected input in .unreq directive.");
7985 }
7986 RegisterReqs.erase(Parser.getTok().getIdentifier());
7987 Parser.Lex(); // Eat the identifier.
7988 return false;
7989}
7990
Jason W Kim135d2442011-12-20 17:38:12 +00007991/// parseDirectiveArch
7992/// ::= .arch token
7993bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7994 return true;
7995}
7996
7997/// parseDirectiveEabiAttr
7998/// ::= .eabi_attribute int, int
7999bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8000 return true;
8001}
8002
Logan Chien4ea23b52013-05-10 16:17:24 +00008003/// parseDirectiveFnStart
8004/// ::= .fnstart
8005bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8006 if (FnStartLoc.isValid()) {
8007 Error(L, ".fnstart starts before the end of previous one");
8008 Error(FnStartLoc, "previous .fnstart starts here");
8009 return true;
8010 }
8011
8012 FnStartLoc = L;
8013 getParser().getStreamer().EmitFnStart();
8014 return false;
8015}
8016
8017/// parseDirectiveFnEnd
8018/// ::= .fnend
8019bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8020 // Check the ordering of unwind directives
8021 if (!FnStartLoc.isValid())
8022 return Error(L, ".fnstart must precede .fnend directive");
8023
8024 // Reset the unwind directives parser state
8025 resetUnwindDirectiveParserState();
8026
8027 getParser().getStreamer().EmitFnEnd();
8028 return false;
8029}
8030
8031/// parseDirectiveCantUnwind
8032/// ::= .cantunwind
8033bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8034 // Check the ordering of unwind directives
8035 CantUnwindLoc = L;
8036 if (!FnStartLoc.isValid())
8037 return Error(L, ".fnstart must precede .cantunwind directive");
8038 if (HandlerDataLoc.isValid()) {
8039 Error(L, ".cantunwind can't be used with .handlerdata directive");
8040 Error(HandlerDataLoc, ".handlerdata was specified here");
8041 return true;
8042 }
8043 if (PersonalityLoc.isValid()) {
8044 Error(L, ".cantunwind can't be used with .personality directive");
8045 Error(PersonalityLoc, ".personality was specified here");
8046 return true;
8047 }
8048
8049 getParser().getStreamer().EmitCantUnwind();
8050 return false;
8051}
8052
8053/// parseDirectivePersonality
8054/// ::= .personality name
8055bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8056 // Check the ordering of unwind directives
8057 PersonalityLoc = L;
8058 if (!FnStartLoc.isValid())
8059 return Error(L, ".fnstart must precede .personality directive");
8060 if (CantUnwindLoc.isValid()) {
8061 Error(L, ".personality can't be used with .cantunwind directive");
8062 Error(CantUnwindLoc, ".cantunwind was specified here");
8063 return true;
8064 }
8065 if (HandlerDataLoc.isValid()) {
8066 Error(L, ".personality must precede .handlerdata directive");
8067 Error(HandlerDataLoc, ".handlerdata was specified here");
8068 return true;
8069 }
8070
8071 // Parse the name of the personality routine
8072 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8073 Parser.eatToEndOfStatement();
8074 return Error(L, "unexpected input in .personality directive.");
8075 }
8076 StringRef Name(Parser.getTok().getIdentifier());
8077 Parser.Lex();
8078
8079 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8080 getParser().getStreamer().EmitPersonality(PR);
8081 return false;
8082}
8083
8084/// parseDirectiveHandlerData
8085/// ::= .handlerdata
8086bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8087 // Check the ordering of unwind directives
8088 HandlerDataLoc = L;
8089 if (!FnStartLoc.isValid())
8090 return Error(L, ".fnstart must precede .personality directive");
8091 if (CantUnwindLoc.isValid()) {
8092 Error(L, ".handlerdata can't be used with .cantunwind directive");
8093 Error(CantUnwindLoc, ".cantunwind was specified here");
8094 return true;
8095 }
8096
8097 getParser().getStreamer().EmitHandlerData();
8098 return false;
8099}
8100
8101/// parseDirectiveSetFP
8102/// ::= .setfp fpreg, spreg [, offset]
8103bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8104 // Check the ordering of unwind directives
8105 if (!FnStartLoc.isValid())
8106 return Error(L, ".fnstart must precede .setfp directive");
8107 if (HandlerDataLoc.isValid())
8108 return Error(L, ".setfp must precede .handlerdata directive");
8109
8110 // Parse fpreg
8111 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8112 int NewFPReg = tryParseRegister();
8113 if (NewFPReg == -1)
8114 return Error(NewFPRegLoc, "frame pointer register expected");
8115
8116 // Consume comma
8117 if (!Parser.getTok().is(AsmToken::Comma))
8118 return Error(Parser.getTok().getLoc(), "comma expected");
8119 Parser.Lex(); // skip comma
8120
8121 // Parse spreg
8122 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8123 int NewSPReg = tryParseRegister();
8124 if (NewSPReg == -1)
8125 return Error(NewSPRegLoc, "stack pointer register expected");
8126
8127 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8128 return Error(NewSPRegLoc,
8129 "register should be either $sp or the latest fp register");
8130
8131 // Update the frame pointer register
8132 FPReg = NewFPReg;
8133
8134 // Parse offset
8135 int64_t Offset = 0;
8136 if (Parser.getTok().is(AsmToken::Comma)) {
8137 Parser.Lex(); // skip comma
8138
8139 if (Parser.getTok().isNot(AsmToken::Hash) &&
8140 Parser.getTok().isNot(AsmToken::Dollar)) {
8141 return Error(Parser.getTok().getLoc(), "'#' expected");
8142 }
8143 Parser.Lex(); // skip hash token.
8144
8145 const MCExpr *OffsetExpr;
8146 SMLoc ExLoc = Parser.getTok().getLoc();
8147 SMLoc EndLoc;
8148 if (getParser().parseExpression(OffsetExpr, EndLoc))
8149 return Error(ExLoc, "malformed setfp offset");
8150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8151 if (!CE)
8152 return Error(ExLoc, "setfp offset must be an immediate");
8153
8154 Offset = CE->getValue();
8155 }
8156
8157 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8158 static_cast<unsigned>(NewSPReg),
8159 Offset);
8160 return false;
8161}
8162
8163/// parseDirective
8164/// ::= .pad offset
8165bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8166 // Check the ordering of unwind directives
8167 if (!FnStartLoc.isValid())
8168 return Error(L, ".fnstart must precede .pad directive");
8169 if (HandlerDataLoc.isValid())
8170 return Error(L, ".pad must precede .handlerdata directive");
8171
8172 // Parse the offset
8173 if (Parser.getTok().isNot(AsmToken::Hash) &&
8174 Parser.getTok().isNot(AsmToken::Dollar)) {
8175 return Error(Parser.getTok().getLoc(), "'#' expected");
8176 }
8177 Parser.Lex(); // skip hash token.
8178
8179 const MCExpr *OffsetExpr;
8180 SMLoc ExLoc = Parser.getTok().getLoc();
8181 SMLoc EndLoc;
8182 if (getParser().parseExpression(OffsetExpr, EndLoc))
8183 return Error(ExLoc, "malformed pad offset");
8184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8185 if (!CE)
8186 return Error(ExLoc, "pad offset must be an immediate");
8187
8188 getParser().getStreamer().EmitPad(CE->getValue());
8189 return false;
8190}
8191
8192/// parseDirectiveRegSave
8193/// ::= .save { registers }
8194/// ::= .vsave { registers }
8195bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8196 // Check the ordering of unwind directives
8197 if (!FnStartLoc.isValid())
8198 return Error(L, ".fnstart must precede .save or .vsave directives");
8199 if (HandlerDataLoc.isValid())
8200 return Error(L, ".save or .vsave must precede .handlerdata directive");
8201
8202 // Parse the register list
8203 SmallVector<MCParsedAsmOperand*, 1> Operands;
8204 if (parseRegisterList(Operands))
8205 return true;
8206 ARMOperand *Op = (ARMOperand*)Operands[0];
8207 if (!IsVector && !Op->isRegList())
8208 return Error(L, ".save expects GPR registers");
8209 if (IsVector && !Op->isDPRRegList())
8210 return Error(L, ".vsave expects DPR registers");
8211
8212 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8213 return false;
8214}
8215
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008216/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008217extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008218 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8219 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008220}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008221
Chris Lattner3e4582a2010-09-06 19:11:01 +00008222#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008223#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008224#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008225#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008226
8227// Define this matcher function after the auto-generated include so we
8228// have the match class enum definitions.
8229unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8230 unsigned Kind) {
8231 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8232 // If the kind is a token for a literal immediate, check if our asm
8233 // operand matches. This is for InstAliases which have a fixed-value
8234 // immediate in the syntax.
8235 if (Kind == MCK__35_0 && Op->isImm()) {
8236 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8237 if (!CE)
8238 return Match_InvalidOperand;
8239 if (CE->getValue() == 0)
8240 return Match_Success;
8241 }
8242 return Match_InvalidOperand;
8243}