blob: bd4ea535567809cad99515723a205f4a454264b1 [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 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
166 }
Tim Northovera2292d02013-06-10 23:20:58 +0000167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
169 }
170
Evan Cheng284b4672011-07-08 22:36:29 +0000171 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000174 }
James Molloy21efa7d2011-09-28 14:21:38 +0000175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
177 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000178
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000179 /// @name Auto-generated Match Functions
180 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000181
Chris Lattner3e4582a2010-09-06 19:11:01 +0000182#define GET_ASSEMBLER_HEADER
183#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000184
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000185 /// }
186
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000194 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000195 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000198 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
206 }
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
209 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
219 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000220
221 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
223 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
224 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000226 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000228 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000229 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000230 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000231 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000232 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000233 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000234 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000235 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000236 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000237 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000238 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000239 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000240 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000241 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000242 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000243 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000244 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000245 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000246 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
247 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
248 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000249 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000250 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000251 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000252 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000253 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000254 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000255 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000256 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000257 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000258 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000259 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000260 bool validateInstruction(MCInst &Inst,
261 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000262 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000263 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000264 bool shouldOmitCCOutOperand(StringRef Mnemonic,
265 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000266
Kevin Enderbyccab3172009-09-15 00:27:25 +0000267public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000268 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000269 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000270 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000271 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000272 Match_RequiresThumb2,
273#define GET_OPERAND_DIAGNOSTIC_TYPES
274#include "ARMGenAsmMatcher.inc"
275
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000276 };
277
Evan Cheng91111d22011-07-09 05:47:46 +0000278 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000279 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000280 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000281
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000282 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000283 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000284
Evan Cheng4d1ca962011-07-08 01:53:10 +0000285 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000286 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000287
288 // Not in an ITBlock to start with.
289 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000290
291 // Set ELF header flags.
292 // FIXME: This should eventually end up somewhere else where more
293 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000294 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
295 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
296 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000297 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000298
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000299 // Implementation of the MCTargetAsmParser interface:
300 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000301 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
302 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000303 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000304 bool ParseDirective(AsmToken DirectiveID);
305
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000306 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000307 unsigned checkTargetMatchPredicate(MCInst &Inst);
308
Chad Rosier49963552012-10-13 00:26:04 +0000309 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000310 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000311 MCStreamer &Out, unsigned &ErrorInfo,
312 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000313};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000314} // end anonymous namespace
315
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000316namespace {
317
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000318/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000319/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000320class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000321 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000322 k_CondCode,
323 k_CCOut,
324 k_ITCondMask,
325 k_CoprocNum,
326 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000327 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000328 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000329 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000330 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000331 k_Memory,
332 k_PostIndexRegister,
333 k_MSRMask,
334 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000335 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000336 k_Register,
337 k_RegisterList,
338 k_DPRRegisterList,
339 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000340 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000341 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000342 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000343 k_ShiftedRegister,
344 k_ShiftedImmediate,
345 k_ShifterImmediate,
346 k_RotateImmediate,
347 k_BitfieldDescriptor,
348 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000349 } Kind;
350
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000351 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000352 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000353
Eric Christopher8996c5d2013-03-15 00:42:55 +0000354 struct CCOp {
355 ARMCC::CondCodes Val;
356 };
357
358 struct CopOp {
359 unsigned Val;
360 };
361
362 struct CoprocOptionOp {
363 unsigned Val;
364 };
365
366 struct ITMaskOp {
367 unsigned Mask:4;
368 };
369
370 struct MBOptOp {
371 ARM_MB::MemBOpt Val;
372 };
373
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000374 struct ISBOptOp {
375 ARM_ISB::InstSyncBOpt Val;
376 };
377
Eric Christopher8996c5d2013-03-15 00:42:55 +0000378 struct IFlagsOp {
379 ARM_PROC::IFlags Val;
380 };
381
382 struct MMaskOp {
383 unsigned Val;
384 };
385
386 struct TokOp {
387 const char *Data;
388 unsigned Length;
389 };
390
391 struct RegOp {
392 unsigned RegNum;
393 };
394
395 // A vector register list is a sequential list of 1 to 4 registers.
396 struct VectorListOp {
397 unsigned RegNum;
398 unsigned Count;
399 unsigned LaneIndex;
400 bool isDoubleSpaced;
401 };
402
403 struct VectorIndexOp {
404 unsigned Val;
405 };
406
407 struct ImmOp {
408 const MCExpr *Val;
409 };
410
411 /// Combined record for all forms of ARM address expressions.
412 struct MemoryOp {
413 unsigned BaseRegNum;
414 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
415 // was specified.
416 const MCConstantExpr *OffsetImm; // Offset immediate value
417 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
418 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
419 unsigned ShiftImm; // shift for OffsetReg.
420 unsigned Alignment; // 0 = no alignment specified
421 // n = alignment in bytes (2, 4, 8, 16, or 32)
422 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
423 };
424
425 struct PostIdxRegOp {
426 unsigned RegNum;
427 bool isAdd;
428 ARM_AM::ShiftOpc ShiftTy;
429 unsigned ShiftImm;
430 };
431
432 struct ShifterImmOp {
433 bool isASR;
434 unsigned Imm;
435 };
436
437 struct RegShiftedRegOp {
438 ARM_AM::ShiftOpc ShiftTy;
439 unsigned SrcReg;
440 unsigned ShiftReg;
441 unsigned ShiftImm;
442 };
443
444 struct RegShiftedImmOp {
445 ARM_AM::ShiftOpc ShiftTy;
446 unsigned SrcReg;
447 unsigned ShiftImm;
448 };
449
450 struct RotImmOp {
451 unsigned Imm;
452 };
453
454 struct BitfieldOp {
455 unsigned LSB;
456 unsigned Width;
457 };
458
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000459 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000460 struct CCOp CC;
461 struct CopOp Cop;
462 struct CoprocOptionOp CoprocOption;
463 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000464 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000465 struct ITMaskOp ITMask;
466 struct IFlagsOp IFlags;
467 struct MMaskOp MMask;
468 struct TokOp Tok;
469 struct RegOp Reg;
470 struct VectorListOp VectorList;
471 struct VectorIndexOp VectorIndex;
472 struct ImmOp Imm;
473 struct MemoryOp Memory;
474 struct PostIdxRegOp PostIdxReg;
475 struct ShifterImmOp ShifterImm;
476 struct RegShiftedRegOp RegShiftedReg;
477 struct RegShiftedImmOp RegShiftedImm;
478 struct RotImmOp RotImm;
479 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000480 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000481
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000482 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
483public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000484 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
485 Kind = o.Kind;
486 StartLoc = o.StartLoc;
487 EndLoc = o.EndLoc;
488 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000490 CC = o.CC;
491 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000492 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000493 ITMask = o.ITMask;
494 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000495 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000496 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000497 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000498 case k_CCOut:
499 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000500 Reg = o.Reg;
501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_RegisterList:
503 case k_DPRRegisterList:
504 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000505 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000506 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000507 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000508 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000509 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000510 VectorList = o.VectorList;
511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 case k_CoprocNum:
513 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000514 Cop = o.Cop;
515 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000516 case k_CoprocOption:
517 CoprocOption = o.CoprocOption;
518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000519 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000520 Imm = o.Imm;
521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000522 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000523 MBOpt = o.MBOpt;
524 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000525 case k_InstSyncBarrierOpt:
526 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000527 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000528 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000530 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000531 PostIdxReg = o.PostIdxReg;
532 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000533 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000534 MMask = o.MMask;
535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000536 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000537 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000540 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000541 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000542 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000543 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000544 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000546 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000547 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000548 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000549 RotImm = o.RotImm;
550 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000552 Bitfield = o.Bitfield;
553 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000554 case k_VectorIndex:
555 VectorIndex = o.VectorIndex;
556 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000557 }
558 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000559
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000560 /// getStartLoc - Get the location of the first token of this operand.
561 SMLoc getStartLoc() const { return StartLoc; }
562 /// getEndLoc - Get the location of the last token of this operand.
563 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000564 /// getLocRange - Get the range between the first and last token of this
565 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000566 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
567
Daniel Dunbard8042b72010-08-11 06:36:53 +0000568 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000569 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000570 return CC.Val;
571 }
572
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000573 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000575 return Cop.Val;
576 }
577
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000578 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000579 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000580 return StringRef(Tok.Data, Tok.Length);
581 }
582
583 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000584 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000585 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000586 }
587
Bill Wendlingbed94652010-11-09 23:28:44 +0000588 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
590 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000591 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000592 }
593
Kevin Enderbyf5079942009-10-13 22:19:02 +0000594 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000595 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000596 return Imm.Val;
597 }
598
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000599 unsigned getVectorIndex() const {
600 assert(Kind == k_VectorIndex && "Invalid access!");
601 return VectorIndex.Val;
602 }
603
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000604 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000605 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000606 return MBOpt.Val;
607 }
608
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000609 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
610 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
611 return ISBOpt.Val;
612 }
613
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000614 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000615 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000616 return IFlags.Val;
617 }
618
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000619 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000620 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000621 return MMask.Val;
622 }
623
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000624 bool isCoprocNum() const { return Kind == k_CoprocNum; }
625 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000626 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000627 bool isCondCode() const { return Kind == k_CondCode; }
628 bool isCCOut() const { return Kind == k_CCOut; }
629 bool isITMask() const { return Kind == k_ITCondMask; }
630 bool isITCondCode() const { return Kind == k_CondCode; }
631 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000632 // checks whether this operand is an unsigned offset which fits is a field
633 // of specified width and scaled by a specific number of bits
634 template<unsigned width, unsigned scale>
635 bool isUnsignedOffset() const {
636 if (!isImm()) return false;
637 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
638 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
639 int64_t Val = CE->getValue();
640 int64_t Align = 1LL << scale;
641 int64_t Max = Align * ((1LL << width) - 1);
642 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
643 }
644 return false;
645 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000646 bool isFPImm() const {
647 if (!isImm()) return false;
648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
651 return Val != -1;
652 }
Jim Grosbachea231912011-12-22 22:19:05 +0000653 bool isFBits16() const {
654 if (!isImm()) return false;
655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return Value >= 0 && Value <= 16;
659 }
660 bool isFBits32() const {
661 if (!isImm()) return false;
662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value >= 1 && Value <= 32;
666 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000667 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000668 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
672 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
673 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000674 bool isImm0_4() const {
675 if (!isImm()) return false;
676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return Value >= 0 && Value < 5;
680 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000681 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000682 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = CE->getValue();
686 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
687 }
688 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000689 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
691 if (!CE) return false;
692 int64_t Value = CE->getValue();
693 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
694 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000695 bool isImm0_508s4Neg() const {
696 if (!isImm()) return false;
697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
698 if (!CE) return false;
699 int64_t Value = -CE->getValue();
700 // explicitly exclude zero. we want that to use the normal 0_508 version.
701 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
702 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000703 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000704 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = CE->getValue();
708 return Value >= 0 && Value < 256;
709 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000710 bool isImm0_4095() const {
711 if (!isImm()) return false;
712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value >= 0 && Value < 4096;
716 }
717 bool isImm0_4095Neg() const {
718 if (!isImm()) return false;
719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = -CE->getValue();
722 return Value > 0 && Value < 4096;
723 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000724 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000725 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value >= 0 && Value < 2;
730 }
731 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000732 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 4;
737 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000738 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value >= 0 && Value < 8;
744 }
745 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 16;
751 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000752 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value >= 0 && Value < 32;
758 }
Jim Grosbach00326402011-12-08 01:30:04 +0000759 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 if (!CE) return false;
763 int64_t Value = CE->getValue();
764 return Value >= 0 && Value < 64;
765 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000766 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000767 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return Value == 8;
772 }
773 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value == 16;
779 }
780 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value == 32;
786 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000787 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000788 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value > 0 && Value <= 8;
793 }
794 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000795 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value > 0 && Value <= 16;
800 }
801 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value > 0 && Value <= 32;
807 }
808 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value > 0 && Value <= 64;
814 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000815 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000816 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return Value > 0 && Value < 8;
821 }
822 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000823 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value > 0 && Value < 16;
828 }
829 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000830 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value > 0 && Value < 32;
835 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000836 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value > 0 && Value < 17;
842 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000843 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value > 0 && Value < 33;
849 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000850 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value >= 0 && Value < 33;
856 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000857 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 65536;
863 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000864 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000865 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 // If it's not a constant expression, it'll generate a fixup and be
868 // handled later.
869 if (!CE) return true;
870 int64_t Value = CE->getValue();
871 return Value >= 0 && Value < 65536;
872 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000873 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000874 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value <= 0xffffff;
879 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000880 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value > 0 && Value < 33;
886 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000887 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000888 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 if (!CE) return false;
891 int64_t Value = CE->getValue();
892 return Value >= 0 && Value < 32;
893 }
894 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000895 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return Value > 0 && Value <= 32;
900 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000901 bool isAdrLabel() const {
902 // If we have an immediate that's not a constant, treat it as a label
903 // reference needing a fixup. If it is a constant, but it can't fit
904 // into shift immediate encoding, we reject it.
905 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
906 else return (isARMSOImm() || isARMSOImmNeg());
907 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000908 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000909 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
911 if (!CE) return false;
912 int64_t Value = CE->getValue();
913 return ARM_AM::getSOImmVal(Value) != -1;
914 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000915 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
918 if (!CE) return false;
919 int64_t Value = CE->getValue();
920 return ARM_AM::getSOImmVal(~Value) != -1;
921 }
Jim Grosbach30506252011-12-08 00:31:07 +0000922 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000923 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
925 if (!CE) return false;
926 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000927 // Only use this when not representable as a plain so_imm.
928 return ARM_AM::getSOImmVal(Value) == -1 &&
929 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000930 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000931 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000932 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
936 return ARM_AM::getT2SOImmVal(Value) != -1;
937 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000938 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000939 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return ARM_AM::getT2SOImmVal(~Value) != -1;
944 }
Jim Grosbach30506252011-12-08 00:31:07 +0000945 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000946 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000950 // Only use this when not representable as a plain so_imm.
951 return ARM_AM::getT2SOImmVal(Value) == -1 &&
952 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000953 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000954 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000955 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
959 return Value == 1 || Value == 0;
960 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000961 bool isReg() const { return Kind == k_Register; }
962 bool isRegList() const { return Kind == k_RegisterList; }
963 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
964 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
965 bool isToken() const { return Kind == k_Token; }
966 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000967 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000968 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000969 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
970 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
971 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
972 bool isRotImm() const { return Kind == k_RotateImmediate; }
973 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
974 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000975 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000976 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000977 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000978 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000979 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000980 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000981 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000982 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
983 (alignOK || Memory.Alignment == 0);
984 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000985 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000986 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000987 return false;
988 // Base register must be PC.
989 if (Memory.BaseRegNum != ARM::PC)
990 return false;
991 // Immediate offset in range [-4095, 4095].
992 if (!Memory.OffsetImm) return true;
993 int64_t Val = Memory.OffsetImm->getValue();
994 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
995 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000996 bool isAlignedMemory() const {
997 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000998 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000999 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001000 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001001 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001002 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001003 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001004 if (!Memory.OffsetImm) return true;
1005 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001006 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001007 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001008 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001009 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001010 // Immediate offset in range [-4095, 4095].
1011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1012 if (!CE) return false;
1013 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001014 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001015 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001016 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001017 // If we have an immediate that's not a constant, treat it as a label
1018 // reference needing a fixup. If it is a constant, it's something else
1019 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001020 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001021 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001022 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001023 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001024 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001025 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001026 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001027 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001028 if (!Memory.OffsetImm) return true;
1029 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001030 // The #-0 offset is encoded as INT32_MIN, and we have to check
1031 // for this too.
1032 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001033 }
1034 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001035 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001036 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001037 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001038 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1039 // Immediate offset in range [-255, 255].
1040 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1041 if (!CE) return false;
1042 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001043 // Special case, #-0 is INT32_MIN.
1044 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001045 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001046 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001047 // If we have an immediate that's not a constant, treat it as a label
1048 // reference needing a fixup. If it is a constant, it's something else
1049 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001050 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001051 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001052 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001053 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001054 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001055 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001056 if (!Memory.OffsetImm) return true;
1057 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001058 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001059 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001060 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001061 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001062 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001063 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001064 return false;
1065 return true;
1066 }
1067 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001068 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001069 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1070 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001071 return false;
1072 return true;
1073 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001074 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001075 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001076 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001077 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001078 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001079 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001081 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001082 return false;
1083 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001084 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001085 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001086 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001087 return false;
1088 return true;
1089 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001090 bool isMemThumbRR() const {
1091 // Thumb reg+reg addressing is simple. Just two registers, a base and
1092 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001094 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001095 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001096 return isARMLowRegister(Memory.BaseRegNum) &&
1097 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001098 }
1099 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001100 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001101 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001102 return false;
1103 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 if (!Memory.OffsetImm) return true;
1105 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001106 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1107 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001108 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001109 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001110 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001111 return false;
1112 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001113 if (!Memory.OffsetImm) return true;
1114 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001115 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1116 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001117 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001118 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001119 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001120 return false;
1121 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001122 if (!Memory.OffsetImm) return true;
1123 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001124 return Val >= 0 && Val <= 31;
1125 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001126 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001128 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001129 return false;
1130 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001133 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001134 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001135 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001136 // If we have an immediate that's not a constant, treat it as a label
1137 // reference needing a fixup. If it is a constant, it's something else
1138 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001139 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001140 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001141 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001142 return false;
1143 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001144 if (!Memory.OffsetImm) return true;
1145 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001146 // Special case, #-0 is INT32_MIN.
1147 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001148 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001149 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001150 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001151 return false;
1152 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001153 if (!Memory.OffsetImm) return true;
1154 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001155 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1156 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001157 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001158 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001159 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001160 // Base reg of PC isn't allowed for these encodings.
1161 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001162 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001163 if (!Memory.OffsetImm) return true;
1164 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001165 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001166 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001167 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001168 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001169 return false;
1170 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001173 return Val >= 0 && Val < 256;
1174 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001175 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001177 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001178 // Base reg of PC isn't allowed for these encodings.
1179 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001180 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001181 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001182 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001183 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001184 }
1185 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001187 return false;
1188 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001191 return (Val >= 0 && Val < 4096);
1192 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001193 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001194 // If we have an immediate that's not a constant, treat it as a label
1195 // reference needing a fixup. If it is a constant, it's something else
1196 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001197 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001198 return true;
1199
Chad Rosier41099832012-09-11 23:02:35 +00001200 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001201 return false;
1202 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001203 if (!Memory.OffsetImm) return true;
1204 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001205 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001206 }
1207 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001208 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001209 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1210 if (!CE) return false;
1211 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001212 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001213 }
Jim Grosbach93981412011-10-11 21:55:36 +00001214 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001215 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001216 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1217 if (!CE) return false;
1218 int64_t Val = CE->getValue();
1219 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1220 (Val == INT32_MIN);
1221 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001222
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001223 bool isMSRMask() const { return Kind == k_MSRMask; }
1224 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001225
Jim Grosbach741cd732011-10-17 22:26:03 +00001226 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001227 bool isSingleSpacedVectorList() const {
1228 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1229 }
1230 bool isDoubleSpacedVectorList() const {
1231 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1232 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001233 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001234 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001235 return VectorList.Count == 1;
1236 }
1237
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001238 bool isVecListDPair() const {
1239 if (!isSingleSpacedVectorList()) return false;
1240 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1241 .contains(VectorList.RegNum));
1242 }
1243
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001244 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001245 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001246 return VectorList.Count == 3;
1247 }
1248
Jim Grosbach846bcff2011-10-21 20:35:01 +00001249 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001250 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001251 return VectorList.Count == 4;
1252 }
1253
Jim Grosbache5307f92012-03-05 21:43:40 +00001254 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001255 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001256 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1257 .contains(VectorList.RegNum));
1258 }
1259
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001260 bool isVecListThreeQ() const {
1261 if (!isDoubleSpacedVectorList()) return false;
1262 return VectorList.Count == 3;
1263 }
1264
Jim Grosbach1e946a42012-01-24 00:43:12 +00001265 bool isVecListFourQ() const {
1266 if (!isDoubleSpacedVectorList()) return false;
1267 return VectorList.Count == 4;
1268 }
1269
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001270 bool isSingleSpacedVectorAllLanes() const {
1271 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1272 }
1273 bool isDoubleSpacedVectorAllLanes() const {
1274 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1275 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001276 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001277 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001278 return VectorList.Count == 1;
1279 }
1280
Jim Grosbach13a292c2012-03-06 22:01:44 +00001281 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001282 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001283 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1284 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001285 }
1286
Jim Grosbached428bc2012-03-06 23:10:38 +00001287 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001288 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001289 return VectorList.Count == 2;
1290 }
1291
Jim Grosbachb78403c2012-01-24 23:47:04 +00001292 bool isVecListThreeDAllLanes() const {
1293 if (!isSingleSpacedVectorAllLanes()) return false;
1294 return VectorList.Count == 3;
1295 }
1296
1297 bool isVecListThreeQAllLanes() const {
1298 if (!isDoubleSpacedVectorAllLanes()) return false;
1299 return VectorList.Count == 3;
1300 }
1301
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001302 bool isVecListFourDAllLanes() const {
1303 if (!isSingleSpacedVectorAllLanes()) return false;
1304 return VectorList.Count == 4;
1305 }
1306
1307 bool isVecListFourQAllLanes() const {
1308 if (!isDoubleSpacedVectorAllLanes()) return false;
1309 return VectorList.Count == 4;
1310 }
1311
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001312 bool isSingleSpacedVectorIndexed() const {
1313 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1314 }
1315 bool isDoubleSpacedVectorIndexed() const {
1316 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1317 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001318 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001319 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001320 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1321 }
1322
Jim Grosbachda511042011-12-14 23:35:06 +00001323 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001324 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001325 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1326 }
1327
1328 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001329 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001330 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1331 }
1332
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001333 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001334 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001335 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1336 }
1337
Jim Grosbachda511042011-12-14 23:35:06 +00001338 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001339 if (!isSingleSpacedVectorIndexed()) return false;
1340 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1341 }
1342
1343 bool isVecListTwoQWordIndexed() const {
1344 if (!isDoubleSpacedVectorIndexed()) return false;
1345 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1346 }
1347
1348 bool isVecListTwoQHWordIndexed() const {
1349 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001350 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1351 }
1352
1353 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001354 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001355 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1356 }
1357
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001358 bool isVecListThreeDByteIndexed() const {
1359 if (!isSingleSpacedVectorIndexed()) return false;
1360 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1361 }
1362
1363 bool isVecListThreeDHWordIndexed() const {
1364 if (!isSingleSpacedVectorIndexed()) return false;
1365 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1366 }
1367
1368 bool isVecListThreeQWordIndexed() const {
1369 if (!isDoubleSpacedVectorIndexed()) return false;
1370 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1371 }
1372
1373 bool isVecListThreeQHWordIndexed() const {
1374 if (!isDoubleSpacedVectorIndexed()) return false;
1375 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1376 }
1377
1378 bool isVecListThreeDWordIndexed() const {
1379 if (!isSingleSpacedVectorIndexed()) return false;
1380 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1381 }
1382
Jim Grosbach14952a02012-01-24 18:37:25 +00001383 bool isVecListFourDByteIndexed() const {
1384 if (!isSingleSpacedVectorIndexed()) return false;
1385 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1386 }
1387
1388 bool isVecListFourDHWordIndexed() const {
1389 if (!isSingleSpacedVectorIndexed()) return false;
1390 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1391 }
1392
1393 bool isVecListFourQWordIndexed() const {
1394 if (!isDoubleSpacedVectorIndexed()) return false;
1395 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1396 }
1397
1398 bool isVecListFourQHWordIndexed() const {
1399 if (!isDoubleSpacedVectorIndexed()) return false;
1400 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1401 }
1402
1403 bool isVecListFourDWordIndexed() const {
1404 if (!isSingleSpacedVectorIndexed()) return false;
1405 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1406 }
1407
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001408 bool isVectorIndex8() const {
1409 if (Kind != k_VectorIndex) return false;
1410 return VectorIndex.Val < 8;
1411 }
1412 bool isVectorIndex16() const {
1413 if (Kind != k_VectorIndex) return false;
1414 return VectorIndex.Val < 4;
1415 }
1416 bool isVectorIndex32() const {
1417 if (Kind != k_VectorIndex) return false;
1418 return VectorIndex.Val < 2;
1419 }
1420
Jim Grosbach741cd732011-10-17 22:26:03 +00001421 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001422 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 // Must be a constant.
1425 if (!CE) return false;
1426 int64_t Value = CE->getValue();
1427 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1428 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001429 return Value >= 0 && Value < 256;
1430 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001431
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001432 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001433 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001434 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1435 // Must be a constant.
1436 if (!CE) return false;
1437 int64_t Value = CE->getValue();
1438 // i16 value in the range [0,255] or [0x0100, 0xff00]
1439 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1440 }
1441
Jim Grosbach8211c052011-10-18 00:22:00 +00001442 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001443 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1445 // Must be a constant.
1446 if (!CE) return false;
1447 int64_t Value = CE->getValue();
1448 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1449 return (Value >= 0 && Value < 256) ||
1450 (Value >= 0x0100 && Value <= 0xff00) ||
1451 (Value >= 0x010000 && Value <= 0xff0000) ||
1452 (Value >= 0x01000000 && Value <= 0xff000000);
1453 }
1454
1455 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001456 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001457 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1458 // Must be a constant.
1459 if (!CE) return false;
1460 int64_t Value = CE->getValue();
1461 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1462 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1463 return (Value >= 0 && Value < 256) ||
1464 (Value >= 0x0100 && Value <= 0xff00) ||
1465 (Value >= 0x010000 && Value <= 0xff0000) ||
1466 (Value >= 0x01000000 && Value <= 0xff000000) ||
1467 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1468 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1469 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001470 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001471 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001472 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1473 // Must be a constant.
1474 if (!CE) return false;
1475 int64_t Value = ~CE->getValue();
1476 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1477 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1478 return (Value >= 0 && Value < 256) ||
1479 (Value >= 0x0100 && Value <= 0xff00) ||
1480 (Value >= 0x010000 && Value <= 0xff0000) ||
1481 (Value >= 0x01000000 && Value <= 0xff000000) ||
1482 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1483 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1484 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001485
Jim Grosbache4454e02011-10-18 16:18:11 +00001486 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001487 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001488 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1489 // Must be a constant.
1490 if (!CE) return false;
1491 uint64_t Value = CE->getValue();
1492 // i64 value with each byte being either 0 or 0xff.
1493 for (unsigned i = 0; i < 8; ++i)
1494 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1495 return true;
1496 }
1497
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001498 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001499 // Add as immediates when possible. Null MCExpr = 0.
1500 if (Expr == 0)
1501 Inst.addOperand(MCOperand::CreateImm(0));
1502 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001503 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1504 else
1505 Inst.addOperand(MCOperand::CreateExpr(Expr));
1506 }
1507
Daniel Dunbard8042b72010-08-11 06:36:53 +00001508 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001509 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001510 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001511 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1512 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001513 }
1514
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001515 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1516 assert(N == 1 && "Invalid number of operands!");
1517 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1518 }
1519
Jim Grosbach48399582011-10-12 17:34:41 +00001520 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
1522 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1523 }
1524
1525 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1526 assert(N == 1 && "Invalid number of operands!");
1527 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1528 }
1529
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001530 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1531 assert(N == 1 && "Invalid number of operands!");
1532 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1533 }
1534
1535 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1538 }
1539
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001540 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1541 assert(N == 1 && "Invalid number of operands!");
1542 Inst.addOperand(MCOperand::CreateReg(getReg()));
1543 }
1544
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001545 void addRegOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 Inst.addOperand(MCOperand::CreateReg(getReg()));
1548 }
1549
Jim Grosbachac798e12011-07-25 20:49:51 +00001550 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001551 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001552 assert(isRegShiftedReg() &&
1553 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001554 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1555 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001556 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001557 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001558 }
1559
Jim Grosbachac798e12011-07-25 20:49:51 +00001560 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001561 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001562 assert(isRegShiftedImm() &&
1563 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001564 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001565 // Shift of #32 is encoded as 0 where permitted
1566 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001567 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001568 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001569 }
1570
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001571 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001572 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001573 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1574 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001575 }
1576
Bill Wendling8d2aa032010-11-08 23:49:57 +00001577 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001578 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001579 const SmallVectorImpl<unsigned> &RegList = getRegList();
1580 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001581 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1582 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001583 }
1584
Bill Wendling9898ac92010-11-17 04:32:08 +00001585 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1586 addRegListOperands(Inst, N);
1587 }
1588
1589 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1590 addRegListOperands(Inst, N);
1591 }
1592
Jim Grosbach833b9d32011-07-27 20:15:40 +00001593 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
1595 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1596 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1597 }
1598
Jim Grosbach864b6092011-07-28 21:34:26 +00001599 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1600 assert(N == 1 && "Invalid number of operands!");
1601 // Munge the lsb/width into a bitfield mask.
1602 unsigned lsb = Bitfield.LSB;
1603 unsigned width = Bitfield.Width;
1604 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1605 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1606 (32 - (lsb + width)));
1607 Inst.addOperand(MCOperand::CreateImm(Mask));
1608 }
1609
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001610 void addImmOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 addExpr(Inst, getImm());
1613 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001614
Jim Grosbachea231912011-12-22 22:19:05 +00001615 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1616 assert(N == 1 && "Invalid number of operands!");
1617 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1618 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1619 }
1620
1621 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1622 assert(N == 1 && "Invalid number of operands!");
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1625 }
1626
Jim Grosbache7fbce72011-10-03 23:38:36 +00001627 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1630 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1631 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001632 }
1633
Jim Grosbach7db8d692011-09-08 22:07:06 +00001634 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 // FIXME: We really want to scale the value here, but the LDRD/STRD
1637 // instruction don't encode operands that way yet.
1638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1639 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1640 }
1641
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001642 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 // The immediate is scaled by four in the encoding and is stored
1645 // in the MCInst as such. Lop off the low two bits here.
1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1648 }
1649
Jim Grosbach930f2f62012-04-05 20:57:13 +00001650 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 // The immediate is scaled by four in the encoding and is stored
1653 // in the MCInst as such. Lop off the low two bits here.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1656 }
1657
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001658 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1659 assert(N == 1 && "Invalid number of operands!");
1660 // The immediate is scaled by four in the encoding and is stored
1661 // in the MCInst as such. Lop off the low two bits here.
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1664 }
1665
Jim Grosbach475c6db2011-07-25 23:09:14 +00001666 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The constant encodes as the immediate-1, and we store in the instruction
1669 // the bits as encoded, so subtract off one here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1672 }
1673
Jim Grosbach801e0a32011-07-22 23:16:18 +00001674 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The constant encodes as the immediate-1, and we store in the instruction
1677 // the bits as encoded, so subtract off one here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1680 }
1681
Jim Grosbach46dd4132011-08-17 21:51:27 +00001682 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The constant encodes as the immediate, except for 32, which encodes as
1685 // zero.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 unsigned Imm = CE->getValue();
1688 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1689 }
1690
Jim Grosbach27c1e252011-07-21 17:23:04 +00001691 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1694 // the instruction as well.
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 int Val = CE->getValue();
1697 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1698 }
1699
Jim Grosbachb009a872011-10-28 22:36:30 +00001700 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 // The operand is actually a t2_so_imm, but we have its bitwise
1703 // negation in the assembly source, so twiddle it here.
1704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1705 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1706 }
1707
Jim Grosbach30506252011-12-08 00:31:07 +00001708 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // The operand is actually a t2_so_imm, but we have its
1711 // negation in the assembly source, so twiddle it here.
1712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1713 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1714 }
1715
Jim Grosbach930f2f62012-04-05 20:57:13 +00001716 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1717 assert(N == 1 && "Invalid number of operands!");
1718 // The operand is actually an imm0_4095, but we have its
1719 // negation in the assembly source, so twiddle it here.
1720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1722 }
1723
Mihai Popad36cbaa2013-07-03 09:21:44 +00001724 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1725 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1726 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1727 return;
1728 }
1729
1730 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1731 assert(SR && "Unknown value type!");
1732 Inst.addOperand(MCOperand::CreateExpr(SR));
1733 }
1734
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001735 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 1 && "Invalid number of operands!");
1737 // The operand is actually a so_imm, but we have its bitwise
1738 // negation in the assembly source, so twiddle it here.
1739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1740 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1741 }
1742
Jim Grosbach30506252011-12-08 00:31:07 +00001743 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1744 assert(N == 1 && "Invalid number of operands!");
1745 // The operand is actually a so_imm, but we have its
1746 // negation in the assembly source, so twiddle it here.
1747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1748 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1749 }
1750
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001751 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1752 assert(N == 1 && "Invalid number of operands!");
1753 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1754 }
1755
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001756 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1757 assert(N == 1 && "Invalid number of operands!");
1758 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1759 }
1760
Jim Grosbachd3595712011-08-03 23:50:40 +00001761 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1762 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001763 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001764 }
1765
Jim Grosbach94298a92012-01-18 22:46:46 +00001766 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1767 assert(N == 1 && "Invalid number of operands!");
1768 int32_t Imm = Memory.OffsetImm->getValue();
1769 // FIXME: Handle #-0
1770 if (Imm == INT32_MIN) Imm = 0;
1771 Inst.addOperand(MCOperand::CreateImm(Imm));
1772 }
1773
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001774 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1775 assert(N == 1 && "Invalid number of operands!");
1776 assert(isImm() && "Not an immediate!");
1777
1778 // If we have an immediate that's not a constant, treat it as a label
1779 // reference needing a fixup.
1780 if (!isa<MCConstantExpr>(getImm())) {
1781 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1782 return;
1783 }
1784
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 int Val = CE->getValue();
1787 Inst.addOperand(MCOperand::CreateImm(Val));
1788 }
1789
Jim Grosbacha95ec992011-10-11 17:29:55 +00001790 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 2 && "Invalid number of operands!");
1792 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1793 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1794 }
1795
Jim Grosbachd3595712011-08-03 23:50:40 +00001796 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1797 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001798 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1799 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001800 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1801 // Special case for #-0
1802 if (Val == INT32_MIN) Val = 0;
1803 if (Val < 0) Val = -Val;
1804 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1805 } else {
1806 // For register offset, we encode the shift type and negation flag
1807 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001808 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1809 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001810 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001811 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1812 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001813 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001814 }
1815
Jim Grosbachcd17c122011-08-04 23:01:30 +00001816 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 2 && "Invalid number of operands!");
1818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1819 assert(CE && "non-constant AM2OffsetImm operand!");
1820 int32_t Val = CE->getValue();
1821 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1822 // Special case for #-0
1823 if (Val == INT32_MIN) Val = 0;
1824 if (Val < 0) Val = -Val;
1825 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1826 Inst.addOperand(MCOperand::CreateReg(0));
1827 Inst.addOperand(MCOperand::CreateImm(Val));
1828 }
1829
Jim Grosbach5b96b802011-08-10 20:29:19 +00001830 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1831 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001832 // If we have an immediate that's not a constant, treat it as a label
1833 // reference needing a fixup. If it is a constant, it's something else
1834 // and we reject it.
1835 if (isImm()) {
1836 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1837 Inst.addOperand(MCOperand::CreateReg(0));
1838 Inst.addOperand(MCOperand::CreateImm(0));
1839 return;
1840 }
1841
Jim Grosbach871dff72011-10-11 15:59:20 +00001842 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1843 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001844 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;
1848 Val = ARM_AM::getAM3Opc(AddSub, Val);
1849 } else {
1850 // For register offset, we encode the shift type and negation flag
1851 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001852 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001853 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001854 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1855 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001856 Inst.addOperand(MCOperand::CreateImm(Val));
1857 }
1858
1859 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1860 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001861 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001862 int32_t Val =
1863 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1864 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1865 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001866 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001867 }
1868
1869 // Constant offset.
1870 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1871 int32_t Val = CE->getValue();
1872 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1873 // Special case for #-0
1874 if (Val == INT32_MIN) Val = 0;
1875 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001876 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001877 Inst.addOperand(MCOperand::CreateReg(0));
1878 Inst.addOperand(MCOperand::CreateImm(Val));
1879 }
1880
Jim Grosbachd3595712011-08-03 23:50:40 +00001881 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1882 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001883 // If we have an immediate that's not a constant, treat it as a label
1884 // reference needing a fixup. If it is a constant, it's something else
1885 // and we reject it.
1886 if (isImm()) {
1887 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1888 Inst.addOperand(MCOperand::CreateImm(0));
1889 return;
1890 }
1891
Jim Grosbachd3595712011-08-03 23:50:40 +00001892 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001893 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001894 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1895 // Special case for #-0
1896 if (Val == INT32_MIN) Val = 0;
1897 if (Val < 0) Val = -Val;
1898 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001899 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001900 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001901 }
1902
Jim Grosbach7db8d692011-09-08 22:07:06 +00001903 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1904 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001905 // If we have an immediate that's not a constant, treat it as a label
1906 // reference needing a fixup. If it is a constant, it's something else
1907 // and we reject it.
1908 if (isImm()) {
1909 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1910 Inst.addOperand(MCOperand::CreateImm(0));
1911 return;
1912 }
1913
Jim Grosbach871dff72011-10-11 15:59:20 +00001914 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1915 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001916 Inst.addOperand(MCOperand::CreateImm(Val));
1917 }
1918
Jim Grosbacha05627e2011-09-09 18:37:27 +00001919 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1920 assert(N == 2 && "Invalid number of operands!");
1921 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001922 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1923 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001924 Inst.addOperand(MCOperand::CreateImm(Val));
1925 }
1926
Jim Grosbachd3595712011-08-03 23:50:40 +00001927 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1928 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001929 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1930 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001931 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001932 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001933
Jim Grosbach2392c532011-09-07 23:39:14 +00001934 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1935 addMemImm8OffsetOperands(Inst, N);
1936 }
1937
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001938 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001939 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001940 }
1941
1942 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1943 assert(N == 2 && "Invalid number of operands!");
1944 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001945 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001946 addExpr(Inst, getImm());
1947 Inst.addOperand(MCOperand::CreateImm(0));
1948 return;
1949 }
1950
1951 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001952 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1953 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001954 Inst.addOperand(MCOperand::CreateImm(Val));
1955 }
1956
Jim Grosbachd3595712011-08-03 23:50:40 +00001957 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001959 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001960 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001961 addExpr(Inst, getImm());
1962 Inst.addOperand(MCOperand::CreateImm(0));
1963 return;
1964 }
1965
1966 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001967 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001969 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001970 }
Bill Wendling811c9362010-11-30 07:44:32 +00001971
Jim Grosbach05541f42011-09-19 22:21:13 +00001972 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001974 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1975 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001976 }
1977
1978 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001980 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1981 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001982 }
1983
Jim Grosbachd3595712011-08-03 23:50:40 +00001984 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1985 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001986 unsigned Val =
1987 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1988 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1990 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001991 Inst.addOperand(MCOperand::CreateImm(Val));
1992 }
1993
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001994 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1995 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001996 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1997 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1998 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001999 }
2000
Jim Grosbachd3595712011-08-03 23:50:40 +00002001 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2002 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2004 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002005 }
2006
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002007 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2008 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002009 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002011 Inst.addOperand(MCOperand::CreateImm(Val));
2012 }
2013
Jim Grosbach26d35872011-08-19 18:55:51 +00002014 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002016 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2017 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002018 Inst.addOperand(MCOperand::CreateImm(Val));
2019 }
2020
Jim Grosbacha32c7532011-08-19 18:49:59 +00002021 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2022 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002023 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002025 Inst.addOperand(MCOperand::CreateImm(Val));
2026 }
2027
Jim Grosbach23983d62011-08-19 18:13:48 +00002028 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2029 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002030 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002032 Inst.addOperand(MCOperand::CreateImm(Val));
2033 }
2034
Jim Grosbachd3595712011-08-03 23:50:40 +00002035 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2036 assert(N == 1 && "Invalid number of operands!");
2037 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2038 assert(CE && "non-constant post-idx-imm8 operand!");
2039 int Imm = CE->getValue();
2040 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002041 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002042 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2043 Inst.addOperand(MCOperand::CreateImm(Imm));
2044 }
2045
Jim Grosbach93981412011-10-11 21:55:36 +00002046 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2049 assert(CE && "non-constant post-idx-imm8s4 operand!");
2050 int Imm = CE->getValue();
2051 bool isAdd = Imm >= 0;
2052 if (Imm == INT32_MIN) Imm = 0;
2053 // Immediate is scaled by 4.
2054 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2055 Inst.addOperand(MCOperand::CreateImm(Imm));
2056 }
2057
Jim Grosbachd3595712011-08-03 23:50:40 +00002058 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2059 assert(N == 2 && "Invalid number of operands!");
2060 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002061 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2062 }
2063
2064 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 2 && "Invalid number of operands!");
2066 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2067 // The sign, shift type, and shift amount are encoded in a single operand
2068 // using the AM2 encoding helpers.
2069 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2070 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2071 PostIdxReg.ShiftTy);
2072 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002073 }
2074
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002075 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2076 assert(N == 1 && "Invalid number of operands!");
2077 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2078 }
2079
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002080 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2081 assert(N == 1 && "Invalid number of operands!");
2082 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2083 }
2084
Jim Grosbach182b6a02011-11-29 23:51:09 +00002085 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002086 assert(N == 1 && "Invalid number of operands!");
2087 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2088 }
2089
Jim Grosbach04945c42011-12-02 00:35:16 +00002090 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
2092 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2093 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2094 }
2095
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002096 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2097 assert(N == 1 && "Invalid number of operands!");
2098 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2099 }
2100
2101 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2102 assert(N == 1 && "Invalid number of operands!");
2103 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2104 }
2105
2106 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2109 }
2110
Jim Grosbach741cd732011-10-17 22:26:03 +00002111 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 // The immediate encodes the type of constant as well as the value.
2114 // Mask in that this is an i8 splat.
2115 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2116 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2117 }
2118
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002119 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2120 assert(N == 1 && "Invalid number of operands!");
2121 // The immediate encodes the type of constant as well as the value.
2122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2123 unsigned Value = CE->getValue();
2124 if (Value >= 256)
2125 Value = (Value >> 8) | 0xa00;
2126 else
2127 Value |= 0x800;
2128 Inst.addOperand(MCOperand::CreateImm(Value));
2129 }
2130
Jim Grosbach8211c052011-10-18 00:22:00 +00002131 void addNEONi32splatOperands(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 <= 0xff00)
2137 Value = (Value >> 8) | 0x200;
2138 else if (Value > 0xffff && Value <= 0xff0000)
2139 Value = (Value >> 16) | 0x400;
2140 else if (Value > 0xffffff)
2141 Value = (Value >> 24) | 0x600;
2142 Inst.addOperand(MCOperand::CreateImm(Value));
2143 }
2144
2145 void addNEONi32vmovOperands(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 unsigned Value = CE->getValue();
2150 if (Value >= 256 && Value <= 0xffff)
2151 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2152 else if (Value > 0xffff && Value <= 0xffffff)
2153 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2154 else if (Value > 0xffffff)
2155 Value = (Value >> 24) | 0x600;
2156 Inst.addOperand(MCOperand::CreateImm(Value));
2157 }
2158
Jim Grosbach045b6c72011-12-19 23:51:07 +00002159 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2160 assert(N == 1 && "Invalid number of operands!");
2161 // The immediate encodes the type of constant as well as the value.
2162 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2163 unsigned Value = ~CE->getValue();
2164 if (Value >= 256 && Value <= 0xffff)
2165 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2166 else if (Value > 0xffff && Value <= 0xffffff)
2167 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2168 else if (Value > 0xffffff)
2169 Value = (Value >> 24) | 0x600;
2170 Inst.addOperand(MCOperand::CreateImm(Value));
2171 }
2172
Jim Grosbache4454e02011-10-18 16:18:11 +00002173 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2174 assert(N == 1 && "Invalid number of operands!");
2175 // The immediate encodes the type of constant as well as the value.
2176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2177 uint64_t Value = CE->getValue();
2178 unsigned Imm = 0;
2179 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2180 Imm |= (Value & 1) << i;
2181 }
2182 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2183 }
2184
Jim Grosbach602aa902011-07-13 15:34:57 +00002185 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002186
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002187 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002188 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002189 Op->ITMask.Mask = Mask;
2190 Op->StartLoc = S;
2191 Op->EndLoc = S;
2192 return Op;
2193 }
2194
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002195 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002196 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002197 Op->CC.Val = CC;
2198 Op->StartLoc = S;
2199 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002200 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002201 }
2202
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002203 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002204 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002205 Op->Cop.Val = CopVal;
2206 Op->StartLoc = S;
2207 Op->EndLoc = S;
2208 return Op;
2209 }
2210
2211 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002212 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002213 Op->Cop.Val = CopVal;
2214 Op->StartLoc = S;
2215 Op->EndLoc = S;
2216 return Op;
2217 }
2218
Jim Grosbach48399582011-10-12 17:34:41 +00002219 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2220 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2221 Op->Cop.Val = Val;
2222 Op->StartLoc = S;
2223 Op->EndLoc = E;
2224 return Op;
2225 }
2226
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002227 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002228 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002229 Op->Reg.RegNum = RegNum;
2230 Op->StartLoc = S;
2231 Op->EndLoc = S;
2232 return Op;
2233 }
2234
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002235 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002236 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002237 Op->Tok.Data = Str.data();
2238 Op->Tok.Length = Str.size();
2239 Op->StartLoc = S;
2240 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002241 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002242 }
2243
Bill Wendling2063b842010-11-18 23:43:05 +00002244 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002245 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002246 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002247 Op->StartLoc = S;
2248 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002249 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002250 }
2251
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002252 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2253 unsigned SrcReg,
2254 unsigned ShiftReg,
2255 unsigned ShiftImm,
2256 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002257 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002258 Op->RegShiftedReg.ShiftTy = ShTy;
2259 Op->RegShiftedReg.SrcReg = SrcReg;
2260 Op->RegShiftedReg.ShiftReg = ShiftReg;
2261 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002262 Op->StartLoc = S;
2263 Op->EndLoc = E;
2264 return Op;
2265 }
2266
Owen Andersonb595ed02011-07-21 18:54:16 +00002267 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2268 unsigned SrcReg,
2269 unsigned ShiftImm,
2270 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002272 Op->RegShiftedImm.ShiftTy = ShTy;
2273 Op->RegShiftedImm.SrcReg = SrcReg;
2274 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002275 Op->StartLoc = S;
2276 Op->EndLoc = E;
2277 return Op;
2278 }
2279
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002280 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002281 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002282 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002283 Op->ShifterImm.isASR = isASR;
2284 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002285 Op->StartLoc = S;
2286 Op->EndLoc = E;
2287 return Op;
2288 }
2289
Jim Grosbach833b9d32011-07-27 20:15:40 +00002290 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002291 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002292 Op->RotImm.Imm = Imm;
2293 Op->StartLoc = S;
2294 Op->EndLoc = E;
2295 return Op;
2296 }
2297
Jim Grosbach864b6092011-07-28 21:34:26 +00002298 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2299 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002300 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002301 Op->Bitfield.LSB = LSB;
2302 Op->Bitfield.Width = Width;
2303 Op->StartLoc = S;
2304 Op->EndLoc = E;
2305 return Op;
2306 }
2307
Bill Wendling2cae3272010-11-09 22:44:22 +00002308 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002309 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002310 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002311 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002312 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002313
Chad Rosierfa705ee2013-07-01 20:49:23 +00002314 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002315 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002316 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002317 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002318 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002319
Chad Rosierfa705ee2013-07-01 20:49:23 +00002320 // Sort based on the register encoding values.
2321 array_pod_sort(Regs.begin(), Regs.end());
2322
Bill Wendling9898ac92010-11-17 04:32:08 +00002323 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002324 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002325 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002326 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002327 Op->StartLoc = StartLoc;
2328 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002329 return Op;
2330 }
2331
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002332 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002333 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002334 ARMOperand *Op = new ARMOperand(k_VectorList);
2335 Op->VectorList.RegNum = RegNum;
2336 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002337 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002338 Op->StartLoc = S;
2339 Op->EndLoc = E;
2340 return Op;
2341 }
2342
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002343 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002344 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002345 SMLoc S, SMLoc E) {
2346 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2347 Op->VectorList.RegNum = RegNum;
2348 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002349 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002350 Op->StartLoc = S;
2351 Op->EndLoc = E;
2352 return Op;
2353 }
2354
Jim Grosbach04945c42011-12-02 00:35:16 +00002355 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002356 unsigned Index,
2357 bool isDoubleSpaced,
2358 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002359 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2360 Op->VectorList.RegNum = RegNum;
2361 Op->VectorList.Count = Count;
2362 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002363 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002364 Op->StartLoc = S;
2365 Op->EndLoc = E;
2366 return Op;
2367 }
2368
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002369 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2370 MCContext &Ctx) {
2371 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2372 Op->VectorIndex.Val = Idx;
2373 Op->StartLoc = S;
2374 Op->EndLoc = E;
2375 return Op;
2376 }
2377
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002378 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002379 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002380 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002381 Op->StartLoc = S;
2382 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002383 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002384 }
2385
Jim Grosbachd3595712011-08-03 23:50:40 +00002386 static ARMOperand *CreateMem(unsigned BaseRegNum,
2387 const MCConstantExpr *OffsetImm,
2388 unsigned OffsetRegNum,
2389 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002390 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002391 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002392 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002393 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002394 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002395 Op->Memory.BaseRegNum = BaseRegNum;
2396 Op->Memory.OffsetImm = OffsetImm;
2397 Op->Memory.OffsetRegNum = OffsetRegNum;
2398 Op->Memory.ShiftType = ShiftType;
2399 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002400 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002401 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002402 Op->StartLoc = S;
2403 Op->EndLoc = E;
2404 return Op;
2405 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002406
Jim Grosbachc320c852011-08-05 21:28:30 +00002407 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2408 ARM_AM::ShiftOpc ShiftTy,
2409 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002410 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002411 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002412 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002413 Op->PostIdxReg.isAdd = isAdd;
2414 Op->PostIdxReg.ShiftTy = ShiftTy;
2415 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002416 Op->StartLoc = S;
2417 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002418 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002419 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002420
2421 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002422 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002423 Op->MBOpt.Val = Opt;
2424 Op->StartLoc = S;
2425 Op->EndLoc = S;
2426 return Op;
2427 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002428
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002429 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2430 SMLoc S) {
2431 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2432 Op->ISBOpt.Val = Opt;
2433 Op->StartLoc = S;
2434 Op->EndLoc = S;
2435 return Op;
2436 }
2437
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002438 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002439 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002440 Op->IFlags.Val = IFlags;
2441 Op->StartLoc = S;
2442 Op->EndLoc = S;
2443 return Op;
2444 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002445
2446 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002447 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002448 Op->MMask.Val = MMask;
2449 Op->StartLoc = S;
2450 Op->EndLoc = S;
2451 return Op;
2452 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002453};
2454
2455} // end anonymous namespace.
2456
Jim Grosbach602aa902011-07-13 15:34:57 +00002457void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002458 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002459 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002460 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002462 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002463 OS << "<ccout " << getReg() << ">";
2464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002465 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002466 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002467 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2468 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2469 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002470 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2471 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2472 break;
2473 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002474 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002475 OS << "<coprocessor number: " << getCoproc() << ">";
2476 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002477 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002478 OS << "<coprocessor register: " << getCoproc() << ">";
2479 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002480 case k_CoprocOption:
2481 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2482 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002483 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002484 OS << "<mask: " << getMSRMask() << ">";
2485 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002486 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002487 getImm()->print(OS);
2488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002489 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002490 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2491 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002492 case k_InstSyncBarrierOpt:
2493 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2494 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002495 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002496 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002497 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002498 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002500 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002501 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2502 << PostIdxReg.RegNum;
2503 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2504 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2505 << PostIdxReg.ShiftImm;
2506 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002508 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002509 OS << "<ARM_PROC::";
2510 unsigned IFlags = getProcIFlags();
2511 for (int i=2; i >= 0; --i)
2512 if (IFlags & (1 << i))
2513 OS << ARM_PROC::IFlagsToString(1 << i);
2514 OS << ">";
2515 break;
2516 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002517 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002518 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002520 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002521 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2522 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002523 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002525 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002526 << RegShiftedReg.SrcReg << " "
2527 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2528 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002530 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002531 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002532 << RegShiftedImm.SrcReg << " "
2533 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2534 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002536 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002537 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002539 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002540 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2541 << ", width: " << Bitfield.Width << ">";
2542 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_RegisterList:
2544 case k_DPRRegisterList:
2545 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002546 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002547
Bill Wendlingbed94652010-11-09 23:28:44 +00002548 const SmallVectorImpl<unsigned> &RegList = getRegList();
2549 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002550 I = RegList.begin(), E = RegList.end(); I != E; ) {
2551 OS << *I;
2552 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002553 }
2554
2555 OS << ">";
2556 break;
2557 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002558 case k_VectorList:
2559 OS << "<vector_list " << VectorList.Count << " * "
2560 << VectorList.RegNum << ">";
2561 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002562 case k_VectorListAllLanes:
2563 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2564 << VectorList.RegNum << ">";
2565 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002566 case k_VectorListIndexed:
2567 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2568 << VectorList.Count << " * " << VectorList.RegNum << ">";
2569 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002570 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002571 OS << "'" << getToken() << "'";
2572 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002573 case k_VectorIndex:
2574 OS << "<vectorindex " << getVectorIndex() << ">";
2575 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002576 }
2577}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002578
2579/// @name Auto-generated Match Functions
2580/// {
2581
2582static unsigned MatchRegisterName(StringRef Name);
2583
2584/// }
2585
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002586bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2587 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002588 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002589 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002590 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002591
2592 return (RegNo == (unsigned)-1);
2593}
2594
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002595/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002596/// and if it is a register name the token is eaten and the register number is
2597/// returned. Otherwise return -1.
2598///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002599int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002600 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002601 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002602
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002603 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002604 unsigned RegNum = MatchRegisterName(lowerCase);
2605 if (!RegNum) {
2606 RegNum = StringSwitch<unsigned>(lowerCase)
2607 .Case("r13", ARM::SP)
2608 .Case("r14", ARM::LR)
2609 .Case("r15", ARM::PC)
2610 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002611 // Additional register name aliases for 'gas' compatibility.
2612 .Case("a1", ARM::R0)
2613 .Case("a2", ARM::R1)
2614 .Case("a3", ARM::R2)
2615 .Case("a4", ARM::R3)
2616 .Case("v1", ARM::R4)
2617 .Case("v2", ARM::R5)
2618 .Case("v3", ARM::R6)
2619 .Case("v4", ARM::R7)
2620 .Case("v5", ARM::R8)
2621 .Case("v6", ARM::R9)
2622 .Case("v7", ARM::R10)
2623 .Case("v8", ARM::R11)
2624 .Case("sb", ARM::R9)
2625 .Case("sl", ARM::R10)
2626 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002627 .Default(0);
2628 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002629 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002630 // Check for aliases registered via .req. Canonicalize to lower case.
2631 // That's more consistent since register names are case insensitive, and
2632 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2633 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002634 // If no match, return failure.
2635 if (Entry == RegisterReqs.end())
2636 return -1;
2637 Parser.Lex(); // Eat identifier token.
2638 return Entry->getValue();
2639 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002640
Chris Lattner44e5981c2010-10-30 04:09:10 +00002641 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002642
Chris Lattner44e5981c2010-10-30 04:09:10 +00002643 return RegNum;
2644}
Jim Grosbach99710a82010-11-01 16:44:21 +00002645
Jim Grosbachbb24c592011-07-13 18:49:30 +00002646// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2647// If a recoverable error occurs, return 1. If an irrecoverable error
2648// occurs, return -1. An irrecoverable error is one where tokens have been
2649// consumed in the process of trying to parse the shifter (i.e., when it is
2650// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002651int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002652 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2653 SMLoc S = Parser.getTok().getLoc();
2654 const AsmToken &Tok = Parser.getTok();
2655 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2656
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002657 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002658 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002659 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002660 .Case("lsl", ARM_AM::lsl)
2661 .Case("lsr", ARM_AM::lsr)
2662 .Case("asr", ARM_AM::asr)
2663 .Case("ror", ARM_AM::ror)
2664 .Case("rrx", ARM_AM::rrx)
2665 .Default(ARM_AM::no_shift);
2666
2667 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002668 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002669
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002670 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002671
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002672 // The source register for the shift has already been added to the
2673 // operand list, so we need to pop it off and combine it into the shifted
2674 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002675 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002676 if (!PrevOp->isReg())
2677 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2678 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002679
2680 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002681 int64_t Imm = 0;
2682 int ShiftReg = 0;
2683 if (ShiftTy == ARM_AM::rrx) {
2684 // RRX Doesn't have an explicit shift amount. The encoder expects
2685 // the shift register to be the same as the source register. Seems odd,
2686 // but OK.
2687 ShiftReg = SrcReg;
2688 } else {
2689 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002690 if (Parser.getTok().is(AsmToken::Hash) ||
2691 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002692 Parser.Lex(); // Eat hash.
2693 SMLoc ImmLoc = Parser.getTok().getLoc();
2694 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002695 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002696 Error(ImmLoc, "invalid immediate shift value");
2697 return -1;
2698 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002699 // The expression must be evaluatable as an immediate.
2700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002701 if (!CE) {
2702 Error(ImmLoc, "invalid immediate shift value");
2703 return -1;
2704 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002705 // Range check the immediate.
2706 // lsl, ror: 0 <= imm <= 31
2707 // lsr, asr: 0 <= imm <= 32
2708 Imm = CE->getValue();
2709 if (Imm < 0 ||
2710 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2711 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002712 Error(ImmLoc, "immediate shift value out of range");
2713 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002714 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002715 // shift by zero is a nop. Always send it through as lsl.
2716 // ('as' compatibility)
2717 if (Imm == 0)
2718 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002719 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002720 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002721 EndLoc = Parser.getTok().getEndLoc();
2722 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002723 if (ShiftReg == -1) {
2724 Error (L, "expected immediate or register in shift operand");
2725 return -1;
2726 }
2727 } else {
2728 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002729 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002730 return -1;
2731 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002732 }
2733
Owen Andersonb595ed02011-07-21 18:54:16 +00002734 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2735 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002736 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002737 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002738 else
2739 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002740 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002741
Jim Grosbachbb24c592011-07-13 18:49:30 +00002742 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002743}
2744
2745
Bill Wendling2063b842010-11-18 23:43:05 +00002746/// Try to parse a register name. The token must be an Identifier when called.
2747/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2748/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002749///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002750/// TODO this is likely to change to allow different register types and or to
2751/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002752bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002753tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002754 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002755 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002756 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002757 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002758
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002759 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2760 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002761
Chris Lattner44e5981c2010-10-30 04:09:10 +00002762 const AsmToken &ExclaimTok = Parser.getTok();
2763 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002764 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2765 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002766 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002767 return false;
2768 }
2769
2770 // Also check for an index operand. This is only legal for vector registers,
2771 // but that'll get caught OK in operand matching, so we don't need to
2772 // explicitly filter everything else out here.
2773 if (Parser.getTok().is(AsmToken::LBrac)) {
2774 SMLoc SIdx = Parser.getTok().getLoc();
2775 Parser.Lex(); // Eat left bracket token.
2776
2777 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002778 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002779 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002780 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002781 if (!MCE)
2782 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002783
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002784 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002785 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002786
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002787 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002788 Parser.Lex(); // Eat right bracket token.
2789
2790 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2791 SIdx, E,
2792 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002793 }
2794
Bill Wendling2063b842010-11-18 23:43:05 +00002795 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002796}
2797
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002798/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2799/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2800/// "c5", ...
2801static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002802 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2803 // but efficient.
2804 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002805 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002806 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002807 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002808 return -1;
2809 switch (Name[1]) {
2810 default: return -1;
2811 case '0': return 0;
2812 case '1': return 1;
2813 case '2': return 2;
2814 case '3': return 3;
2815 case '4': return 4;
2816 case '5': return 5;
2817 case '6': return 6;
2818 case '7': return 7;
2819 case '8': return 8;
2820 case '9': return 9;
2821 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002822 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002823 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002824 return -1;
2825 switch (Name[2]) {
2826 default: return -1;
2827 case '0': return 10;
2828 case '1': return 11;
2829 case '2': return 12;
2830 case '3': return 13;
2831 case '4': return 14;
2832 case '5': return 15;
2833 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002834 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002835}
2836
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002837/// parseITCondCode - Try to parse a condition code for an IT instruction.
2838ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2839parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2840 SMLoc S = Parser.getTok().getLoc();
2841 const AsmToken &Tok = Parser.getTok();
2842 if (!Tok.is(AsmToken::Identifier))
2843 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002844 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002845 .Case("eq", ARMCC::EQ)
2846 .Case("ne", ARMCC::NE)
2847 .Case("hs", ARMCC::HS)
2848 .Case("cs", ARMCC::HS)
2849 .Case("lo", ARMCC::LO)
2850 .Case("cc", ARMCC::LO)
2851 .Case("mi", ARMCC::MI)
2852 .Case("pl", ARMCC::PL)
2853 .Case("vs", ARMCC::VS)
2854 .Case("vc", ARMCC::VC)
2855 .Case("hi", ARMCC::HI)
2856 .Case("ls", ARMCC::LS)
2857 .Case("ge", ARMCC::GE)
2858 .Case("lt", ARMCC::LT)
2859 .Case("gt", ARMCC::GT)
2860 .Case("le", ARMCC::LE)
2861 .Case("al", ARMCC::AL)
2862 .Default(~0U);
2863 if (CC == ~0U)
2864 return MatchOperand_NoMatch;
2865 Parser.Lex(); // Eat the token.
2866
2867 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2868
2869 return MatchOperand_Success;
2870}
2871
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002872/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002873/// token must be an Identifier when called, and if it is a coprocessor
2874/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002875ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002876parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002877 SMLoc S = Parser.getTok().getLoc();
2878 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002879 if (Tok.isNot(AsmToken::Identifier))
2880 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002881
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002882 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002883 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002884 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002885
2886 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002887 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002888 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002889}
2890
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002891/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002892/// token must be an Identifier when called, and if it is a coprocessor
2893/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002894ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002895parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002896 SMLoc S = Parser.getTok().getLoc();
2897 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002898 if (Tok.isNot(AsmToken::Identifier))
2899 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002900
2901 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2902 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002903 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002904
2905 Parser.Lex(); // Eat identifier token.
2906 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002907 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002908}
2909
Jim Grosbach48399582011-10-12 17:34:41 +00002910/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2911/// coproc_option : '{' imm0_255 '}'
2912ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2913parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2914 SMLoc S = Parser.getTok().getLoc();
2915
2916 // If this isn't a '{', this isn't a coprocessor immediate operand.
2917 if (Parser.getTok().isNot(AsmToken::LCurly))
2918 return MatchOperand_NoMatch;
2919 Parser.Lex(); // Eat the '{'
2920
2921 const MCExpr *Expr;
2922 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002923 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002924 Error(Loc, "illegal expression");
2925 return MatchOperand_ParseFail;
2926 }
2927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2928 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2929 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2930 return MatchOperand_ParseFail;
2931 }
2932 int Val = CE->getValue();
2933
2934 // Check for and consume the closing '}'
2935 if (Parser.getTok().isNot(AsmToken::RCurly))
2936 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002937 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002938 Parser.Lex(); // Eat the '}'
2939
2940 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2941 return MatchOperand_Success;
2942}
2943
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002944// For register list parsing, we need to map from raw GPR register numbering
2945// to the enumeration values. The enumeration values aren't sorted by
2946// register number due to our using "sp", "lr" and "pc" as canonical names.
2947static unsigned getNextRegister(unsigned Reg) {
2948 // If this is a GPR, we need to do it manually, otherwise we can rely
2949 // on the sort ordering of the enumeration since the other reg-classes
2950 // are sane.
2951 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2952 return Reg + 1;
2953 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002954 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002955 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2956 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2957 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2958 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2959 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2960 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2961 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2962 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2963 }
2964}
2965
Jim Grosbach85a23432011-11-11 21:27:40 +00002966// Return the low-subreg of a given Q register.
2967static unsigned getDRegFromQReg(unsigned QReg) {
2968 switch (QReg) {
2969 default: llvm_unreachable("expected a Q register!");
2970 case ARM::Q0: return ARM::D0;
2971 case ARM::Q1: return ARM::D2;
2972 case ARM::Q2: return ARM::D4;
2973 case ARM::Q3: return ARM::D6;
2974 case ARM::Q4: return ARM::D8;
2975 case ARM::Q5: return ARM::D10;
2976 case ARM::Q6: return ARM::D12;
2977 case ARM::Q7: return ARM::D14;
2978 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002979 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002980 case ARM::Q10: return ARM::D20;
2981 case ARM::Q11: return ARM::D22;
2982 case ARM::Q12: return ARM::D24;
2983 case ARM::Q13: return ARM::D26;
2984 case ARM::Q14: return ARM::D28;
2985 case ARM::Q15: return ARM::D30;
2986 }
2987}
2988
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002989/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002990bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002991parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002992 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002993 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002994 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002995 Parser.Lex(); // Eat '{' token.
2996 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002997
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002998 // Check the first register in the list to see what register class
2999 // this is a list of.
3000 int Reg = tryParseRegister();
3001 if (Reg == -1)
3002 return Error(RegLoc, "register expected");
3003
Jim Grosbach85a23432011-11-11 21:27:40 +00003004 // The reglist instructions have at most 16 registers, so reserve
3005 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003006 int EReg = 0;
3007 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003008
3009 // Allow Q regs and just interpret them as the two D sub-registers.
3010 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3011 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003012 EReg = MRI->getEncodingValue(Reg);
3013 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003014 ++Reg;
3015 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003016 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003017 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3018 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3019 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3020 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3021 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3022 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3023 else
3024 return Error(RegLoc, "invalid register in register list");
3025
Jim Grosbach85a23432011-11-11 21:27:40 +00003026 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003027 EReg = MRI->getEncodingValue(Reg);
3028 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003029
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003030 // This starts immediately after the first register token in the list,
3031 // so we can see either a comma or a minus (range separator) as a legal
3032 // next token.
3033 while (Parser.getTok().is(AsmToken::Comma) ||
3034 Parser.getTok().is(AsmToken::Minus)) {
3035 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003036 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003037 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003038 int EndReg = tryParseRegister();
3039 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003040 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003041 // Allow Q regs and just interpret them as the two D sub-registers.
3042 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3043 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003044 // If the register is the same as the start reg, there's nothing
3045 // more to do.
3046 if (Reg == EndReg)
3047 continue;
3048 // The register must be in the same register class as the first.
3049 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003050 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003051 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003052 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003053 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003054
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003055 // Add all the registers in the range to the register list.
3056 while (Reg != EndReg) {
3057 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003058 EReg = MRI->getEncodingValue(Reg);
3059 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003060 }
3061 continue;
3062 }
3063 Parser.Lex(); // Eat the comma.
3064 RegLoc = Parser.getTok().getLoc();
3065 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003066 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003067 Reg = tryParseRegister();
3068 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003069 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003070 // Allow Q regs and just interpret them as the two D sub-registers.
3071 bool isQReg = false;
3072 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3073 Reg = getDRegFromQReg(Reg);
3074 isQReg = true;
3075 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003076 // The register must be in the same register class as the first.
3077 if (!RC->contains(Reg))
3078 return Error(RegLoc, "invalid register in register list");
3079 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003080 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003081 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3082 Warning(RegLoc, "register list not in ascending order");
3083 else
3084 return Error(RegLoc, "register list not in ascending order");
3085 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003086 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003087 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3088 ") in register list");
3089 continue;
3090 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003091 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003092 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3093 Reg != OldReg + 1)
3094 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003095 EReg = MRI->getEncodingValue(Reg);
3096 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3097 if (isQReg) {
3098 EReg = MRI->getEncodingValue(++Reg);
3099 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3100 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003101 }
3102
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003103 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003104 return Error(Parser.getTok().getLoc(), "'}' expected");
3105 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003106 Parser.Lex(); // Eat '}' token.
3107
Jim Grosbach18bf3632011-12-13 21:48:29 +00003108 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003109 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003110
3111 // The ARM system instruction variants for LDM/STM have a '^' token here.
3112 if (Parser.getTok().is(AsmToken::Caret)) {
3113 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3114 Parser.Lex(); // Eat '^' token.
3115 }
3116
Bill Wendling2063b842010-11-18 23:43:05 +00003117 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003118}
3119
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003120// Helper function to parse the lane index for vector lists.
3121ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003122parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003123 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003124 if (Parser.getTok().is(AsmToken::LBrac)) {
3125 Parser.Lex(); // Eat the '['.
3126 if (Parser.getTok().is(AsmToken::RBrac)) {
3127 // "Dn[]" is the 'all lanes' syntax.
3128 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003129 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003130 Parser.Lex(); // Eat the ']'.
3131 return MatchOperand_Success;
3132 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003133
3134 // There's an optional '#' token here. Normally there wouldn't be, but
3135 // inline assemble puts one in, and it's friendly to accept that.
3136 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003137 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003138
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003139 const MCExpr *LaneIndex;
3140 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003141 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003142 Error(Loc, "illegal expression");
3143 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003144 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003145 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3146 if (!CE) {
3147 Error(Loc, "lane index must be empty or an integer");
3148 return MatchOperand_ParseFail;
3149 }
3150 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3151 Error(Parser.getTok().getLoc(), "']' expected");
3152 return MatchOperand_ParseFail;
3153 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003154 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003155 Parser.Lex(); // Eat the ']'.
3156 int64_t Val = CE->getValue();
3157
3158 // FIXME: Make this range check context sensitive for .8, .16, .32.
3159 if (Val < 0 || Val > 7) {
3160 Error(Parser.getTok().getLoc(), "lane index out of range");
3161 return MatchOperand_ParseFail;
3162 }
3163 Index = Val;
3164 LaneKind = IndexedLane;
3165 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003166 }
3167 LaneKind = NoLanes;
3168 return MatchOperand_Success;
3169}
3170
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003171// parse a vector register list
3172ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3173parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003174 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003175 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003176 SMLoc S = Parser.getTok().getLoc();
3177 // As an extension (to match gas), support a plain D register or Q register
3178 // (without encosing curly braces) as a single or double entry list,
3179 // respectively.
3180 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003181 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003182 int Reg = tryParseRegister();
3183 if (Reg == -1)
3184 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003185 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003186 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003187 if (Res != MatchOperand_Success)
3188 return Res;
3189 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003190 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003191 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003192 break;
3193 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003194 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3195 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003196 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003197 case IndexedLane:
3198 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003199 LaneIndex,
3200 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003201 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003202 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003203 return MatchOperand_Success;
3204 }
3205 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3206 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003207 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003208 if (Res != MatchOperand_Success)
3209 return Res;
3210 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003211 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003212 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003213 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003214 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003215 break;
3216 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003217 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3218 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003219 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3220 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003222 case IndexedLane:
3223 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003224 LaneIndex,
3225 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003226 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003227 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003228 return MatchOperand_Success;
3229 }
3230 Error(S, "vector register expected");
3231 return MatchOperand_ParseFail;
3232 }
3233
3234 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003235 return MatchOperand_NoMatch;
3236
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003237 Parser.Lex(); // Eat '{' token.
3238 SMLoc RegLoc = Parser.getTok().getLoc();
3239
3240 int Reg = tryParseRegister();
3241 if (Reg == -1) {
3242 Error(RegLoc, "register expected");
3243 return MatchOperand_ParseFail;
3244 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003245 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003246 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003247 unsigned FirstReg = Reg;
3248 // The list is of D registers, but we also allow Q regs and just interpret
3249 // them as the two D sub-registers.
3250 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3251 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003252 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3253 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003254 ++Reg;
3255 ++Count;
3256 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003257
3258 SMLoc E;
3259 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003260 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003261
Jim Grosbache891fe82011-11-15 23:19:15 +00003262 while (Parser.getTok().is(AsmToken::Comma) ||
3263 Parser.getTok().is(AsmToken::Minus)) {
3264 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003265 if (!Spacing)
3266 Spacing = 1; // Register range implies a single spaced list.
3267 else if (Spacing == 2) {
3268 Error(Parser.getTok().getLoc(),
3269 "sequential registers in double spaced list");
3270 return MatchOperand_ParseFail;
3271 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003272 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003273 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003274 int EndReg = tryParseRegister();
3275 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003276 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003277 return MatchOperand_ParseFail;
3278 }
3279 // Allow Q regs and just interpret them as the two D sub-registers.
3280 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3281 EndReg = getDRegFromQReg(EndReg) + 1;
3282 // If the register is the same as the start reg, there's nothing
3283 // more to do.
3284 if (Reg == EndReg)
3285 continue;
3286 // The register must be in the same register class as the first.
3287 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003288 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003289 return MatchOperand_ParseFail;
3290 }
3291 // Ranges must go from low to high.
3292 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003293 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003294 return MatchOperand_ParseFail;
3295 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003296 // Parse the lane specifier if present.
3297 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003298 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003299 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3300 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003301 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003302 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003303 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003304 return MatchOperand_ParseFail;
3305 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003306
3307 // Add all the registers in the range to the register list.
3308 Count += EndReg - Reg;
3309 Reg = EndReg;
3310 continue;
3311 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003312 Parser.Lex(); // Eat the comma.
3313 RegLoc = Parser.getTok().getLoc();
3314 int OldReg = Reg;
3315 Reg = tryParseRegister();
3316 if (Reg == -1) {
3317 Error(RegLoc, "register expected");
3318 return MatchOperand_ParseFail;
3319 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003320 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003321 // It's OK to use the enumeration values directly here rather, as the
3322 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003323 //
3324 // The list is of D registers, but we also allow Q regs and just interpret
3325 // them as the two D sub-registers.
3326 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003327 if (!Spacing)
3328 Spacing = 1; // Register range implies a single spaced list.
3329 else if (Spacing == 2) {
3330 Error(RegLoc,
3331 "invalid register in double-spaced list (must be 'D' register')");
3332 return MatchOperand_ParseFail;
3333 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003334 Reg = getDRegFromQReg(Reg);
3335 if (Reg != OldReg + 1) {
3336 Error(RegLoc, "non-contiguous register range");
3337 return MatchOperand_ParseFail;
3338 }
3339 ++Reg;
3340 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003341 // Parse the lane specifier if present.
3342 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003343 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003344 SMLoc LaneLoc = Parser.getTok().getLoc();
3345 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3346 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003347 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003348 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003349 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003350 return MatchOperand_ParseFail;
3351 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003352 continue;
3353 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003354 // Normal D register.
3355 // Figure out the register spacing (single or double) of the list if
3356 // we don't know it already.
3357 if (!Spacing)
3358 Spacing = 1 + (Reg == OldReg + 2);
3359
3360 // Just check that it's contiguous and keep going.
3361 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003362 Error(RegLoc, "non-contiguous register range");
3363 return MatchOperand_ParseFail;
3364 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003365 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003366 // Parse the lane specifier if present.
3367 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003368 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003369 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003370 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003371 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003372 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003373 Error(EndLoc, "mismatched lane index in register list");
3374 return MatchOperand_ParseFail;
3375 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003376 }
3377
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003378 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003379 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003380 return MatchOperand_ParseFail;
3381 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003382 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003383 Parser.Lex(); // Eat '}' token.
3384
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003385 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003386 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003387 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003388 // composite register classes.
3389 if (Count == 2) {
3390 const MCRegisterClass *RC = (Spacing == 1) ?
3391 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3392 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3393 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3394 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003395
Jim Grosbach2f50e922011-12-15 21:44:33 +00003396 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3397 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003398 break;
3399 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003400 // Two-register operands have been converted to the
3401 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003402 if (Count == 2) {
3403 const MCRegisterClass *RC = (Spacing == 1) ?
3404 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3405 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003406 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3407 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003408 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003409 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003410 S, E));
3411 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003412 case IndexedLane:
3413 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003414 LaneIndex,
3415 (Spacing == 2),
3416 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003417 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003418 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003419 return MatchOperand_Success;
3420}
3421
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003422/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003423ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003424parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003425 SMLoc S = Parser.getTok().getLoc();
3426 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003427 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003428
Jiangning Liu288e1af2012-08-02 08:21:27 +00003429 if (Tok.is(AsmToken::Identifier)) {
3430 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003431
Jiangning Liu288e1af2012-08-02 08:21:27 +00003432 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3433 .Case("sy", ARM_MB::SY)
3434 .Case("st", ARM_MB::ST)
3435 .Case("sh", ARM_MB::ISH)
3436 .Case("ish", ARM_MB::ISH)
3437 .Case("shst", ARM_MB::ISHST)
3438 .Case("ishst", ARM_MB::ISHST)
3439 .Case("nsh", ARM_MB::NSH)
3440 .Case("un", ARM_MB::NSH)
3441 .Case("nshst", ARM_MB::NSHST)
3442 .Case("unst", ARM_MB::NSHST)
3443 .Case("osh", ARM_MB::OSH)
3444 .Case("oshst", ARM_MB::OSHST)
3445 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003446
Jiangning Liu288e1af2012-08-02 08:21:27 +00003447 if (Opt == ~0U)
3448 return MatchOperand_NoMatch;
3449
3450 Parser.Lex(); // Eat identifier token.
3451 } else if (Tok.is(AsmToken::Hash) ||
3452 Tok.is(AsmToken::Dollar) ||
3453 Tok.is(AsmToken::Integer)) {
3454 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003455 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003456 SMLoc Loc = Parser.getTok().getLoc();
3457
3458 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003459 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003460 Error(Loc, "illegal expression");
3461 return MatchOperand_ParseFail;
3462 }
3463
3464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3465 if (!CE) {
3466 Error(Loc, "constant expression expected");
3467 return MatchOperand_ParseFail;
3468 }
3469
3470 int Val = CE->getValue();
3471 if (Val & ~0xf) {
3472 Error(Loc, "immediate value out of range");
3473 return MatchOperand_ParseFail;
3474 }
3475
3476 Opt = ARM_MB::RESERVED_0 + Val;
3477 } else
3478 return MatchOperand_ParseFail;
3479
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003480 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003481 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003482}
3483
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003484/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3485ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3486parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3487 SMLoc S = Parser.getTok().getLoc();
3488 const AsmToken &Tok = Parser.getTok();
3489 unsigned Opt;
3490
3491 if (Tok.is(AsmToken::Identifier)) {
3492 StringRef OptStr = Tok.getString();
3493
3494 if (OptStr.lower() == "sy")
3495 Opt = ARM_ISB::SY;
3496 else
3497 return MatchOperand_NoMatch;
3498
3499 Parser.Lex(); // Eat identifier token.
3500 } else if (Tok.is(AsmToken::Hash) ||
3501 Tok.is(AsmToken::Dollar) ||
3502 Tok.is(AsmToken::Integer)) {
3503 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003504 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003505 SMLoc Loc = Parser.getTok().getLoc();
3506
3507 const MCExpr *ISBarrierID;
3508 if (getParser().parseExpression(ISBarrierID)) {
3509 Error(Loc, "illegal expression");
3510 return MatchOperand_ParseFail;
3511 }
3512
3513 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3514 if (!CE) {
3515 Error(Loc, "constant expression expected");
3516 return MatchOperand_ParseFail;
3517 }
3518
3519 int Val = CE->getValue();
3520 if (Val & ~0xf) {
3521 Error(Loc, "immediate value out of range");
3522 return MatchOperand_ParseFail;
3523 }
3524
3525 Opt = ARM_ISB::RESERVED_0 + Val;
3526 } else
3527 return MatchOperand_ParseFail;
3528
3529 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3530 (ARM_ISB::InstSyncBOpt)Opt, S));
3531 return MatchOperand_Success;
3532}
3533
3534
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003535/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003536ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003537parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003538 SMLoc S = Parser.getTok().getLoc();
3539 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003540 if (!Tok.is(AsmToken::Identifier))
3541 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003542 StringRef IFlagsStr = Tok.getString();
3543
Owen Anderson10c5b122011-10-05 17:16:40 +00003544 // An iflags string of "none" is interpreted to mean that none of the AIF
3545 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003546 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003547 if (IFlagsStr != "none") {
3548 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3549 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3550 .Case("a", ARM_PROC::A)
3551 .Case("i", ARM_PROC::I)
3552 .Case("f", ARM_PROC::F)
3553 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003554
Owen Anderson10c5b122011-10-05 17:16:40 +00003555 // If some specific iflag is already set, it means that some letter is
3556 // present more than once, this is not acceptable.
3557 if (Flag == ~0U || (IFlags & Flag))
3558 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003559
Owen Anderson10c5b122011-10-05 17:16:40 +00003560 IFlags |= Flag;
3561 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003562 }
3563
3564 Parser.Lex(); // Eat identifier token.
3565 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3566 return MatchOperand_Success;
3567}
3568
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003569/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003570ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003571parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003572 SMLoc S = Parser.getTok().getLoc();
3573 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003574 if (!Tok.is(AsmToken::Identifier))
3575 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003576 StringRef Mask = Tok.getString();
3577
James Molloy21efa7d2011-09-28 14:21:38 +00003578 if (isMClass()) {
3579 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003580 std::string Name = Mask.lower();
3581 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003582 // Note: in the documentation:
3583 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3584 // for MSR APSR_nzcvq.
3585 // but we do make it an alias here. This is so to get the "mask encoding"
3586 // bits correct on MSR APSR writes.
3587 //
3588 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3589 // should really only be allowed when writing a special register. Note
3590 // they get dropped in the MRS instruction reading a special register as
3591 // the SYSm field is only 8 bits.
3592 //
3593 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3594 // includes the DSP extension but that is not checked.
3595 .Case("apsr", 0x800)
3596 .Case("apsr_nzcvq", 0x800)
3597 .Case("apsr_g", 0x400)
3598 .Case("apsr_nzcvqg", 0xc00)
3599 .Case("iapsr", 0x801)
3600 .Case("iapsr_nzcvq", 0x801)
3601 .Case("iapsr_g", 0x401)
3602 .Case("iapsr_nzcvqg", 0xc01)
3603 .Case("eapsr", 0x802)
3604 .Case("eapsr_nzcvq", 0x802)
3605 .Case("eapsr_g", 0x402)
3606 .Case("eapsr_nzcvqg", 0xc02)
3607 .Case("xpsr", 0x803)
3608 .Case("xpsr_nzcvq", 0x803)
3609 .Case("xpsr_g", 0x403)
3610 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003611 .Case("ipsr", 0x805)
3612 .Case("epsr", 0x806)
3613 .Case("iepsr", 0x807)
3614 .Case("msp", 0x808)
3615 .Case("psp", 0x809)
3616 .Case("primask", 0x810)
3617 .Case("basepri", 0x811)
3618 .Case("basepri_max", 0x812)
3619 .Case("faultmask", 0x813)
3620 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003621 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003622
James Molloy21efa7d2011-09-28 14:21:38 +00003623 if (FlagsVal == ~0U)
3624 return MatchOperand_NoMatch;
3625
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003626 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003627 // basepri, basepri_max and faultmask only valid for V7m.
3628 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003629
James Molloy21efa7d2011-09-28 14:21:38 +00003630 Parser.Lex(); // Eat identifier token.
3631 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3632 return MatchOperand_Success;
3633 }
3634
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003635 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3636 size_t Start = 0, Next = Mask.find('_');
3637 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003638 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003639 if (Next != StringRef::npos)
3640 Flags = Mask.slice(Next+1, Mask.size());
3641
3642 // FlagsVal contains the complete mask:
3643 // 3-0: Mask
3644 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3645 unsigned FlagsVal = 0;
3646
3647 if (SpecReg == "apsr") {
3648 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003649 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003650 .Case("g", 0x4) // same as CPSR_s
3651 .Case("nzcvqg", 0xc) // same as CPSR_fs
3652 .Default(~0U);
3653
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003654 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003655 if (!Flags.empty())
3656 return MatchOperand_NoMatch;
3657 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003658 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003659 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003660 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003661 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3662 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003663 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003664 for (int i = 0, e = Flags.size(); i != e; ++i) {
3665 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3666 .Case("c", 1)
3667 .Case("x", 2)
3668 .Case("s", 4)
3669 .Case("f", 8)
3670 .Default(~0U);
3671
3672 // If some specific flag is already set, it means that some letter is
3673 // present more than once, this is not acceptable.
3674 if (FlagsVal == ~0U || (FlagsVal & Flag))
3675 return MatchOperand_NoMatch;
3676 FlagsVal |= Flag;
3677 }
3678 } else // No match for special register.
3679 return MatchOperand_NoMatch;
3680
Owen Anderson03a173e2011-10-21 18:43:28 +00003681 // Special register without flags is NOT equivalent to "fc" flags.
3682 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3683 // two lines would enable gas compatibility at the expense of breaking
3684 // round-tripping.
3685 //
3686 // if (!FlagsVal)
3687 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003688
3689 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3690 if (SpecReg == "spsr")
3691 FlagsVal |= 16;
3692
3693 Parser.Lex(); // Eat identifier token.
3694 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3695 return MatchOperand_Success;
3696}
3697
Jim Grosbach27c1e252011-07-21 17:23:04 +00003698ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3699parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3700 int Low, int High) {
3701 const AsmToken &Tok = Parser.getTok();
3702 if (Tok.isNot(AsmToken::Identifier)) {
3703 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3704 return MatchOperand_ParseFail;
3705 }
3706 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003707 std::string LowerOp = Op.lower();
3708 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003709 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3710 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3711 return MatchOperand_ParseFail;
3712 }
3713 Parser.Lex(); // Eat shift type token.
3714
3715 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003716 if (Parser.getTok().isNot(AsmToken::Hash) &&
3717 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003718 Error(Parser.getTok().getLoc(), "'#' expected");
3719 return MatchOperand_ParseFail;
3720 }
3721 Parser.Lex(); // Eat hash token.
3722
3723 const MCExpr *ShiftAmount;
3724 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003725 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003726 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003727 Error(Loc, "illegal expression");
3728 return MatchOperand_ParseFail;
3729 }
3730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3731 if (!CE) {
3732 Error(Loc, "constant expression expected");
3733 return MatchOperand_ParseFail;
3734 }
3735 int Val = CE->getValue();
3736 if (Val < Low || Val > High) {
3737 Error(Loc, "immediate value out of range");
3738 return MatchOperand_ParseFail;
3739 }
3740
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003741 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003742
3743 return MatchOperand_Success;
3744}
3745
Jim Grosbach0a547702011-07-22 17:44:50 +00003746ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3747parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3748 const AsmToken &Tok = Parser.getTok();
3749 SMLoc S = Tok.getLoc();
3750 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003751 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003752 return MatchOperand_ParseFail;
3753 }
Tim Northover4d141442013-05-31 15:58:45 +00003754 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003755 .Case("be", 1)
3756 .Case("le", 0)
3757 .Default(-1);
3758 Parser.Lex(); // Eat the token.
3759
3760 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003761 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003762 return MatchOperand_ParseFail;
3763 }
3764 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3765 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003766 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003767 return MatchOperand_Success;
3768}
3769
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003770/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3771/// instructions. Legal values are:
3772/// lsl #n 'n' in [0,31]
3773/// asr #n 'n' in [1,32]
3774/// n == 32 encoded as n == 0.
3775ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3776parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3777 const AsmToken &Tok = Parser.getTok();
3778 SMLoc S = Tok.getLoc();
3779 if (Tok.isNot(AsmToken::Identifier)) {
3780 Error(S, "shift operator 'asr' or 'lsl' expected");
3781 return MatchOperand_ParseFail;
3782 }
3783 StringRef ShiftName = Tok.getString();
3784 bool isASR;
3785 if (ShiftName == "lsl" || ShiftName == "LSL")
3786 isASR = false;
3787 else if (ShiftName == "asr" || ShiftName == "ASR")
3788 isASR = true;
3789 else {
3790 Error(S, "shift operator 'asr' or 'lsl' expected");
3791 return MatchOperand_ParseFail;
3792 }
3793 Parser.Lex(); // Eat the operator.
3794
3795 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003796 if (Parser.getTok().isNot(AsmToken::Hash) &&
3797 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003798 Error(Parser.getTok().getLoc(), "'#' expected");
3799 return MatchOperand_ParseFail;
3800 }
3801 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003802 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003803
3804 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003805 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003806 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003807 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003808 return MatchOperand_ParseFail;
3809 }
3810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3811 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003812 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003813 return MatchOperand_ParseFail;
3814 }
3815
3816 int64_t Val = CE->getValue();
3817 if (isASR) {
3818 // Shift amount must be in [1,32]
3819 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003820 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003821 return MatchOperand_ParseFail;
3822 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003823 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3824 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003825 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003826 return MatchOperand_ParseFail;
3827 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003828 if (Val == 32) Val = 0;
3829 } else {
3830 // Shift amount must be in [1,32]
3831 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003832 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003833 return MatchOperand_ParseFail;
3834 }
3835 }
3836
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003837 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003838
3839 return MatchOperand_Success;
3840}
3841
Jim Grosbach833b9d32011-07-27 20:15:40 +00003842/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3843/// of instructions. Legal values are:
3844/// ror #n 'n' in {0, 8, 16, 24}
3845ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3846parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3847 const AsmToken &Tok = Parser.getTok();
3848 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003849 if (Tok.isNot(AsmToken::Identifier))
3850 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003851 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003852 if (ShiftName != "ror" && ShiftName != "ROR")
3853 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003854 Parser.Lex(); // Eat the operator.
3855
3856 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003857 if (Parser.getTok().isNot(AsmToken::Hash) &&
3858 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003859 Error(Parser.getTok().getLoc(), "'#' expected");
3860 return MatchOperand_ParseFail;
3861 }
3862 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003863 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003864
3865 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003866 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003867 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003868 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003869 return MatchOperand_ParseFail;
3870 }
3871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3872 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003873 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003874 return MatchOperand_ParseFail;
3875 }
3876
3877 int64_t Val = CE->getValue();
3878 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3879 // normally, zero is represented in asm by omitting the rotate operand
3880 // entirely.
3881 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003882 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003883 return MatchOperand_ParseFail;
3884 }
3885
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003886 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003887
3888 return MatchOperand_Success;
3889}
3890
Jim Grosbach864b6092011-07-28 21:34:26 +00003891ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3892parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3893 SMLoc S = Parser.getTok().getLoc();
3894 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003895 if (Parser.getTok().isNot(AsmToken::Hash) &&
3896 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003897 Error(Parser.getTok().getLoc(), "'#' expected");
3898 return MatchOperand_ParseFail;
3899 }
3900 Parser.Lex(); // Eat hash token.
3901
3902 const MCExpr *LSBExpr;
3903 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003904 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003905 Error(E, "malformed immediate expression");
3906 return MatchOperand_ParseFail;
3907 }
3908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3909 if (!CE) {
3910 Error(E, "'lsb' operand must be an immediate");
3911 return MatchOperand_ParseFail;
3912 }
3913
3914 int64_t LSB = CE->getValue();
3915 // The LSB must be in the range [0,31]
3916 if (LSB < 0 || LSB > 31) {
3917 Error(E, "'lsb' operand must be in the range [0,31]");
3918 return MatchOperand_ParseFail;
3919 }
3920 E = Parser.getTok().getLoc();
3921
3922 // Expect another immediate operand.
3923 if (Parser.getTok().isNot(AsmToken::Comma)) {
3924 Error(Parser.getTok().getLoc(), "too few operands");
3925 return MatchOperand_ParseFail;
3926 }
3927 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003928 if (Parser.getTok().isNot(AsmToken::Hash) &&
3929 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003930 Error(Parser.getTok().getLoc(), "'#' expected");
3931 return MatchOperand_ParseFail;
3932 }
3933 Parser.Lex(); // Eat hash token.
3934
3935 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003936 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003937 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003938 Error(E, "malformed immediate expression");
3939 return MatchOperand_ParseFail;
3940 }
3941 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3942 if (!CE) {
3943 Error(E, "'width' operand must be an immediate");
3944 return MatchOperand_ParseFail;
3945 }
3946
3947 int64_t Width = CE->getValue();
3948 // The LSB must be in the range [1,32-lsb]
3949 if (Width < 1 || Width > 32 - LSB) {
3950 Error(E, "'width' operand must be in the range [1,32-lsb]");
3951 return MatchOperand_ParseFail;
3952 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003953
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003954 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003955
3956 return MatchOperand_Success;
3957}
3958
Jim Grosbachd3595712011-08-03 23:50:40 +00003959ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3960parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3961 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003962 // postidx_reg := '+' register {, shift}
3963 // | '-' register {, shift}
3964 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003965
3966 // This method must return MatchOperand_NoMatch without consuming any tokens
3967 // in the case where there is no match, as other alternatives take other
3968 // parse methods.
3969 AsmToken Tok = Parser.getTok();
3970 SMLoc S = Tok.getLoc();
3971 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003972 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003973 if (Tok.is(AsmToken::Plus)) {
3974 Parser.Lex(); // Eat the '+' token.
3975 haveEaten = true;
3976 } else if (Tok.is(AsmToken::Minus)) {
3977 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003978 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003979 haveEaten = true;
3980 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003981
3982 SMLoc E = Parser.getTok().getEndLoc();
3983 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003984 if (Reg == -1) {
3985 if (!haveEaten)
3986 return MatchOperand_NoMatch;
3987 Error(Parser.getTok().getLoc(), "register expected");
3988 return MatchOperand_ParseFail;
3989 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003990
Jim Grosbachc320c852011-08-05 21:28:30 +00003991 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3992 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003993 if (Parser.getTok().is(AsmToken::Comma)) {
3994 Parser.Lex(); // Eat the ','.
3995 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3996 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003997
3998 // FIXME: Only approximates end...may include intervening whitespace.
3999 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004000 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004001
4002 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4003 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004004
4005 return MatchOperand_Success;
4006}
4007
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004008ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4009parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4010 // Check for a post-index addressing register operand. Specifically:
4011 // am3offset := '+' register
4012 // | '-' register
4013 // | register
4014 // | # imm
4015 // | # + imm
4016 // | # - imm
4017
4018 // This method must return MatchOperand_NoMatch without consuming any tokens
4019 // in the case where there is no match, as other alternatives take other
4020 // parse methods.
4021 AsmToken Tok = Parser.getTok();
4022 SMLoc S = Tok.getLoc();
4023
4024 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004025 if (Parser.getTok().is(AsmToken::Hash) ||
4026 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004027 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004028 // Explicitly look for a '-', as we need to encode negative zero
4029 // differently.
4030 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4031 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004032 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004033 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004034 return MatchOperand_ParseFail;
4035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4036 if (!CE) {
4037 Error(S, "constant expression expected");
4038 return MatchOperand_ParseFail;
4039 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004040 // Negative zero is encoded as the flag value INT32_MIN.
4041 int32_t Val = CE->getValue();
4042 if (isNegative && Val == 0)
4043 Val = INT32_MIN;
4044
4045 Operands.push_back(
4046 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4047
4048 return MatchOperand_Success;
4049 }
4050
4051
4052 bool haveEaten = false;
4053 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004054 if (Tok.is(AsmToken::Plus)) {
4055 Parser.Lex(); // Eat the '+' token.
4056 haveEaten = true;
4057 } else if (Tok.is(AsmToken::Minus)) {
4058 Parser.Lex(); // Eat the '-' token.
4059 isAdd = false;
4060 haveEaten = true;
4061 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004062
4063 Tok = Parser.getTok();
4064 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004065 if (Reg == -1) {
4066 if (!haveEaten)
4067 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004068 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004069 return MatchOperand_ParseFail;
4070 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004071
4072 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004073 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004074
4075 return MatchOperand_Success;
4076}
4077
Jim Grosbach7db8d692011-09-08 22:07:06 +00004078/// cvtT2LdrdPre - Convert parsed operands to MCInst.
4079/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4080/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004081void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004082cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00004083 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4084 // Rt, Rt2
4085 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4086 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4087 // Create a writeback register dummy placeholder.
4088 Inst.addOperand(MCOperand::CreateReg(0));
4089 // addr
4090 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4091 // pred
4092 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00004093}
4094
4095/// cvtT2StrdPre - Convert parsed operands to MCInst.
4096/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4097/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004098void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004099cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00004100 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4101 // Create a writeback register dummy placeholder.
4102 Inst.addOperand(MCOperand::CreateReg(0));
4103 // Rt, Rt2
4104 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4105 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4106 // addr
4107 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4108 // pred
4109 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00004110}
4111
Jim Grosbachc086f682011-09-08 00:39:19 +00004112/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4113/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4114/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004115void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004116cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00004117 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4118 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4119
4120 // Create a writeback register dummy placeholder.
4121 Inst.addOperand(MCOperand::CreateImm(0));
4122
4123 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4124 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00004125}
4126
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004127/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4128/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4129/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004130void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004131cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004132 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4133 // Create a writeback register dummy placeholder.
4134 Inst.addOperand(MCOperand::CreateImm(0));
4135 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4136 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4137 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004138}
4139
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004140/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004141/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4142/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004143void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004144cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004145 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4147
4148 // Create a writeback register dummy placeholder.
4149 Inst.addOperand(MCOperand::CreateImm(0));
4150
Jim Grosbachd3595712011-08-03 23:50:40 +00004151 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004152 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004153}
4154
Owen Anderson16d33f32011-08-26 20:43:14 +00004155/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4156/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4157/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004158void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004159cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00004160 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4161 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4162
4163 // Create a writeback register dummy placeholder.
4164 Inst.addOperand(MCOperand::CreateImm(0));
4165
4166 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4167 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00004168}
4169
4170
Jim Grosbachd564bf32011-08-11 19:22:40 +00004171/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4172/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4173/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004174void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004175cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00004176 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4177 // Create a writeback register dummy placeholder.
4178 Inst.addOperand(MCOperand::CreateImm(0));
4179 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4180 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4181 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00004182}
4183
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004184/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004185/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4186/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004187void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004188cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004189 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4190 // Create a writeback register dummy placeholder.
4191 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00004192 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4193 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4194 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004195}
4196
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004197/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4198/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4199/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004200void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004201cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004202 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4203 // Create a writeback register dummy placeholder.
4204 Inst.addOperand(MCOperand::CreateImm(0));
4205 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4206 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4207 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004208}
4209
Jim Grosbachd3595712011-08-03 23:50:40 +00004210/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4211/// 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 +00004214cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004215 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4216 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004217 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004218 // Create a writeback register dummy placeholder.
4219 Inst.addOperand(MCOperand::CreateImm(0));
4220 // addr
4221 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4222 // offset
4223 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4224 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004225 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004226}
4227
Jim Grosbachd3595712011-08-03 23:50:40 +00004228/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004229/// 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 +00004232cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004233 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4234 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004235 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004236 // Create a writeback register dummy placeholder.
4237 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004238 // 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 Grosbachd3595712011-08-03 23:50:40 +00004246/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004247/// 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 +00004250cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004251 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004252 // Create a writeback register dummy placeholder.
4253 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004254 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004255 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004256 // addr
4257 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4258 // offset
4259 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4260 // pred
4261 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004262}
4263
4264/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4265/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4266/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004267void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004268cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004269 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4270 // Create a writeback register dummy placeholder.
4271 Inst.addOperand(MCOperand::CreateImm(0));
4272 // Rt
4273 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4274 // addr
4275 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4276 // offset
4277 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4278 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004279 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004280}
4281
Jim Grosbach5b96b802011-08-10 20:29:19 +00004282/// cvtLdrdPre - Convert parsed operands to MCInst.
4283/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4284/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004285void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004286cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004287 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4288 // Rt, Rt2
4289 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4290 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4291 // Create a writeback register dummy placeholder.
4292 Inst.addOperand(MCOperand::CreateImm(0));
4293 // addr
4294 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4295 // pred
4296 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004297}
4298
Jim Grosbacheb09f492011-08-11 20:28:23 +00004299/// cvtStrdPre - Convert parsed operands to MCInst.
4300/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4301/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004302void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004303cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004304 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4305 // Create a writeback register dummy placeholder.
4306 Inst.addOperand(MCOperand::CreateImm(0));
4307 // Rt, Rt2
4308 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4309 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4310 // addr
4311 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4312 // pred
4313 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004314}
4315
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004316/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4317/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4318/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004319void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004320cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004321 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4322 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4323 // Create a writeback register dummy placeholder.
4324 Inst.addOperand(MCOperand::CreateImm(0));
4325 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4326 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004327}
4328
Chad Rosier5eec49f2012-08-30 23:00:00 +00004329/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004330/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4331/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004332void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004333cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004334 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004335 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4336 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004337 // If we have a three-operand form, make sure to set Rn to be the operand
4338 // that isn't the same as Rd.
4339 unsigned RegOp = 4;
4340 if (Operands.size() == 6 &&
4341 ((ARMOperand*)Operands[4])->getReg() ==
4342 ((ARMOperand*)Operands[3])->getReg())
4343 RegOp = 5;
4344 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4345 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004346 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004347}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004348
Chad Rosier98cfa102012-08-31 00:03:31 +00004349void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004350cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004351 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4352 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004353 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004354 // Create a writeback register dummy placeholder.
4355 Inst.addOperand(MCOperand::CreateImm(0));
4356 // Vn
4357 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4358 // pred
4359 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004360}
4361
Chad Rosier98cfa102012-08-31 00:03:31 +00004362void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004363cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004364 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4365 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004366 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004367 // Create a writeback register dummy placeholder.
4368 Inst.addOperand(MCOperand::CreateImm(0));
4369 // Vn
4370 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4371 // Vm
4372 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4373 // pred
4374 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004375}
4376
Chad Rosier98cfa102012-08-31 00:03:31 +00004377void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004378cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004379 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4380 // Create a writeback register dummy placeholder.
4381 Inst.addOperand(MCOperand::CreateImm(0));
4382 // Vn
4383 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4384 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004385 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004386 // pred
4387 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004388}
4389
Chad Rosier98cfa102012-08-31 00:03:31 +00004390void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004391cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004392 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4393 // Create a writeback register dummy placeholder.
4394 Inst.addOperand(MCOperand::CreateImm(0));
4395 // Vn
4396 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4397 // Vm
4398 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4399 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004400 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004401 // pred
4402 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004403}
4404
Bill Wendlinge18980a2010-11-06 22:36:58 +00004405/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004407bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004408parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004409 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004410 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004411 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004412 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004413 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004414
Sean Callanan936b0d32010-01-19 21:44:56 +00004415 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004416 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004417 if (BaseRegNum == -1)
4418 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004419
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004420 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004421 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004422 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4423 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004424 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004425
Jim Grosbachd3595712011-08-03 23:50:40 +00004426 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004427 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004428 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004429
Jim Grosbachd3595712011-08-03 23:50:40 +00004430 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004431 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004432
Jim Grosbach40700e02011-09-19 18:42:21 +00004433 // If there's a pre-indexing writeback marker, '!', just add it as a token
4434 // operand. It's rather odd, but syntactically valid.
4435 if (Parser.getTok().is(AsmToken::Exclaim)) {
4436 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4437 Parser.Lex(); // Eat the '!'.
4438 }
4439
Jim Grosbachd3595712011-08-03 23:50:40 +00004440 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004441 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004442
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004443 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4444 "Lost colon or comma in memory operand?!");
4445 if (Tok.is(AsmToken::Comma)) {
4446 Parser.Lex(); // Eat the comma.
4447 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004448
Jim Grosbacha95ec992011-10-11 17:29:55 +00004449 // If we have a ':', it's an alignment specifier.
4450 if (Parser.getTok().is(AsmToken::Colon)) {
4451 Parser.Lex(); // Eat the ':'.
4452 E = Parser.getTok().getLoc();
4453
4454 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004455 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004456 return true;
4457
4458 // The expression has to be a constant. Memory references with relocations
4459 // don't come through here, as they use the <label> forms of the relevant
4460 // instructions.
4461 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4462 if (!CE)
4463 return Error (E, "constant expression expected");
4464
4465 unsigned Align = 0;
4466 switch (CE->getValue()) {
4467 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004468 return Error(E,
4469 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4470 case 16: Align = 2; break;
4471 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004472 case 64: Align = 8; break;
4473 case 128: Align = 16; break;
4474 case 256: Align = 32; break;
4475 }
4476
4477 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004478 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004479 return Error(Parser.getTok().getLoc(), "']' expected");
4480 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004481 Parser.Lex(); // Eat right bracket token.
4482
4483 // Don't worry about range checking the value here. That's handled by
4484 // the is*() predicates.
4485 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4486 ARM_AM::no_shift, 0, Align,
4487 false, S, E));
4488
4489 // If there's a pre-indexing writeback marker, '!', just add it as a token
4490 // operand.
4491 if (Parser.getTok().is(AsmToken::Exclaim)) {
4492 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4493 Parser.Lex(); // Eat the '!'.
4494 }
4495
4496 return false;
4497 }
4498
4499 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004500 // offset. Be friendly and also accept a plain integer (without a leading
4501 // hash) for gas compatibility.
4502 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004503 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004504 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004505 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004506 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004507 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004508
Owen Anderson967674d2011-08-29 19:36:44 +00004509 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004510 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004511 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004512 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004513
4514 // The expression has to be a constant. Memory references with relocations
4515 // don't come through here, as they use the <label> forms of the relevant
4516 // instructions.
4517 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4518 if (!CE)
4519 return Error (E, "constant expression expected");
4520
Owen Anderson967674d2011-08-29 19:36:44 +00004521 // If the constant was #-0, represent it as INT32_MIN.
4522 int32_t Val = CE->getValue();
4523 if (isNegative && Val == 0)
4524 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4525
Jim Grosbachd3595712011-08-03 23:50:40 +00004526 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004527 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004528 return Error(Parser.getTok().getLoc(), "']' expected");
4529 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004530 Parser.Lex(); // Eat right bracket token.
4531
4532 // Don't worry about range checking the value here. That's handled by
4533 // the is*() predicates.
4534 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004535 ARM_AM::no_shift, 0, 0,
4536 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004537
4538 // If there's a pre-indexing writeback marker, '!', just add it as a token
4539 // operand.
4540 if (Parser.getTok().is(AsmToken::Exclaim)) {
4541 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4542 Parser.Lex(); // Eat the '!'.
4543 }
4544
4545 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004546 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004547
4548 // The register offset is optionally preceded by a '+' or '-'
4549 bool isNegative = false;
4550 if (Parser.getTok().is(AsmToken::Minus)) {
4551 isNegative = true;
4552 Parser.Lex(); // Eat the '-'.
4553 } else if (Parser.getTok().is(AsmToken::Plus)) {
4554 // Nothing to do.
4555 Parser.Lex(); // Eat the '+'.
4556 }
4557
4558 E = Parser.getTok().getLoc();
4559 int OffsetRegNum = tryParseRegister();
4560 if (OffsetRegNum == -1)
4561 return Error(E, "register expected");
4562
4563 // If there's a shift operator, handle it.
4564 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004565 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004566 if (Parser.getTok().is(AsmToken::Comma)) {
4567 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004568 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004569 return true;
4570 }
4571
4572 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004573 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004574 return Error(Parser.getTok().getLoc(), "']' expected");
4575 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004576 Parser.Lex(); // Eat right bracket token.
4577
4578 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004579 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004580 S, E));
4581
Jim Grosbachc320c852011-08-05 21:28:30 +00004582 // If there's a pre-indexing writeback marker, '!', just add it as a token
4583 // operand.
4584 if (Parser.getTok().is(AsmToken::Exclaim)) {
4585 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4586 Parser.Lex(); // Eat the '!'.
4587 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004588
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004589 return false;
4590}
4591
Jim Grosbachd3595712011-08-03 23:50:40 +00004592/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004593/// ( lsl | lsr | asr | ror ) , # shift_amount
4594/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004595/// return true if it parses a shift otherwise it returns false.
4596bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4597 unsigned &Amount) {
4598 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004599 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004600 if (Tok.isNot(AsmToken::Identifier))
4601 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004602 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004603 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4604 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004605 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004606 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004607 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004608 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004609 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004610 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004611 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004612 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004613 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004614 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004615 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004616 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004617
Jim Grosbachd3595712011-08-03 23:50:40 +00004618 // rrx stands alone.
4619 Amount = 0;
4620 if (St != ARM_AM::rrx) {
4621 Loc = Parser.getTok().getLoc();
4622 // A '#' and a shift amount.
4623 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004624 if (HashTok.isNot(AsmToken::Hash) &&
4625 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004626 return Error(HashTok.getLoc(), "'#' expected");
4627 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004628
Jim Grosbachd3595712011-08-03 23:50:40 +00004629 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004630 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004631 return true;
4632 // Range check the immediate.
4633 // lsl, ror: 0 <= imm <= 31
4634 // lsr, asr: 0 <= imm <= 32
4635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4636 if (!CE)
4637 return Error(Loc, "shift amount must be an immediate");
4638 int64_t Imm = CE->getValue();
4639 if (Imm < 0 ||
4640 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4641 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4642 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004643 // If <ShiftTy> #0, turn it into a no_shift.
4644 if (Imm == 0)
4645 St = ARM_AM::lsl;
4646 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4647 if (Imm == 32)
4648 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004649 Amount = Imm;
4650 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004651
4652 return false;
4653}
4654
Jim Grosbache7fbce72011-10-03 23:38:36 +00004655/// parseFPImm - A floating point immediate expression operand.
4656ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4657parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004658 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004659 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004660 // integer only.
4661 //
4662 // This routine still creates a generic Immediate operand, containing
4663 // a bitcast of the 64-bit floating point value. The various operands
4664 // that accept floats can check whether the value is valid for them
4665 // via the standard is*() predicates.
4666
Jim Grosbache7fbce72011-10-03 23:38:36 +00004667 SMLoc S = Parser.getTok().getLoc();
4668
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004669 if (Parser.getTok().isNot(AsmToken::Hash) &&
4670 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004671 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004672
4673 // Disambiguate the VMOV forms that can accept an FP immediate.
4674 // vmov.f32 <sreg>, #imm
4675 // vmov.f64 <dreg>, #imm
4676 // vmov.f32 <dreg>, #imm @ vector f32x2
4677 // vmov.f32 <qreg>, #imm @ vector f32x4
4678 //
4679 // There are also the NEON VMOV instructions which expect an
4680 // integer constant. Make sure we don't try to parse an FPImm
4681 // for these:
4682 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4683 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4684 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4685 TyOp->getToken() != ".f64"))
4686 return MatchOperand_NoMatch;
4687
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004688 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004689
4690 // Handle negation, as that still comes through as a separate token.
4691 bool isNegative = false;
4692 if (Parser.getTok().is(AsmToken::Minus)) {
4693 isNegative = true;
4694 Parser.Lex();
4695 }
4696 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004697 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004698 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004699 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004700 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4701 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004702 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004703 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004704 Operands.push_back(ARMOperand::CreateImm(
4705 MCConstantExpr::Create(IntVal, getContext()),
4706 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004707 return MatchOperand_Success;
4708 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004709 // Also handle plain integers. Instructions which allow floating point
4710 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004711 if (Tok.is(AsmToken::Integer)) {
4712 int64_t Val = Tok.getIntVal();
4713 Parser.Lex(); // Eat the token.
4714 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004715 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004716 return MatchOperand_ParseFail;
4717 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004718 double RealVal = ARM_AM::getFPImmFloat(Val);
4719 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4720 Operands.push_back(ARMOperand::CreateImm(
4721 MCConstantExpr::Create(Val, getContext()), S,
4722 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004723 return MatchOperand_Success;
4724 }
4725
Jim Grosbach235c8d22012-01-19 02:47:30 +00004726 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004727 return MatchOperand_ParseFail;
4728}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004729
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004730/// Parse a arm instruction operand. For now this parses the operand regardless
4731/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004732bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004733 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004734 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004735
4736 // Check if the current operand has a custom associated parser, if so, try to
4737 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004738 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4739 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004740 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004741 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4742 // there was a match, but an error occurred, in which case, just return that
4743 // the operand parsing failed.
4744 if (ResTy == MatchOperand_ParseFail)
4745 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004746
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004747 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004748 default:
4749 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004750 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004751 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004752 // If we've seen a branch mnemonic, the next operand must be a label. This
4753 // is true even if the label is a register name. So "br r1" means branch to
4754 // label "r1".
4755 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4756 if (!ExpectLabel) {
4757 if (!tryParseRegisterWithWriteBack(Operands))
4758 return false;
4759 int Res = tryParseShiftRegister(Operands);
4760 if (Res == 0) // success
4761 return false;
4762 else if (Res == -1) // irrecoverable error
4763 return true;
4764 // If this is VMRS, check for the apsr_nzcv operand.
4765 if (Mnemonic == "vmrs" &&
4766 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4767 S = Parser.getTok().getLoc();
4768 Parser.Lex();
4769 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4770 return false;
4771 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004772 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004773
4774 // Fall though for the Identifier case that is not a register or a
4775 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004776 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004777 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004778 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004779 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004780 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004781 // This was not a register so parse other operands that start with an
4782 // identifier (like labels) as expressions and create them as immediates.
4783 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004784 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004785 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004786 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004787 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004788 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4789 return false;
4790 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004791 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004792 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004793 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004794 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004795 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004796 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004797 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004798 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004799 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004800
4801 if (Parser.getTok().isNot(AsmToken::Colon)) {
4802 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4803 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004804 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004805 return true;
4806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4807 if (CE) {
4808 int32_t Val = CE->getValue();
4809 if (isNegative && Val == 0)
4810 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4811 }
4812 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4813 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004814
4815 // There can be a trailing '!' on operands that we want as a separate
4816 // '!' Token operand. Handle that here. For example, the compatibilty
4817 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4818 if (Parser.getTok().is(AsmToken::Exclaim)) {
4819 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4820 Parser.getTok().getLoc()));
4821 Parser.Lex(); // Eat exclaim token
4822 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004823 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004824 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004825 // w/ a ':' after the '#', it's just like a plain ':'.
4826 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004827 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004828 case AsmToken::Colon: {
4829 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004830 // FIXME: Check it's an expression prefix,
4831 // e.g. (FOO - :lower16:BAR) isn't legal.
4832 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004833 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004834 return true;
4835
Evan Cheng965b3c72011-01-13 07:58:56 +00004836 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004837 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004838 return true;
4839
Evan Cheng965b3c72011-01-13 07:58:56 +00004840 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004841 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004842 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004843 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004844 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004845 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004846 }
4847}
4848
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004849// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004850// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004851bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004852 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004853
4854 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004855 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004856 Parser.Lex(); // Eat ':'
4857
4858 if (getLexer().isNot(AsmToken::Identifier)) {
4859 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4860 return true;
4861 }
4862
4863 StringRef IDVal = Parser.getTok().getIdentifier();
4864 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004865 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004866 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004867 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004868 } else {
4869 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4870 return true;
4871 }
4872 Parser.Lex();
4873
4874 if (getLexer().isNot(AsmToken::Colon)) {
4875 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4876 return true;
4877 }
4878 Parser.Lex(); // Eat the last ':'
4879 return false;
4880}
4881
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004882/// \brief Given a mnemonic, split out possible predication code and carry
4883/// setting letters to form a canonical mnemonic and flags.
4884//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004885// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004886// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004887StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004888 unsigned &PredicationCode,
4889 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004890 unsigned &ProcessorIMod,
4891 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004892 PredicationCode = ARMCC::AL;
4893 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004894 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004895
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004896 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004897 //
4898 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004899 if ((Mnemonic == "movs" && isThumb()) ||
4900 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4901 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4902 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4903 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004904 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004905 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4906 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004907 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4908 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004909 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004910
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004911 // First, split out any predication code. Ignore mnemonics we know aren't
4912 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004913 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004914 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004915 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004916 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004917 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4918 .Case("eq", ARMCC::EQ)
4919 .Case("ne", ARMCC::NE)
4920 .Case("hs", ARMCC::HS)
4921 .Case("cs", ARMCC::HS)
4922 .Case("lo", ARMCC::LO)
4923 .Case("cc", ARMCC::LO)
4924 .Case("mi", ARMCC::MI)
4925 .Case("pl", ARMCC::PL)
4926 .Case("vs", ARMCC::VS)
4927 .Case("vc", ARMCC::VC)
4928 .Case("hi", ARMCC::HI)
4929 .Case("ls", ARMCC::LS)
4930 .Case("ge", ARMCC::GE)
4931 .Case("lt", ARMCC::LT)
4932 .Case("gt", ARMCC::GT)
4933 .Case("le", ARMCC::LE)
4934 .Case("al", ARMCC::AL)
4935 .Default(~0U);
4936 if (CC != ~0U) {
4937 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4938 PredicationCode = CC;
4939 }
Bill Wendling193961b2010-10-29 23:50:21 +00004940 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004941
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004942 // Next, determine if we have a carry setting bit. We explicitly ignore all
4943 // the instructions we know end in 's'.
4944 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004945 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004946 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4947 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4948 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004949 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004950 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004951 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004952 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004953 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004954 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004955 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4956 CarrySetting = true;
4957 }
4958
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004959 // The "cps" instruction can have a interrupt mode operand which is glued into
4960 // the mnemonic. Check if this is the case, split it and parse the imod op
4961 if (Mnemonic.startswith("cps")) {
4962 // Split out any imod code.
4963 unsigned IMod =
4964 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4965 .Case("ie", ARM_PROC::IE)
4966 .Case("id", ARM_PROC::ID)
4967 .Default(~0U);
4968 if (IMod != ~0U) {
4969 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4970 ProcessorIMod = IMod;
4971 }
4972 }
4973
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004974 // The "it" instruction has the condition mask on the end of the mnemonic.
4975 if (Mnemonic.startswith("it")) {
4976 ITMask = Mnemonic.slice(2, Mnemonic.size());
4977 Mnemonic = Mnemonic.slice(0, 2);
4978 }
4979
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004980 return Mnemonic;
4981}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004982
4983/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4984/// inclusion of carry set or predication code operands.
4985//
4986// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004987void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004988getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004989 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004990 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4991 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004992 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004993 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004994 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004995 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004996 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004997 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004998 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004999 Mnemonic == "mla" || Mnemonic == "smlal" ||
5000 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005001 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005002 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005003 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005004
Tim Northover2c45a382013-06-26 16:52:40 +00005005 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5006 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
5007 Mnemonic == "trap" || Mnemonic == "setend" ||
5008 Mnemonic.startswith("cps")) {
5009 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005010 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005011 } else if (!isThumb()) {
5012 // Some instructions are only predicable in Thumb mode
5013 CanAcceptPredicationCode
5014 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5015 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5016 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5017 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5018 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5019 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5020 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5021 } else if (isThumbOne()) {
5022 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005023 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005024 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005025}
5026
Jim Grosbach7283da92011-08-16 21:12:37 +00005027bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5028 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005029 // FIXME: This is all horribly hacky. We really need a better way to deal
5030 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005031
5032 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5033 // another does not. Specifically, the MOVW instruction does not. So we
5034 // special case it here and remove the defaulted (non-setting) cc_out
5035 // operand if that's the instruction we're trying to match.
5036 //
5037 // We do this as post-processing of the explicit operands rather than just
5038 // conditionally adding the cc_out in the first place because we need
5039 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005040 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00005041 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5042 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5043 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5044 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005045
5046 // Register-register 'add' for thumb does not have a cc_out operand
5047 // when there are only two register operands.
5048 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5049 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5050 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5051 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5052 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005053 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005054 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5055 // have to check the immediate range here since Thumb2 has a variant
5056 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005057 if (((isThumb() && Mnemonic == "add") ||
5058 (isThumbTwo() && Mnemonic == "sub")) &&
5059 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005060 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5061 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5062 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005063 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005064 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005065 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005066 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005067 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5068 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005069 // selecting via the generic "add" mnemonic, so to know that we
5070 // should remove the cc_out operand, we have to explicitly check that
5071 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005072 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5073 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005074 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5075 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5076 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5077 // Nest conditions rather than one big 'if' statement for readability.
5078 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005079 // If both registers are low, we're in an IT block, and the immediate is
5080 // in range, we should use encoding T1 instead, which has a cc_out.
5081 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005082 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005083 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5084 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5085 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005086 // Check against T3. If the second register is the PC, this is an
5087 // alternate form of ADR, which uses encoding T4, so check for that too.
5088 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5089 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5090 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005091
5092 // Otherwise, we use encoding T4, which does not have a cc_out
5093 // operand.
5094 return true;
5095 }
5096
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005097 // The thumb2 multiply instruction doesn't have a CCOut register, so
5098 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5099 // use the 16-bit encoding or not.
5100 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5101 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5102 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5103 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5104 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5105 // If the registers aren't low regs, the destination reg isn't the
5106 // same as one of the source regs, or the cc_out operand is zero
5107 // outside of an IT block, we have to use the 32-bit encoding, so
5108 // remove the cc_out operand.
5109 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5110 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005111 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005112 !inITBlock() ||
5113 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5114 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5115 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5116 static_cast<ARMOperand*>(Operands[4])->getReg())))
5117 return true;
5118
Jim Grosbachefa7e952011-11-15 19:55:16 +00005119 // Also check the 'mul' syntax variant that doesn't specify an explicit
5120 // destination register.
5121 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5122 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5123 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5124 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5125 // If the registers aren't low regs or the cc_out operand is zero
5126 // outside of an IT block, we have to use the 32-bit encoding, so
5127 // remove the cc_out operand.
5128 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5129 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5130 !inITBlock()))
5131 return true;
5132
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005133
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005134
Jim Grosbach4b701af2011-08-24 21:42:27 +00005135 // Register-register 'add/sub' for thumb does not have a cc_out operand
5136 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5137 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5138 // right, this will result in better diagnostics (which operand is off)
5139 // anyway.
5140 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5141 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005142 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5143 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005144 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5145 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5146 (Operands.size() == 6 &&
5147 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005148 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005149
Jim Grosbach7283da92011-08-16 21:12:37 +00005150 return false;
5151}
5152
Jim Grosbach12952fe2011-11-11 23:08:10 +00005153static bool isDataTypeToken(StringRef Tok) {
5154 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5155 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5156 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5157 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5158 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5159 Tok == ".f" || Tok == ".d";
5160}
5161
5162// FIXME: This bit should probably be handled via an explicit match class
5163// in the .td files that matches the suffix instead of having it be
5164// a literal string token the way it is now.
5165static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5166 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5167}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005168static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5169 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005170/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005171bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5172 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005173 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005174 // Apply mnemonic aliases before doing anything else, as the destination
5175 // mnemnonic may include suffices and we want to handle them normally.
5176 // The generic tblgen'erated code does this later, at the start of
5177 // MatchInstructionImpl(), but that's too late for aliases that include
5178 // any sort of suffix.
5179 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005180 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5181 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005182
Jim Grosbachab5830e2011-12-14 02:16:11 +00005183 // First check for the ARM-specific .req directive.
5184 if (Parser.getTok().is(AsmToken::Identifier) &&
5185 Parser.getTok().getIdentifier() == ".req") {
5186 parseDirectiveReq(Name, NameLoc);
5187 // We always return 'error' for this, as we're done with this
5188 // statement and don't need to match the 'instruction."
5189 return true;
5190 }
5191
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005192 // Create the leading tokens for the mnemonic, split by '.' characters.
5193 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005194 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005195
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005196 // Split out the predication code and carry setting flag from the mnemonic.
5197 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005198 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005199 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005200 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005201 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005202 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005203
Jim Grosbach1c171b12011-08-25 17:23:55 +00005204 // In Thumb1, only the branch (B) instruction can be predicated.
5205 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005206 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005207 return Error(NameLoc, "conditional execution not supported in Thumb1");
5208 }
5209
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005210 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5211
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005212 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5213 // is the mask as it will be for the IT encoding if the conditional
5214 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5215 // where the conditional bit0 is zero, the instruction post-processing
5216 // will adjust the mask accordingly.
5217 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005218 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5219 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005220 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005221 return Error(Loc, "too many conditions on IT instruction");
5222 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005223 unsigned Mask = 8;
5224 for (unsigned i = ITMask.size(); i != 0; --i) {
5225 char pos = ITMask[i - 1];
5226 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005227 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005228 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005229 }
5230 Mask >>= 1;
5231 if (ITMask[i - 1] == 't')
5232 Mask |= 8;
5233 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005234 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005235 }
5236
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005237 // FIXME: This is all a pretty gross hack. We should automatically handle
5238 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005239
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005240 // Next, add the CCOut and ConditionCode operands, if needed.
5241 //
5242 // For mnemonics which can ever incorporate a carry setting bit or predication
5243 // code, our matching model involves us always generating CCOut and
5244 // ConditionCode operands to match the mnemonic "as written" and then we let
5245 // the matcher deal with finding the right instruction or generating an
5246 // appropriate error.
5247 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005248 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005249
Jim Grosbach03a8a162011-07-14 22:04:21 +00005250 // If we had a carry-set on an instruction that can't do that, issue an
5251 // error.
5252 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005253 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005254 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005255 "' can not set flags, but 's' suffix specified");
5256 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005257 // If we had a predication code on an instruction that can't do that, issue an
5258 // error.
5259 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005260 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005261 return Error(NameLoc, "instruction '" + Mnemonic +
5262 "' is not predicable, but condition code specified");
5263 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005264
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005265 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005266 if (CanAcceptCarrySet) {
5267 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005268 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005269 Loc));
5270 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005271
5272 // Add the predication code operand, if necessary.
5273 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005274 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5275 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005276 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005277 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005278 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005279
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005280 // Add the processor imod operand, if necessary.
5281 if (ProcessorIMod) {
5282 Operands.push_back(ARMOperand::CreateImm(
5283 MCConstantExpr::Create(ProcessorIMod, getContext()),
5284 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005285 }
5286
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005287 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005288 while (Next != StringRef::npos) {
5289 Start = Next;
5290 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005291 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005292
Jim Grosbach12952fe2011-11-11 23:08:10 +00005293 // Some NEON instructions have an optional datatype suffix that is
5294 // completely ignored. Check for that.
5295 if (isDataTypeToken(ExtraToken) &&
5296 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5297 continue;
5298
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005299 // For for ARM mode generate an error if the .n qualifier is used.
5300 if (ExtraToken == ".n" && !isThumb()) {
5301 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5302 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5303 "arm mode");
5304 }
5305
5306 // The .n qualifier is always discarded as that is what the tables
5307 // and matcher expect. In ARM mode the .w qualifier has no effect,
5308 // so discard it to avoid errors that can be caused by the matcher.
5309 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005310 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5311 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5312 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005313 }
5314
5315 // Read the remaining operands.
5316 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005317 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005318 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005319 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005320 return true;
5321 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005322
5323 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005324 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005325
5326 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005327 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005328 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005329 return true;
5330 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005331 }
5332 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005333
Chris Lattnera2a9d162010-09-11 16:18:25 +00005334 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005335 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005336 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005337 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005338 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005339
Chris Lattner91689c12010-09-08 05:10:46 +00005340 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005341
Jim Grosbach7283da92011-08-16 21:12:37 +00005342 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5343 // do and don't have a cc_out optional-def operand. With some spot-checks
5344 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005345 // parse and adjust accordingly before actually matching. We shouldn't ever
5346 // try to remove a cc_out operand that was explicitly set on the the
5347 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5348 // table driven matcher doesn't fit well with the ARM instruction set.
5349 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005350 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5351 Operands.erase(Operands.begin() + 1);
5352 delete Op;
5353 }
5354
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005355 // ARM mode 'blx' need special handling, as the register operand version
5356 // is predicable, but the label operand version is not. So, we can't rely
5357 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005358 // a k_CondCode operand in the list. If we're trying to match the label
5359 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005360 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5361 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5362 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5363 Operands.erase(Operands.begin() + 1);
5364 delete Op;
5365 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005366
Weiming Zhao8f56f882012-11-16 21:55:34 +00005367 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5368 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5369 // a single GPRPair reg operand is used in the .td file to replace the two
5370 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5371 // expressed as a GPRPair, so we have to manually merge them.
5372 // FIXME: We would really like to be able to tablegen'erate this.
5373 if (!isThumb() && Operands.size() > 4 &&
5374 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5375 bool isLoad = (Mnemonic == "ldrexd");
5376 unsigned Idx = isLoad ? 2 : 3;
5377 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5378 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5379
5380 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5381 // Adjust only if Op1 and Op2 are GPRs.
5382 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5383 MRC.contains(Op2->getReg())) {
5384 unsigned Reg1 = Op1->getReg();
5385 unsigned Reg2 = Op2->getReg();
5386 unsigned Rt = MRI->getEncodingValue(Reg1);
5387 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5388
5389 // Rt2 must be Rt + 1 and Rt must be even.
5390 if (Rt + 1 != Rt2 || (Rt & 1)) {
5391 Error(Op2->getStartLoc(), isLoad ?
5392 "destination operands must be sequential" :
5393 "source operands must be sequential");
5394 return true;
5395 }
5396 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5397 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5398 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5399 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5400 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5401 delete Op1;
5402 delete Op2;
5403 }
5404 }
5405
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005406 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005407}
5408
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005409// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005410
5411// return 'true' if register list contains non-low GPR registers,
5412// 'false' otherwise. If Reg is in the register list or is HiReg, set
5413// 'containsReg' to true.
5414static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5415 unsigned HiReg, bool &containsReg) {
5416 containsReg = false;
5417 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5418 unsigned OpReg = Inst.getOperand(i).getReg();
5419 if (OpReg == Reg)
5420 containsReg = true;
5421 // Anything other than a low register isn't legal here.
5422 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5423 return true;
5424 }
5425 return false;
5426}
5427
Jim Grosbacha31f2232011-09-07 18:05:34 +00005428// Check if the specified regisgter is in the register list of the inst,
5429// starting at the indicated operand number.
5430static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5431 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5432 unsigned OpReg = Inst.getOperand(i).getReg();
5433 if (OpReg == Reg)
5434 return true;
5435 }
5436 return false;
5437}
5438
Jim Grosbached16ec42011-08-29 22:24:09 +00005439// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5440// the ARMInsts array) instead. Getting that here requires awkward
5441// API changes, though. Better way?
5442namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005443extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005444}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005445static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005446 return ARMInsts[Opcode];
5447}
5448
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005449// FIXME: We would really like to be able to tablegen'erate this.
5450bool ARMAsmParser::
5451validateInstruction(MCInst &Inst,
5452 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005453 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005454 SMLoc Loc = Operands[0]->getStartLoc();
5455 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005456 // NOTE: BKPT instruction has the interesting property of being
5457 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005458 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005459 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5460 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005461 unsigned bit = 1;
5462 if (ITState.FirstCond)
5463 ITState.FirstCond = false;
5464 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005465 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005466 // The instruction must be predicable.
5467 if (!MCID.isPredicable())
5468 return Error(Loc, "instructions in IT block must be predicable");
5469 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5470 unsigned ITCond = bit ? ITState.Cond :
5471 ARMCC::getOppositeCondition(ITState.Cond);
5472 if (Cond != ITCond) {
5473 // Find the condition code Operand to get its SMLoc information.
5474 SMLoc CondLoc;
5475 for (unsigned i = 1; i < Operands.size(); ++i)
5476 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5477 CondLoc = Operands[i]->getStartLoc();
5478 return Error(CondLoc, "incorrect condition in IT block; got '" +
5479 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5480 "', but expected '" +
5481 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5482 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005483 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005484 } else if (isThumbTwo() && MCID.isPredicable() &&
5485 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005486 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5487 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005488 return Error(Loc, "predicated instructions must be in IT block");
5489
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005490 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005491 case ARM::LDRD:
5492 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005493 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005494 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005495 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5496 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005497 if (Rt2 != Rt + 1)
5498 return Error(Operands[3]->getStartLoc(),
5499 "destination operands must be sequential");
5500 return false;
5501 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005502 case ARM::STRD: {
5503 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005504 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5505 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005506 if (Rt2 != Rt + 1)
5507 return Error(Operands[3]->getStartLoc(),
5508 "source operands must be sequential");
5509 return false;
5510 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005511 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005512 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005513 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005514 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5515 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005516 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005517 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005518 "source operands must be sequential");
5519 return false;
5520 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005521 case ARM::SBFX:
5522 case ARM::UBFX: {
5523 // width must be in range [1, 32-lsb]
5524 unsigned lsb = Inst.getOperand(2).getImm();
5525 unsigned widthm1 = Inst.getOperand(3).getImm();
5526 if (widthm1 >= 32 - lsb)
5527 return Error(Operands[5]->getStartLoc(),
5528 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005529 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005530 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005531 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005532 // If we're parsing Thumb2, the .w variant is available and handles
5533 // most cases that are normally illegal for a Thumb1 LDM
5534 // instruction. We'll make the transformation in processInstruction()
5535 // if necessary.
5536 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005537 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005538 // in the register list.
5539 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005540 bool hasWritebackToken =
5541 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5542 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005543 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005544 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005545 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5546 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005547 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005548 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005549 return Error(Operands[2]->getStartLoc(),
5550 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005551 // If we should not have writeback, there must not be a '!'. This is
5552 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005553 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005554 return Error(Operands[3]->getStartLoc(),
5555 "writeback operator '!' not allowed when base register "
5556 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005557
5558 break;
5559 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005560 case ARM::t2LDMIA_UPD: {
5561 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5562 return Error(Operands[4]->getStartLoc(),
5563 "writeback operator '!' not allowed when base register "
5564 "in register list");
5565 break;
5566 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005567 case ARM::tMUL: {
5568 // The second source operand must be the same register as the destination
5569 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005570 //
5571 // In this case, we must directly check the parsed operands because the
5572 // cvtThumbMultiply() function is written in such a way that it guarantees
5573 // this first statement is always true for the new Inst. Essentially, the
5574 // destination is unconditionally copied into the second source operand
5575 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005576 if (Operands.size() == 6 &&
5577 (((ARMOperand*)Operands[3])->getReg() !=
5578 ((ARMOperand*)Operands[5])->getReg()) &&
5579 (((ARMOperand*)Operands[3])->getReg() !=
5580 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005581 return Error(Operands[3]->getStartLoc(),
5582 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005583 }
5584 break;
5585 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005586 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5587 // so only issue a diagnostic for thumb1. The instructions will be
5588 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005589 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005590 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005591 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5592 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005593 return Error(Operands[2]->getStartLoc(),
5594 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005595 break;
5596 }
5597 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005598 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005599 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5600 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005601 return Error(Operands[2]->getStartLoc(),
5602 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005603 break;
5604 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005605 case ARM::tSTMIA_UPD: {
5606 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005607 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005608 return Error(Operands[4]->getStartLoc(),
5609 "registers must be in range r0-r7");
5610 break;
5611 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005612 case ARM::tADDrSP: {
5613 // If the non-SP source operand and the destination operand are not the
5614 // same, we need thumb2 (for the wide encoding), or we have an error.
5615 if (!isThumbTwo() &&
5616 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5617 return Error(Operands[4]->getStartLoc(),
5618 "source register must be the same as destination");
5619 }
5620 break;
5621 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005622 }
5623
5624 return false;
5625}
5626
Jim Grosbach1a747242012-01-23 23:45:44 +00005627static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005628 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005629 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005630 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005631 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5632 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5633 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5634 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5635 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5636 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5637 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5638 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5639 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005640
5641 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005642 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5643 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5644 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5645 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5646 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005647
Jim Grosbach1e946a42012-01-24 00:43:12 +00005648 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5649 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5650 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5651 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5652 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005653
Jim Grosbach1e946a42012-01-24 00:43:12 +00005654 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5655 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5656 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5657 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5658 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005659
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005660 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005661 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5662 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5663 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5664 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5665 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5666 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5667 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5668 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5669 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5670 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5671 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5672 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5673 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5674 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5675 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005676
Jim Grosbach1a747242012-01-23 23:45:44 +00005677 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005678 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5679 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5680 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5681 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5682 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5683 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5684 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5685 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5686 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5687 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5688 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5689 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5690 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5691 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5692 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5693 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5694 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5695 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005696
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005697 // VST4LN
5698 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5699 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5700 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5701 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5702 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5703 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5704 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5705 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5706 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5707 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5708 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5709 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5710 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5711 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5712 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5713
Jim Grosbachda70eac2012-01-24 00:58:13 +00005714 // VST4
5715 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5716 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5717 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5718 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5719 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5720 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5721 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5722 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5723 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5724 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5725 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5726 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5727 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5728 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5729 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5730 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5731 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5732 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005733 }
5734}
5735
Jim Grosbach1a747242012-01-23 23:45:44 +00005736static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005737 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005738 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005739 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005740 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5741 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5742 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5743 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5744 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5745 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5746 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5747 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5748 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005749
5750 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005751 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5752 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5753 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5754 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5755 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5756 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5757 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5758 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5759 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5760 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5761 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5762 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5763 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5764 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5765 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005766
Jim Grosbachb78403c2012-01-24 23:47:04 +00005767 // VLD3DUP
5768 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5769 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5770 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5771 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5772 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5773 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5774 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5775 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5776 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5777 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5778 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5779 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5780 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5781 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5782 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5783 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5784 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5785 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5786
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005787 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005788 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5789 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5790 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5791 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5792 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5793 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5794 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5795 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5796 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5797 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5798 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5799 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5800 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5801 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5802 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005803
5804 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005805 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5806 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5807 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5808 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5809 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5810 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5811 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5812 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5813 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5814 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5815 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5816 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5817 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5818 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5819 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5820 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5821 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5822 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005823
Jim Grosbach14952a02012-01-24 18:37:25 +00005824 // VLD4LN
5825 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5826 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5827 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5828 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5829 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5830 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5831 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5832 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5833 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5834 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5835 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5836 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5837 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5838 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5839 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5840
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005841 // VLD4DUP
5842 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5843 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5844 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5845 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5846 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5847 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5848 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5849 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5850 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5851 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5852 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5853 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5854 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5855 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5856 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5857 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5858 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5859 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5860
Jim Grosbached561fc2012-01-24 00:43:17 +00005861 // VLD4
5862 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5863 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5864 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5865 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5866 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5867 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5868 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5869 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5870 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5871 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5872 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5873 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5874 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5875 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5876 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5877 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5878 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5879 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005880 }
5881}
5882
Jim Grosbachafad0532011-11-10 23:42:14 +00005883bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005884processInstruction(MCInst &Inst,
5885 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5886 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005887 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5888 case ARM::ADDri: {
5889 if (Inst.getOperand(1).getReg() != ARM::PC ||
5890 Inst.getOperand(5).getReg() != 0)
5891 return false;
5892 MCInst TmpInst;
5893 TmpInst.setOpcode(ARM::ADR);
5894 TmpInst.addOperand(Inst.getOperand(0));
5895 TmpInst.addOperand(Inst.getOperand(2));
5896 TmpInst.addOperand(Inst.getOperand(3));
5897 TmpInst.addOperand(Inst.getOperand(4));
5898 Inst = TmpInst;
5899 return true;
5900 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005901 // Aliases for alternate PC+imm syntax of LDR instructions.
5902 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005903 // Select the narrow version if the immediate will fit.
5904 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005905 Inst.getOperand(1).getImm() <= 0xff &&
5906 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5907 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005908 Inst.setOpcode(ARM::tLDRpci);
5909 else
5910 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005911 return true;
5912 case ARM::t2LDRBpcrel:
5913 Inst.setOpcode(ARM::t2LDRBpci);
5914 return true;
5915 case ARM::t2LDRHpcrel:
5916 Inst.setOpcode(ARM::t2LDRHpci);
5917 return true;
5918 case ARM::t2LDRSBpcrel:
5919 Inst.setOpcode(ARM::t2LDRSBpci);
5920 return true;
5921 case ARM::t2LDRSHpcrel:
5922 Inst.setOpcode(ARM::t2LDRSHpci);
5923 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005924 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005925 case ARM::VST1LNdWB_register_Asm_8:
5926 case ARM::VST1LNdWB_register_Asm_16:
5927 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005928 MCInst TmpInst;
5929 // Shuffle the operands around so the lane index operand is in the
5930 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005931 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005932 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005933 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5934 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5935 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5936 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5937 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5938 TmpInst.addOperand(Inst.getOperand(1)); // lane
5939 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5940 TmpInst.addOperand(Inst.getOperand(6));
5941 Inst = TmpInst;
5942 return true;
5943 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005944
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005945 case ARM::VST2LNdWB_register_Asm_8:
5946 case ARM::VST2LNdWB_register_Asm_16:
5947 case ARM::VST2LNdWB_register_Asm_32:
5948 case ARM::VST2LNqWB_register_Asm_16:
5949 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005950 MCInst TmpInst;
5951 // Shuffle the operands around so the lane index operand is in the
5952 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005953 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005954 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005955 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5956 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5957 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5958 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5959 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005960 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5961 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005962 TmpInst.addOperand(Inst.getOperand(1)); // lane
5963 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5964 TmpInst.addOperand(Inst.getOperand(6));
5965 Inst = TmpInst;
5966 return true;
5967 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005968
5969 case ARM::VST3LNdWB_register_Asm_8:
5970 case ARM::VST3LNdWB_register_Asm_16:
5971 case ARM::VST3LNdWB_register_Asm_32:
5972 case ARM::VST3LNqWB_register_Asm_16:
5973 case ARM::VST3LNqWB_register_Asm_32: {
5974 MCInst TmpInst;
5975 // Shuffle the operands around so the lane index operand is in the
5976 // right place.
5977 unsigned Spacing;
5978 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5979 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5980 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5981 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5982 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5983 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5984 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5985 Spacing));
5986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5987 Spacing * 2));
5988 TmpInst.addOperand(Inst.getOperand(1)); // lane
5989 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5990 TmpInst.addOperand(Inst.getOperand(6));
5991 Inst = TmpInst;
5992 return true;
5993 }
5994
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005995 case ARM::VST4LNdWB_register_Asm_8:
5996 case ARM::VST4LNdWB_register_Asm_16:
5997 case ARM::VST4LNdWB_register_Asm_32:
5998 case ARM::VST4LNqWB_register_Asm_16:
5999 case ARM::VST4LNqWB_register_Asm_32: {
6000 MCInst TmpInst;
6001 // Shuffle the operands around so the lane index operand is in the
6002 // right place.
6003 unsigned Spacing;
6004 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6005 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6006 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6007 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6008 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6009 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6011 Spacing));
6012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6013 Spacing * 2));
6014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6015 Spacing * 3));
6016 TmpInst.addOperand(Inst.getOperand(1)); // lane
6017 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6018 TmpInst.addOperand(Inst.getOperand(6));
6019 Inst = TmpInst;
6020 return true;
6021 }
6022
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006023 case ARM::VST1LNdWB_fixed_Asm_8:
6024 case ARM::VST1LNdWB_fixed_Asm_16:
6025 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006026 MCInst TmpInst;
6027 // Shuffle the operands around so the lane index operand is in the
6028 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006029 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006030 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006031 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6032 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6033 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6034 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6035 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6036 TmpInst.addOperand(Inst.getOperand(1)); // lane
6037 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6038 TmpInst.addOperand(Inst.getOperand(5));
6039 Inst = TmpInst;
6040 return true;
6041 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006042
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006043 case ARM::VST2LNdWB_fixed_Asm_8:
6044 case ARM::VST2LNdWB_fixed_Asm_16:
6045 case ARM::VST2LNdWB_fixed_Asm_32:
6046 case ARM::VST2LNqWB_fixed_Asm_16:
6047 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006048 MCInst TmpInst;
6049 // Shuffle the operands around so the lane index operand is in the
6050 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006051 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006052 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006053 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6054 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6055 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6056 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6057 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6059 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006060 TmpInst.addOperand(Inst.getOperand(1)); // lane
6061 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6062 TmpInst.addOperand(Inst.getOperand(5));
6063 Inst = TmpInst;
6064 return true;
6065 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006066
6067 case ARM::VST3LNdWB_fixed_Asm_8:
6068 case ARM::VST3LNdWB_fixed_Asm_16:
6069 case ARM::VST3LNdWB_fixed_Asm_32:
6070 case ARM::VST3LNqWB_fixed_Asm_16:
6071 case ARM::VST3LNqWB_fixed_Asm_32: {
6072 MCInst TmpInst;
6073 // Shuffle the operands around so the lane index operand is in the
6074 // right place.
6075 unsigned Spacing;
6076 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6077 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6078 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6079 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6080 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6081 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6083 Spacing));
6084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6085 Spacing * 2));
6086 TmpInst.addOperand(Inst.getOperand(1)); // lane
6087 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6088 TmpInst.addOperand(Inst.getOperand(5));
6089 Inst = TmpInst;
6090 return true;
6091 }
6092
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006093 case ARM::VST4LNdWB_fixed_Asm_8:
6094 case ARM::VST4LNdWB_fixed_Asm_16:
6095 case ARM::VST4LNdWB_fixed_Asm_32:
6096 case ARM::VST4LNqWB_fixed_Asm_16:
6097 case ARM::VST4LNqWB_fixed_Asm_32: {
6098 MCInst TmpInst;
6099 // Shuffle the operands around so the lane index operand is in the
6100 // right place.
6101 unsigned Spacing;
6102 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6103 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6104 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6105 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6106 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6107 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6108 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6109 Spacing));
6110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6111 Spacing * 2));
6112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6113 Spacing * 3));
6114 TmpInst.addOperand(Inst.getOperand(1)); // lane
6115 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6116 TmpInst.addOperand(Inst.getOperand(5));
6117 Inst = TmpInst;
6118 return true;
6119 }
6120
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006121 case ARM::VST1LNdAsm_8:
6122 case ARM::VST1LNdAsm_16:
6123 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006124 MCInst TmpInst;
6125 // Shuffle the operands around so the lane index operand is in the
6126 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006127 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006128 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006129 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6130 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6131 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6132 TmpInst.addOperand(Inst.getOperand(1)); // lane
6133 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6134 TmpInst.addOperand(Inst.getOperand(5));
6135 Inst = TmpInst;
6136 return true;
6137 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006138
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006139 case ARM::VST2LNdAsm_8:
6140 case ARM::VST2LNdAsm_16:
6141 case ARM::VST2LNdAsm_32:
6142 case ARM::VST2LNqAsm_16:
6143 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006144 MCInst TmpInst;
6145 // Shuffle the operands around so the lane index operand is in the
6146 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006147 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006148 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006149 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6150 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6151 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006152 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6153 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006154 TmpInst.addOperand(Inst.getOperand(1)); // lane
6155 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6156 TmpInst.addOperand(Inst.getOperand(5));
6157 Inst = TmpInst;
6158 return true;
6159 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006160
6161 case ARM::VST3LNdAsm_8:
6162 case ARM::VST3LNdAsm_16:
6163 case ARM::VST3LNdAsm_32:
6164 case ARM::VST3LNqAsm_16:
6165 case ARM::VST3LNqAsm_32: {
6166 MCInst TmpInst;
6167 // Shuffle the operands around so the lane index operand is in the
6168 // right place.
6169 unsigned Spacing;
6170 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6171 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6172 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6173 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 Spacing));
6176 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6177 Spacing * 2));
6178 TmpInst.addOperand(Inst.getOperand(1)); // lane
6179 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6180 TmpInst.addOperand(Inst.getOperand(5));
6181 Inst = TmpInst;
6182 return true;
6183 }
6184
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006185 case ARM::VST4LNdAsm_8:
6186 case ARM::VST4LNdAsm_16:
6187 case ARM::VST4LNdAsm_32:
6188 case ARM::VST4LNqAsm_16:
6189 case ARM::VST4LNqAsm_32: {
6190 MCInst TmpInst;
6191 // Shuffle the operands around so the lane index operand is in the
6192 // right place.
6193 unsigned Spacing;
6194 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6195 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6196 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6197 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 Spacing));
6200 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 Spacing * 2));
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 Spacing * 3));
6204 TmpInst.addOperand(Inst.getOperand(1)); // lane
6205 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6206 TmpInst.addOperand(Inst.getOperand(5));
6207 Inst = TmpInst;
6208 return true;
6209 }
6210
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006211 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006212 case ARM::VLD1LNdWB_register_Asm_8:
6213 case ARM::VLD1LNdWB_register_Asm_16:
6214 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006215 MCInst TmpInst;
6216 // Shuffle the operands around so the lane index operand is in the
6217 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006218 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006219 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006220 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6221 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6222 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6223 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6224 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6225 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6226 TmpInst.addOperand(Inst.getOperand(1)); // lane
6227 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6228 TmpInst.addOperand(Inst.getOperand(6));
6229 Inst = TmpInst;
6230 return true;
6231 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006232
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006233 case ARM::VLD2LNdWB_register_Asm_8:
6234 case ARM::VLD2LNdWB_register_Asm_16:
6235 case ARM::VLD2LNdWB_register_Asm_32:
6236 case ARM::VLD2LNqWB_register_Asm_16:
6237 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006238 MCInst TmpInst;
6239 // Shuffle the operands around so the lane index operand is in the
6240 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006241 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006242 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006243 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6245 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006246 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6247 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6248 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6249 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6250 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6252 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006253 TmpInst.addOperand(Inst.getOperand(1)); // lane
6254 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6255 TmpInst.addOperand(Inst.getOperand(6));
6256 Inst = TmpInst;
6257 return true;
6258 }
6259
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006260 case ARM::VLD3LNdWB_register_Asm_8:
6261 case ARM::VLD3LNdWB_register_Asm_16:
6262 case ARM::VLD3LNdWB_register_Asm_32:
6263 case ARM::VLD3LNqWB_register_Asm_16:
6264 case ARM::VLD3LNqWB_register_Asm_32: {
6265 MCInst TmpInst;
6266 // Shuffle the operands around so the lane index operand is in the
6267 // right place.
6268 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006269 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006270 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6272 Spacing));
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006274 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006275 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6276 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6277 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6278 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6279 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6281 Spacing));
6282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006283 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006284 TmpInst.addOperand(Inst.getOperand(1)); // lane
6285 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6286 TmpInst.addOperand(Inst.getOperand(6));
6287 Inst = TmpInst;
6288 return true;
6289 }
6290
Jim Grosbach14952a02012-01-24 18:37:25 +00006291 case ARM::VLD4LNdWB_register_Asm_8:
6292 case ARM::VLD4LNdWB_register_Asm_16:
6293 case ARM::VLD4LNdWB_register_Asm_32:
6294 case ARM::VLD4LNqWB_register_Asm_16:
6295 case ARM::VLD4LNqWB_register_Asm_32: {
6296 MCInst TmpInst;
6297 // Shuffle the operands around so the lane index operand is in the
6298 // right place.
6299 unsigned Spacing;
6300 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6301 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6303 Spacing));
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing * 2));
6306 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 Spacing * 3));
6308 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6309 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6310 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6311 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6312 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6314 Spacing));
6315 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6316 Spacing * 2));
6317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 Spacing * 3));
6319 TmpInst.addOperand(Inst.getOperand(1)); // lane
6320 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6321 TmpInst.addOperand(Inst.getOperand(6));
6322 Inst = TmpInst;
6323 return true;
6324 }
6325
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006326 case ARM::VLD1LNdWB_fixed_Asm_8:
6327 case ARM::VLD1LNdWB_fixed_Asm_16:
6328 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006329 MCInst TmpInst;
6330 // Shuffle the operands around so the lane index operand is in the
6331 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006332 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006333 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006334 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6335 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6336 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6337 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6338 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6339 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6340 TmpInst.addOperand(Inst.getOperand(1)); // lane
6341 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6342 TmpInst.addOperand(Inst.getOperand(5));
6343 Inst = TmpInst;
6344 return true;
6345 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006346
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006347 case ARM::VLD2LNdWB_fixed_Asm_8:
6348 case ARM::VLD2LNdWB_fixed_Asm_16:
6349 case ARM::VLD2LNdWB_fixed_Asm_32:
6350 case ARM::VLD2LNqWB_fixed_Asm_16:
6351 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006352 MCInst TmpInst;
6353 // Shuffle the operands around so the lane index operand is in the
6354 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006355 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006356 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006357 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006360 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6363 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6366 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006367 TmpInst.addOperand(Inst.getOperand(1)); // lane
6368 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6369 TmpInst.addOperand(Inst.getOperand(5));
6370 Inst = TmpInst;
6371 return true;
6372 }
6373
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006374 case ARM::VLD3LNdWB_fixed_Asm_8:
6375 case ARM::VLD3LNdWB_fixed_Asm_16:
6376 case ARM::VLD3LNdWB_fixed_Asm_32:
6377 case ARM::VLD3LNqWB_fixed_Asm_16:
6378 case ARM::VLD3LNqWB_fixed_Asm_32: {
6379 MCInst TmpInst;
6380 // Shuffle the operands around so the lane index operand is in the
6381 // right place.
6382 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006383 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006384 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6386 Spacing));
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006388 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006389 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6390 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6391 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6392 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6393 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6395 Spacing));
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006397 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006398 TmpInst.addOperand(Inst.getOperand(1)); // lane
6399 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6400 TmpInst.addOperand(Inst.getOperand(5));
6401 Inst = TmpInst;
6402 return true;
6403 }
6404
Jim Grosbach14952a02012-01-24 18:37:25 +00006405 case ARM::VLD4LNdWB_fixed_Asm_8:
6406 case ARM::VLD4LNdWB_fixed_Asm_16:
6407 case ARM::VLD4LNdWB_fixed_Asm_32:
6408 case ARM::VLD4LNqWB_fixed_Asm_16:
6409 case ARM::VLD4LNqWB_fixed_Asm_32: {
6410 MCInst TmpInst;
6411 // Shuffle the operands around so the lane index operand is in the
6412 // right place.
6413 unsigned Spacing;
6414 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6415 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6416 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6417 Spacing));
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 Spacing * 2));
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 Spacing * 3));
6422 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6423 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6424 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6425 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6426 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6427 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 Spacing));
6429 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 Spacing * 2));
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 Spacing * 3));
6433 TmpInst.addOperand(Inst.getOperand(1)); // lane
6434 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6435 TmpInst.addOperand(Inst.getOperand(5));
6436 Inst = TmpInst;
6437 return true;
6438 }
6439
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006440 case ARM::VLD1LNdAsm_8:
6441 case ARM::VLD1LNdAsm_16:
6442 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006443 MCInst TmpInst;
6444 // Shuffle the operands around so the lane index operand is in the
6445 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006446 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006447 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006448 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6449 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6450 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6451 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6452 TmpInst.addOperand(Inst.getOperand(1)); // lane
6453 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6454 TmpInst.addOperand(Inst.getOperand(5));
6455 Inst = TmpInst;
6456 return true;
6457 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006458
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006459 case ARM::VLD2LNdAsm_8:
6460 case ARM::VLD2LNdAsm_16:
6461 case ARM::VLD2LNdAsm_32:
6462 case ARM::VLD2LNqAsm_16:
6463 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006464 MCInst TmpInst;
6465 // Shuffle the operands around so the lane index operand is in the
6466 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006467 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006468 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006469 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6471 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006472 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6473 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6474 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006477 TmpInst.addOperand(Inst.getOperand(1)); // lane
6478 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(5));
6480 Inst = TmpInst;
6481 return true;
6482 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006483
6484 case ARM::VLD3LNdAsm_8:
6485 case ARM::VLD3LNdAsm_16:
6486 case ARM::VLD3LNdAsm_32:
6487 case ARM::VLD3LNqAsm_16:
6488 case ARM::VLD3LNqAsm_32: {
6489 MCInst TmpInst;
6490 // Shuffle the operands around so the lane index operand is in the
6491 // right place.
6492 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing));
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006498 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006499 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6500 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6501 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6502 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 Spacing));
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006505 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006506 TmpInst.addOperand(Inst.getOperand(1)); // lane
6507 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6508 TmpInst.addOperand(Inst.getOperand(5));
6509 Inst = TmpInst;
6510 return true;
6511 }
6512
Jim Grosbach14952a02012-01-24 18:37:25 +00006513 case ARM::VLD4LNdAsm_8:
6514 case ARM::VLD4LNdAsm_16:
6515 case ARM::VLD4LNdAsm_32:
6516 case ARM::VLD4LNqAsm_16:
6517 case ARM::VLD4LNqAsm_32: {
6518 MCInst TmpInst;
6519 // Shuffle the operands around so the lane index operand is in the
6520 // right place.
6521 unsigned Spacing;
6522 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6523 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 Spacing));
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 Spacing * 2));
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing * 3));
6530 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6531 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6532 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6533 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6534 Spacing));
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 Spacing * 2));
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing * 3));
6539 TmpInst.addOperand(Inst.getOperand(1)); // lane
6540 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6541 TmpInst.addOperand(Inst.getOperand(5));
6542 Inst = TmpInst;
6543 return true;
6544 }
6545
Jim Grosbachb78403c2012-01-24 23:47:04 +00006546 // VLD3DUP single 3-element structure to all lanes instructions.
6547 case ARM::VLD3DUPdAsm_8:
6548 case ARM::VLD3DUPdAsm_16:
6549 case ARM::VLD3DUPdAsm_32:
6550 case ARM::VLD3DUPqAsm_8:
6551 case ARM::VLD3DUPqAsm_16:
6552 case ARM::VLD3DUPqAsm_32: {
6553 MCInst TmpInst;
6554 unsigned Spacing;
6555 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6556 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 Spacing));
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 Spacing * 2));
6561 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6562 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6563 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6564 TmpInst.addOperand(Inst.getOperand(4));
6565 Inst = TmpInst;
6566 return true;
6567 }
6568
6569 case ARM::VLD3DUPdWB_fixed_Asm_8:
6570 case ARM::VLD3DUPdWB_fixed_Asm_16:
6571 case ARM::VLD3DUPdWB_fixed_Asm_32:
6572 case ARM::VLD3DUPqWB_fixed_Asm_8:
6573 case ARM::VLD3DUPqWB_fixed_Asm_16:
6574 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6575 MCInst TmpInst;
6576 unsigned Spacing;
6577 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6578 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6579 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6580 Spacing));
6581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 Spacing * 2));
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6585 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6586 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6587 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6588 TmpInst.addOperand(Inst.getOperand(4));
6589 Inst = TmpInst;
6590 return true;
6591 }
6592
6593 case ARM::VLD3DUPdWB_register_Asm_8:
6594 case ARM::VLD3DUPdWB_register_Asm_16:
6595 case ARM::VLD3DUPdWB_register_Asm_32:
6596 case ARM::VLD3DUPqWB_register_Asm_8:
6597 case ARM::VLD3DUPqWB_register_Asm_16:
6598 case ARM::VLD3DUPqWB_register_Asm_32: {
6599 MCInst TmpInst;
6600 unsigned Spacing;
6601 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6602 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 Spacing));
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing * 2));
6607 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6608 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6609 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6610 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6611 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6612 TmpInst.addOperand(Inst.getOperand(5));
6613 Inst = TmpInst;
6614 return true;
6615 }
6616
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006617 // VLD3 multiple 3-element structure instructions.
6618 case ARM::VLD3dAsm_8:
6619 case ARM::VLD3dAsm_16:
6620 case ARM::VLD3dAsm_32:
6621 case ARM::VLD3qAsm_8:
6622 case ARM::VLD3qAsm_16:
6623 case ARM::VLD3qAsm_32: {
6624 MCInst TmpInst;
6625 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006626 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006627 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6629 Spacing));
6630 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 Spacing * 2));
6632 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6633 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6634 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6635 TmpInst.addOperand(Inst.getOperand(4));
6636 Inst = TmpInst;
6637 return true;
6638 }
6639
6640 case ARM::VLD3dWB_fixed_Asm_8:
6641 case ARM::VLD3dWB_fixed_Asm_16:
6642 case ARM::VLD3dWB_fixed_Asm_32:
6643 case ARM::VLD3qWB_fixed_Asm_8:
6644 case ARM::VLD3qWB_fixed_Asm_16:
6645 case ARM::VLD3qWB_fixed_Asm_32: {
6646 MCInst TmpInst;
6647 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006648 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006649 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6651 Spacing));
6652 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6653 Spacing * 2));
6654 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6655 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6656 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6657 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6658 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6659 TmpInst.addOperand(Inst.getOperand(4));
6660 Inst = TmpInst;
6661 return true;
6662 }
6663
6664 case ARM::VLD3dWB_register_Asm_8:
6665 case ARM::VLD3dWB_register_Asm_16:
6666 case ARM::VLD3dWB_register_Asm_32:
6667 case ARM::VLD3qWB_register_Asm_8:
6668 case ARM::VLD3qWB_register_Asm_16:
6669 case ARM::VLD3qWB_register_Asm_32: {
6670 MCInst TmpInst;
6671 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006672 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing));
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing * 2));
6678 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6679 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6680 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6681 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6682 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6683 TmpInst.addOperand(Inst.getOperand(5));
6684 Inst = TmpInst;
6685 return true;
6686 }
6687
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006688 // VLD4DUP single 3-element structure to all lanes instructions.
6689 case ARM::VLD4DUPdAsm_8:
6690 case ARM::VLD4DUPdAsm_16:
6691 case ARM::VLD4DUPdAsm_32:
6692 case ARM::VLD4DUPqAsm_8:
6693 case ARM::VLD4DUPqAsm_16:
6694 case ARM::VLD4DUPqAsm_32: {
6695 MCInst TmpInst;
6696 unsigned Spacing;
6697 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6698 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6699 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 Spacing));
6701 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6702 Spacing * 2));
6703 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 Spacing * 3));
6705 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6706 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6707 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6708 TmpInst.addOperand(Inst.getOperand(4));
6709 Inst = TmpInst;
6710 return true;
6711 }
6712
6713 case ARM::VLD4DUPdWB_fixed_Asm_8:
6714 case ARM::VLD4DUPdWB_fixed_Asm_16:
6715 case ARM::VLD4DUPdWB_fixed_Asm_32:
6716 case ARM::VLD4DUPqWB_fixed_Asm_8:
6717 case ARM::VLD4DUPqWB_fixed_Asm_16:
6718 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6719 MCInst TmpInst;
6720 unsigned Spacing;
6721 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6722 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6724 Spacing));
6725 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6726 Spacing * 2));
6727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6728 Spacing * 3));
6729 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6730 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6731 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6732 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6733 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6734 TmpInst.addOperand(Inst.getOperand(4));
6735 Inst = TmpInst;
6736 return true;
6737 }
6738
6739 case ARM::VLD4DUPdWB_register_Asm_8:
6740 case ARM::VLD4DUPdWB_register_Asm_16:
6741 case ARM::VLD4DUPdWB_register_Asm_32:
6742 case ARM::VLD4DUPqWB_register_Asm_8:
6743 case ARM::VLD4DUPqWB_register_Asm_16:
6744 case ARM::VLD4DUPqWB_register_Asm_32: {
6745 MCInst TmpInst;
6746 unsigned Spacing;
6747 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6748 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6750 Spacing));
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6752 Spacing * 2));
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 Spacing * 3));
6755 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6756 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6757 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6758 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6759 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6760 TmpInst.addOperand(Inst.getOperand(5));
6761 Inst = TmpInst;
6762 return true;
6763 }
6764
6765 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006766 case ARM::VLD4dAsm_8:
6767 case ARM::VLD4dAsm_16:
6768 case ARM::VLD4dAsm_32:
6769 case ARM::VLD4qAsm_8:
6770 case ARM::VLD4qAsm_16:
6771 case ARM::VLD4qAsm_32: {
6772 MCInst TmpInst;
6773 unsigned Spacing;
6774 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6775 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6776 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6777 Spacing));
6778 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6779 Spacing * 2));
6780 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 Spacing * 3));
6782 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6783 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6784 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6785 TmpInst.addOperand(Inst.getOperand(4));
6786 Inst = TmpInst;
6787 return true;
6788 }
6789
6790 case ARM::VLD4dWB_fixed_Asm_8:
6791 case ARM::VLD4dWB_fixed_Asm_16:
6792 case ARM::VLD4dWB_fixed_Asm_32:
6793 case ARM::VLD4qWB_fixed_Asm_8:
6794 case ARM::VLD4qWB_fixed_Asm_16:
6795 case ARM::VLD4qWB_fixed_Asm_32: {
6796 MCInst TmpInst;
6797 unsigned Spacing;
6798 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6799 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6800 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6801 Spacing));
6802 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6803 Spacing * 2));
6804 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6805 Spacing * 3));
6806 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6807 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6808 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6809 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6810 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6811 TmpInst.addOperand(Inst.getOperand(4));
6812 Inst = TmpInst;
6813 return true;
6814 }
6815
6816 case ARM::VLD4dWB_register_Asm_8:
6817 case ARM::VLD4dWB_register_Asm_16:
6818 case ARM::VLD4dWB_register_Asm_32:
6819 case ARM::VLD4qWB_register_Asm_8:
6820 case ARM::VLD4qWB_register_Asm_16:
6821 case ARM::VLD4qWB_register_Asm_32: {
6822 MCInst TmpInst;
6823 unsigned Spacing;
6824 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6825 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6827 Spacing));
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6829 Spacing * 2));
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6831 Spacing * 3));
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(Inst.getOperand(3)); // Rm
6836 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6837 TmpInst.addOperand(Inst.getOperand(5));
6838 Inst = TmpInst;
6839 return true;
6840 }
6841
Jim Grosbach1a747242012-01-23 23:45:44 +00006842 // VST3 multiple 3-element structure instructions.
6843 case ARM::VST3dAsm_8:
6844 case ARM::VST3dAsm_16:
6845 case ARM::VST3dAsm_32:
6846 case ARM::VST3qAsm_8:
6847 case ARM::VST3qAsm_16:
6848 case ARM::VST3qAsm_32: {
6849 MCInst TmpInst;
6850 unsigned Spacing;
6851 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6852 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6853 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6854 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6856 Spacing));
6857 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6858 Spacing * 2));
6859 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6860 TmpInst.addOperand(Inst.getOperand(4));
6861 Inst = TmpInst;
6862 return true;
6863 }
6864
6865 case ARM::VST3dWB_fixed_Asm_8:
6866 case ARM::VST3dWB_fixed_Asm_16:
6867 case ARM::VST3dWB_fixed_Asm_32:
6868 case ARM::VST3qWB_fixed_Asm_8:
6869 case ARM::VST3qWB_fixed_Asm_16:
6870 case ARM::VST3qWB_fixed_Asm_32: {
6871 MCInst TmpInst;
6872 unsigned Spacing;
6873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6874 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6875 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6876 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6877 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6878 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6880 Spacing));
6881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6882 Spacing * 2));
6883 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6884 TmpInst.addOperand(Inst.getOperand(4));
6885 Inst = TmpInst;
6886 return true;
6887 }
6888
6889 case ARM::VST3dWB_register_Asm_8:
6890 case ARM::VST3dWB_register_Asm_16:
6891 case ARM::VST3dWB_register_Asm_32:
6892 case ARM::VST3qWB_register_Asm_8:
6893 case ARM::VST3qWB_register_Asm_16:
6894 case ARM::VST3qWB_register_Asm_32: {
6895 MCInst TmpInst;
6896 unsigned Spacing;
6897 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6898 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6899 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6900 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6901 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6902 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6903 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6904 Spacing));
6905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6906 Spacing * 2));
6907 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6908 TmpInst.addOperand(Inst.getOperand(5));
6909 Inst = TmpInst;
6910 return true;
6911 }
6912
Jim Grosbachda70eac2012-01-24 00:58:13 +00006913 // VST4 multiple 3-element structure instructions.
6914 case ARM::VST4dAsm_8:
6915 case ARM::VST4dAsm_16:
6916 case ARM::VST4dAsm_32:
6917 case ARM::VST4qAsm_8:
6918 case ARM::VST4qAsm_16:
6919 case ARM::VST4qAsm_32: {
6920 MCInst TmpInst;
6921 unsigned Spacing;
6922 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6923 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6924 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6925 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6926 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6927 Spacing));
6928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6929 Spacing * 2));
6930 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6931 Spacing * 3));
6932 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6933 TmpInst.addOperand(Inst.getOperand(4));
6934 Inst = TmpInst;
6935 return true;
6936 }
6937
6938 case ARM::VST4dWB_fixed_Asm_8:
6939 case ARM::VST4dWB_fixed_Asm_16:
6940 case ARM::VST4dWB_fixed_Asm_32:
6941 case ARM::VST4qWB_fixed_Asm_8:
6942 case ARM::VST4qWB_fixed_Asm_16:
6943 case ARM::VST4qWB_fixed_Asm_32: {
6944 MCInst TmpInst;
6945 unsigned Spacing;
6946 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6947 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6948 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6949 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6950 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6951 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6953 Spacing));
6954 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6955 Spacing * 2));
6956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6957 Spacing * 3));
6958 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6959 TmpInst.addOperand(Inst.getOperand(4));
6960 Inst = TmpInst;
6961 return true;
6962 }
6963
6964 case ARM::VST4dWB_register_Asm_8:
6965 case ARM::VST4dWB_register_Asm_16:
6966 case ARM::VST4dWB_register_Asm_32:
6967 case ARM::VST4qWB_register_Asm_8:
6968 case ARM::VST4qWB_register_Asm_16:
6969 case ARM::VST4qWB_register_Asm_32: {
6970 MCInst TmpInst;
6971 unsigned Spacing;
6972 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6973 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6974 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6975 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6976 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6977 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6978 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6979 Spacing));
6980 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6981 Spacing * 2));
6982 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6983 Spacing * 3));
6984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6985 TmpInst.addOperand(Inst.getOperand(5));
6986 Inst = TmpInst;
6987 return true;
6988 }
6989
Jim Grosbachad66de12012-04-11 00:15:16 +00006990 // Handle encoding choice for the shift-immediate instructions.
6991 case ARM::t2LSLri:
6992 case ARM::t2LSRri:
6993 case ARM::t2ASRri: {
6994 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6995 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6996 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6997 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6998 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6999 unsigned NewOpc;
7000 switch (Inst.getOpcode()) {
7001 default: llvm_unreachable("unexpected opcode");
7002 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7003 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7004 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7005 }
7006 // The Thumb1 operands aren't in the same order. Awesome, eh?
7007 MCInst TmpInst;
7008 TmpInst.setOpcode(NewOpc);
7009 TmpInst.addOperand(Inst.getOperand(0));
7010 TmpInst.addOperand(Inst.getOperand(5));
7011 TmpInst.addOperand(Inst.getOperand(1));
7012 TmpInst.addOperand(Inst.getOperand(2));
7013 TmpInst.addOperand(Inst.getOperand(3));
7014 TmpInst.addOperand(Inst.getOperand(4));
7015 Inst = TmpInst;
7016 return true;
7017 }
7018 return false;
7019 }
7020
Jim Grosbach485e5622011-12-13 22:45:11 +00007021 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007022 case ARM::t2MOVsr:
7023 case ARM::t2MOVSsr: {
7024 // Which instruction to expand to depends on the CCOut operand and
7025 // whether we're in an IT block if the register operands are low
7026 // registers.
7027 bool isNarrow = false;
7028 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7029 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7030 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7031 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7032 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7033 isNarrow = true;
7034 MCInst TmpInst;
7035 unsigned newOpc;
7036 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7037 default: llvm_unreachable("unexpected opcode!");
7038 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7039 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7040 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7041 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7042 }
7043 TmpInst.setOpcode(newOpc);
7044 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7045 if (isNarrow)
7046 TmpInst.addOperand(MCOperand::CreateReg(
7047 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7048 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7049 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7050 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7051 TmpInst.addOperand(Inst.getOperand(5));
7052 if (!isNarrow)
7053 TmpInst.addOperand(MCOperand::CreateReg(
7054 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7055 Inst = TmpInst;
7056 return true;
7057 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007058 case ARM::t2MOVsi:
7059 case ARM::t2MOVSsi: {
7060 // Which instruction to expand to depends on the CCOut operand and
7061 // whether we're in an IT block if the register operands are low
7062 // registers.
7063 bool isNarrow = false;
7064 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7065 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7066 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7067 isNarrow = true;
7068 MCInst TmpInst;
7069 unsigned newOpc;
7070 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7071 default: llvm_unreachable("unexpected opcode!");
7072 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7073 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7074 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7075 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007076 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007077 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007078 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7079 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007080 TmpInst.setOpcode(newOpc);
7081 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7082 if (isNarrow)
7083 TmpInst.addOperand(MCOperand::CreateReg(
7084 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7085 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007086 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007087 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007088 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7089 TmpInst.addOperand(Inst.getOperand(4));
7090 if (!isNarrow)
7091 TmpInst.addOperand(MCOperand::CreateReg(
7092 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7093 Inst = TmpInst;
7094 return true;
7095 }
7096 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007097 case ARM::ASRr:
7098 case ARM::LSRr:
7099 case ARM::LSLr:
7100 case ARM::RORr: {
7101 ARM_AM::ShiftOpc ShiftTy;
7102 switch(Inst.getOpcode()) {
7103 default: llvm_unreachable("unexpected opcode!");
7104 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7105 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7106 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7107 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7108 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007109 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7110 MCInst TmpInst;
7111 TmpInst.setOpcode(ARM::MOVsr);
7112 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7113 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7114 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7115 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7116 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7117 TmpInst.addOperand(Inst.getOperand(4));
7118 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7119 Inst = TmpInst;
7120 return true;
7121 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007122 case ARM::ASRi:
7123 case ARM::LSRi:
7124 case ARM::LSLi:
7125 case ARM::RORi: {
7126 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007127 switch(Inst.getOpcode()) {
7128 default: llvm_unreachable("unexpected opcode!");
7129 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7130 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7131 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7132 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7133 }
7134 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007135 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007136 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007137 // A shift by 32 should be encoded as 0 when permitted
7138 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7139 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007140 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007141 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007142 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007143 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7144 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007145 if (Opc == ARM::MOVsi)
7146 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007147 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7148 TmpInst.addOperand(Inst.getOperand(4));
7149 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7150 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007151 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007152 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007153 case ARM::RRXi: {
7154 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7155 MCInst TmpInst;
7156 TmpInst.setOpcode(ARM::MOVsi);
7157 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7158 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7159 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7160 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7161 TmpInst.addOperand(Inst.getOperand(3));
7162 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7163 Inst = TmpInst;
7164 return true;
7165 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007166 case ARM::t2LDMIA_UPD: {
7167 // If this is a load of a single register, then we should use
7168 // a post-indexed LDR instruction instead, per the ARM ARM.
7169 if (Inst.getNumOperands() != 5)
7170 return false;
7171 MCInst TmpInst;
7172 TmpInst.setOpcode(ARM::t2LDR_POST);
7173 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7174 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7175 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7176 TmpInst.addOperand(MCOperand::CreateImm(4));
7177 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7178 TmpInst.addOperand(Inst.getOperand(3));
7179 Inst = TmpInst;
7180 return true;
7181 }
7182 case ARM::t2STMDB_UPD: {
7183 // If this is a store of a single register, then we should use
7184 // a pre-indexed STR instruction instead, per the ARM ARM.
7185 if (Inst.getNumOperands() != 5)
7186 return false;
7187 MCInst TmpInst;
7188 TmpInst.setOpcode(ARM::t2STR_PRE);
7189 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7190 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7191 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7192 TmpInst.addOperand(MCOperand::CreateImm(-4));
7193 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7194 TmpInst.addOperand(Inst.getOperand(3));
7195 Inst = TmpInst;
7196 return true;
7197 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007198 case ARM::LDMIA_UPD:
7199 // If this is a load of a single register via a 'pop', then we should use
7200 // a post-indexed LDR instruction instead, per the ARM ARM.
7201 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7202 Inst.getNumOperands() == 5) {
7203 MCInst TmpInst;
7204 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7205 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7206 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7207 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7208 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7209 TmpInst.addOperand(MCOperand::CreateImm(4));
7210 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7211 TmpInst.addOperand(Inst.getOperand(3));
7212 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007213 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007214 }
7215 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007216 case ARM::STMDB_UPD:
7217 // If this is a store of a single register via a 'push', then we should use
7218 // a pre-indexed STR instruction instead, per the ARM ARM.
7219 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7220 Inst.getNumOperands() == 5) {
7221 MCInst TmpInst;
7222 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7223 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7224 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7225 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7226 TmpInst.addOperand(MCOperand::CreateImm(-4));
7227 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7228 TmpInst.addOperand(Inst.getOperand(3));
7229 Inst = TmpInst;
7230 }
7231 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007232 case ARM::t2ADDri12:
7233 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7234 // mnemonic was used (not "addw"), encoding T3 is preferred.
7235 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7236 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7237 break;
7238 Inst.setOpcode(ARM::t2ADDri);
7239 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7240 break;
7241 case ARM::t2SUBri12:
7242 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7243 // mnemonic was used (not "subw"), encoding T3 is preferred.
7244 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7245 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7246 break;
7247 Inst.setOpcode(ARM::t2SUBri);
7248 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7249 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007250 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007251 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007252 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7253 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7254 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007255 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007256 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007257 return true;
7258 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007259 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007260 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007261 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007262 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7263 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7264 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007265 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007266 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007267 return true;
7268 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007269 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007270 case ARM::t2ADDri:
7271 case ARM::t2SUBri: {
7272 // If the destination and first source operand are the same, and
7273 // the flags are compatible with the current IT status, use encoding T2
7274 // instead of T3. For compatibility with the system 'as'. Make sure the
7275 // wide encoding wasn't explicit.
7276 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007277 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007278 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7279 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7280 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7281 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7282 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7283 break;
7284 MCInst TmpInst;
7285 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7286 ARM::tADDi8 : ARM::tSUBi8);
7287 TmpInst.addOperand(Inst.getOperand(0));
7288 TmpInst.addOperand(Inst.getOperand(5));
7289 TmpInst.addOperand(Inst.getOperand(0));
7290 TmpInst.addOperand(Inst.getOperand(2));
7291 TmpInst.addOperand(Inst.getOperand(3));
7292 TmpInst.addOperand(Inst.getOperand(4));
7293 Inst = TmpInst;
7294 return true;
7295 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007296 case ARM::t2ADDrr: {
7297 // If the destination and first source operand are the same, and
7298 // there's no setting of the flags, use encoding T2 instead of T3.
7299 // Note that this is only for ADD, not SUB. This mirrors the system
7300 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7301 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7302 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007303 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7304 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007305 break;
7306 MCInst TmpInst;
7307 TmpInst.setOpcode(ARM::tADDhirr);
7308 TmpInst.addOperand(Inst.getOperand(0));
7309 TmpInst.addOperand(Inst.getOperand(0));
7310 TmpInst.addOperand(Inst.getOperand(2));
7311 TmpInst.addOperand(Inst.getOperand(3));
7312 TmpInst.addOperand(Inst.getOperand(4));
7313 Inst = TmpInst;
7314 return true;
7315 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007316 case ARM::tADDrSP: {
7317 // If the non-SP source operand and the destination operand are not the
7318 // same, we need to use the 32-bit encoding if it's available.
7319 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7320 Inst.setOpcode(ARM::t2ADDrr);
7321 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7322 return true;
7323 }
7324 break;
7325 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007326 case ARM::tB:
7327 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007328 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007329 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007330 return true;
7331 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007332 break;
7333 case ARM::t2B:
7334 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007335 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007336 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007337 return true;
7338 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007339 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007340 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007341 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007342 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007343 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007344 return true;
7345 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007346 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007347 case ARM::tBcc:
7348 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007349 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007350 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007351 return true;
7352 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007353 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007354 case ARM::tLDMIA: {
7355 // If the register list contains any high registers, or if the writeback
7356 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7357 // instead if we're in Thumb2. Otherwise, this should have generated
7358 // an error in validateInstruction().
7359 unsigned Rn = Inst.getOperand(0).getReg();
7360 bool hasWritebackToken =
7361 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7362 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7363 bool listContainsBase;
7364 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7365 (!listContainsBase && !hasWritebackToken) ||
7366 (listContainsBase && hasWritebackToken)) {
7367 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7368 assert (isThumbTwo());
7369 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7370 // If we're switching to the updating version, we need to insert
7371 // the writeback tied operand.
7372 if (hasWritebackToken)
7373 Inst.insert(Inst.begin(),
7374 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007375 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007376 }
7377 break;
7378 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007379 case ARM::tSTMIA_UPD: {
7380 // If the register list contains any high registers, we need to use
7381 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7382 // should have generated an error in validateInstruction().
7383 unsigned Rn = Inst.getOperand(0).getReg();
7384 bool listContainsBase;
7385 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7386 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7387 assert (isThumbTwo());
7388 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007389 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007390 }
7391 break;
7392 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007393 case ARM::tPOP: {
7394 bool listContainsBase;
7395 // If the register list contains any high registers, we need to use
7396 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7397 // should have generated an error in validateInstruction().
7398 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007399 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007400 assert (isThumbTwo());
7401 Inst.setOpcode(ARM::t2LDMIA_UPD);
7402 // Add the base register and writeback operands.
7403 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7404 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007405 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007406 }
7407 case ARM::tPUSH: {
7408 bool listContainsBase;
7409 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007410 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007411 assert (isThumbTwo());
7412 Inst.setOpcode(ARM::t2STMDB_UPD);
7413 // Add the base register and writeback operands.
7414 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7415 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007416 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007417 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007418 case ARM::t2MOVi: {
7419 // If we can use the 16-bit encoding and the user didn't explicitly
7420 // request the 32-bit variant, transform it here.
7421 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007422 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007423 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7424 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7425 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007426 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7427 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7428 // The operands aren't in the same order for tMOVi8...
7429 MCInst TmpInst;
7430 TmpInst.setOpcode(ARM::tMOVi8);
7431 TmpInst.addOperand(Inst.getOperand(0));
7432 TmpInst.addOperand(Inst.getOperand(4));
7433 TmpInst.addOperand(Inst.getOperand(1));
7434 TmpInst.addOperand(Inst.getOperand(2));
7435 TmpInst.addOperand(Inst.getOperand(3));
7436 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007437 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007438 }
7439 break;
7440 }
7441 case ARM::t2MOVr: {
7442 // If we can use the 16-bit encoding and the user didn't explicitly
7443 // request the 32-bit variant, transform it here.
7444 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7445 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7446 Inst.getOperand(2).getImm() == ARMCC::AL &&
7447 Inst.getOperand(4).getReg() == ARM::CPSR &&
7448 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7449 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7450 // The operands aren't the same for tMOV[S]r... (no cc_out)
7451 MCInst TmpInst;
7452 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7453 TmpInst.addOperand(Inst.getOperand(0));
7454 TmpInst.addOperand(Inst.getOperand(1));
7455 TmpInst.addOperand(Inst.getOperand(2));
7456 TmpInst.addOperand(Inst.getOperand(3));
7457 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007458 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007459 }
7460 break;
7461 }
Jim Grosbach82213192011-09-19 20:29:33 +00007462 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007463 case ARM::t2SXTB:
7464 case ARM::t2UXTH:
7465 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007466 // If we can use the 16-bit encoding and the user didn't explicitly
7467 // request the 32-bit variant, transform it here.
7468 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7469 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7470 Inst.getOperand(2).getImm() == 0 &&
7471 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7472 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007473 unsigned NewOpc;
7474 switch (Inst.getOpcode()) {
7475 default: llvm_unreachable("Illegal opcode!");
7476 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7477 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7478 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7479 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7480 }
Jim Grosbach82213192011-09-19 20:29:33 +00007481 // The operands aren't the same for thumb1 (no rotate operand).
7482 MCInst TmpInst;
7483 TmpInst.setOpcode(NewOpc);
7484 TmpInst.addOperand(Inst.getOperand(0));
7485 TmpInst.addOperand(Inst.getOperand(1));
7486 TmpInst.addOperand(Inst.getOperand(3));
7487 TmpInst.addOperand(Inst.getOperand(4));
7488 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007489 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007490 }
7491 break;
7492 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007493 case ARM::MOVsi: {
7494 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007495 // rrx shifts and asr/lsr of #32 is encoded as 0
7496 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7497 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007498 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7499 // Shifting by zero is accepted as a vanilla 'MOVr'
7500 MCInst TmpInst;
7501 TmpInst.setOpcode(ARM::MOVr);
7502 TmpInst.addOperand(Inst.getOperand(0));
7503 TmpInst.addOperand(Inst.getOperand(1));
7504 TmpInst.addOperand(Inst.getOperand(3));
7505 TmpInst.addOperand(Inst.getOperand(4));
7506 TmpInst.addOperand(Inst.getOperand(5));
7507 Inst = TmpInst;
7508 return true;
7509 }
7510 return false;
7511 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007512 case ARM::ANDrsi:
7513 case ARM::ORRrsi:
7514 case ARM::EORrsi:
7515 case ARM::BICrsi:
7516 case ARM::SUBrsi:
7517 case ARM::ADDrsi: {
7518 unsigned newOpc;
7519 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7520 if (SOpc == ARM_AM::rrx) return false;
7521 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007522 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007523 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7524 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7525 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7526 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7527 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7528 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7529 }
7530 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007531 // The exception is for right shifts, where 0 == 32
7532 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7533 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007534 MCInst TmpInst;
7535 TmpInst.setOpcode(newOpc);
7536 TmpInst.addOperand(Inst.getOperand(0));
7537 TmpInst.addOperand(Inst.getOperand(1));
7538 TmpInst.addOperand(Inst.getOperand(2));
7539 TmpInst.addOperand(Inst.getOperand(4));
7540 TmpInst.addOperand(Inst.getOperand(5));
7541 TmpInst.addOperand(Inst.getOperand(6));
7542 Inst = TmpInst;
7543 return true;
7544 }
7545 return false;
7546 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007547 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007548 case ARM::t2IT: {
7549 // The mask bits for all but the first condition are represented as
7550 // the low bit of the condition code value implies 't'. We currently
7551 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007552 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007553 MCOperand &MO = Inst.getOperand(1);
7554 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007555 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007556 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007557 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007558 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007559 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007560 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007561 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007562
7563 // Set up the IT block state according to the IT instruction we just
7564 // matched.
7565 assert(!inITBlock() && "nested IT blocks?!");
7566 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7567 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7568 ITState.CurPosition = 0;
7569 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007570 break;
7571 }
Richard Bartona39625e2012-07-09 16:12:24 +00007572 case ARM::t2LSLrr:
7573 case ARM::t2LSRrr:
7574 case ARM::t2ASRrr:
7575 case ARM::t2SBCrr:
7576 case ARM::t2RORrr:
7577 case ARM::t2BICrr:
7578 {
Richard Bartond5660372012-07-09 16:14:28 +00007579 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007580 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7581 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7582 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007583 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7584 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007585 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7586 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7587 unsigned NewOpc;
7588 switch (Inst.getOpcode()) {
7589 default: llvm_unreachable("unexpected opcode");
7590 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7591 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7592 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7593 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7594 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7595 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7596 }
7597 MCInst TmpInst;
7598 TmpInst.setOpcode(NewOpc);
7599 TmpInst.addOperand(Inst.getOperand(0));
7600 TmpInst.addOperand(Inst.getOperand(5));
7601 TmpInst.addOperand(Inst.getOperand(1));
7602 TmpInst.addOperand(Inst.getOperand(2));
7603 TmpInst.addOperand(Inst.getOperand(3));
7604 TmpInst.addOperand(Inst.getOperand(4));
7605 Inst = TmpInst;
7606 return true;
7607 }
7608 return false;
7609 }
7610 case ARM::t2ANDrr:
7611 case ARM::t2EORrr:
7612 case ARM::t2ADCrr:
7613 case ARM::t2ORRrr:
7614 {
Richard Bartond5660372012-07-09 16:14:28 +00007615 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007616 // These instructions are special in that they are commutable, so shorter encodings
7617 // are available more often.
7618 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7619 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7620 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7621 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007622 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7623 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007624 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7625 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7626 unsigned NewOpc;
7627 switch (Inst.getOpcode()) {
7628 default: llvm_unreachable("unexpected opcode");
7629 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7630 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7631 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7632 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7633 }
7634 MCInst TmpInst;
7635 TmpInst.setOpcode(NewOpc);
7636 TmpInst.addOperand(Inst.getOperand(0));
7637 TmpInst.addOperand(Inst.getOperand(5));
7638 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7639 TmpInst.addOperand(Inst.getOperand(1));
7640 TmpInst.addOperand(Inst.getOperand(2));
7641 } else {
7642 TmpInst.addOperand(Inst.getOperand(2));
7643 TmpInst.addOperand(Inst.getOperand(1));
7644 }
7645 TmpInst.addOperand(Inst.getOperand(3));
7646 TmpInst.addOperand(Inst.getOperand(4));
7647 Inst = TmpInst;
7648 return true;
7649 }
7650 return false;
7651 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007652 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007653 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007654}
7655
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007656unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7657 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7658 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007659 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007660 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007661 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7662 assert(MCID.hasOptionalDef() &&
7663 "optionally flag setting instruction missing optional def operand");
7664 assert(MCID.NumOperands == Inst.getNumOperands() &&
7665 "operand count mismatch!");
7666 // Find the optional-def operand (cc_out).
7667 unsigned OpNo;
7668 for (OpNo = 0;
7669 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7670 ++OpNo)
7671 ;
7672 // If we're parsing Thumb1, reject it completely.
7673 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7674 return Match_MnemonicFail;
7675 // If we're parsing Thumb2, which form is legal depends on whether we're
7676 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007677 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7678 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007679 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007680 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7681 inITBlock())
7682 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007683 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007684 // Some high-register supporting Thumb1 encodings only allow both registers
7685 // to be from r0-r7 when in Thumb2.
7686 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7687 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7688 isARMLowRegister(Inst.getOperand(2).getReg()))
7689 return Match_RequiresThumb2;
7690 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007691 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007692 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7693 isARMLowRegister(Inst.getOperand(1).getReg()))
7694 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007695 return Match_Success;
7696}
7697
Jim Grosbach5117ef72012-04-24 22:40:08 +00007698static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007699bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007700MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007701 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007702 MCStreamer &Out, unsigned &ErrorInfo,
7703 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007704 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007705 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007706
Chad Rosier2f480a82012-10-12 22:53:36 +00007707 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007708 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007709 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007710 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007711 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007712 // Context sensitive operand constraints aren't handled by the matcher,
7713 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007714 if (validateInstruction(Inst, Operands)) {
7715 // Still progress the IT block, otherwise one wrong condition causes
7716 // nasty cascading errors.
7717 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007718 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007719 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007720
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007721 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007722 // encoding is selected. Loop on it while changes happen so the
7723 // individual transformations can chain off each other. E.g.,
7724 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7725 while (processInstruction(Inst, Operands))
7726 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007727
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007728 // Only move forward at the very end so that everything in validate
7729 // and process gets a consistent answer about whether we're in an IT
7730 // block.
7731 forwardITPosition();
7732
Jim Grosbach82f76d12012-01-25 19:52:01 +00007733 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7734 // doesn't actually encode.
7735 if (Inst.getOpcode() == ARM::ITasm)
7736 return false;
7737
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007738 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007739 Out.EmitInstruction(Inst);
7740 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007741 case Match_MissingFeature: {
7742 assert(ErrorInfo && "Unknown missing feature!");
7743 // Special case the error message for the very common case where only
7744 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7745 std::string Msg = "instruction requires:";
7746 unsigned Mask = 1;
7747 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7748 if (ErrorInfo & Mask) {
7749 Msg += " ";
7750 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7751 }
7752 Mask <<= 1;
7753 }
7754 return Error(IDLoc, Msg);
7755 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007756 case Match_InvalidOperand: {
7757 SMLoc ErrorLoc = IDLoc;
7758 if (ErrorInfo != ~0U) {
7759 if (ErrorInfo >= Operands.size())
7760 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007761
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007762 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7763 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7764 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007765
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007766 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007767 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007768 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007769 return Error(IDLoc, "invalid instruction",
7770 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007771 case Match_RequiresNotITBlock:
7772 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007773 case Match_RequiresITBlock:
7774 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007775 case Match_RequiresV6:
7776 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7777 case Match_RequiresThumb2:
7778 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007779 case Match_ImmRange0_4: {
7780 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7781 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7782 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7783 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007784 case Match_ImmRange0_15: {
7785 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7786 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7787 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7788 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007789 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007790
Eric Christopher91d7b902010-10-29 09:26:59 +00007791 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007792}
7793
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007794/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007795bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7796 StringRef IDVal = DirectiveID.getIdentifier();
7797 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007798 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007799 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007800 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007801 else if (IDVal == ".arm")
7802 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007803 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007804 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007805 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007806 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007807 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007808 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007809 else if (IDVal == ".unreq")
7810 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007811 else if (IDVal == ".arch")
7812 return parseDirectiveArch(DirectiveID.getLoc());
7813 else if (IDVal == ".eabi_attribute")
7814 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007815 else if (IDVal == ".fnstart")
7816 return parseDirectiveFnStart(DirectiveID.getLoc());
7817 else if (IDVal == ".fnend")
7818 return parseDirectiveFnEnd(DirectiveID.getLoc());
7819 else if (IDVal == ".cantunwind")
7820 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7821 else if (IDVal == ".personality")
7822 return parseDirectivePersonality(DirectiveID.getLoc());
7823 else if (IDVal == ".handlerdata")
7824 return parseDirectiveHandlerData(DirectiveID.getLoc());
7825 else if (IDVal == ".setfp")
7826 return parseDirectiveSetFP(DirectiveID.getLoc());
7827 else if (IDVal == ".pad")
7828 return parseDirectivePad(DirectiveID.getLoc());
7829 else if (IDVal == ".save")
7830 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7831 else if (IDVal == ".vsave")
7832 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007833 return true;
7834}
7835
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007836/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007837/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007838bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007839 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7840 for (;;) {
7841 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007842 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007843 return true;
7844
Eric Christopherbf7bc492013-01-09 03:52:05 +00007845 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007846
7847 if (getLexer().is(AsmToken::EndOfStatement))
7848 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007849
Kevin Enderbyccab3172009-09-15 00:27:25 +00007850 // FIXME: Improve diagnostic.
7851 if (getLexer().isNot(AsmToken::Comma))
7852 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007853 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007854 }
7855 }
7856
Sean Callanana83fd7d2010-01-19 20:27:46 +00007857 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007858 return false;
7859}
7860
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007861/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007862/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007863bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007864 if (getLexer().isNot(AsmToken::EndOfStatement))
7865 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007866 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007867
Tim Northovera2292d02013-06-10 23:20:58 +00007868 if (!hasThumb())
7869 return Error(L, "target does not support Thumb mode");
7870
Jim Grosbach7f882392011-12-07 18:04:19 +00007871 if (!isThumb())
7872 SwitchMode();
7873 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7874 return false;
7875}
7876
7877/// parseDirectiveARM
7878/// ::= .arm
7879bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7880 if (getLexer().isNot(AsmToken::EndOfStatement))
7881 return Error(L, "unexpected token in directive");
7882 Parser.Lex();
7883
Tim Northovera2292d02013-06-10 23:20:58 +00007884 if (!hasARM())
7885 return Error(L, "target does not support ARM mode");
7886
Jim Grosbach7f882392011-12-07 18:04:19 +00007887 if (isThumb())
7888 SwitchMode();
7889 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007890 return false;
7891}
7892
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007893/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007894/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007895bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007896 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7897 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007898 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007899 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007900
Jim Grosbach1152cc02011-12-21 22:30:16 +00007901 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007902 // ELF doesn't
7903 if (isMachO) {
7904 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007905 if (Tok.isNot(AsmToken::EndOfStatement)) {
7906 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7907 return Error(L, "unexpected token in .thumb_func directive");
7908 Name = Tok.getIdentifier();
7909 Parser.Lex(); // Consume the identifier token.
7910 needFuncName = false;
7911 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007912 }
7913
Jim Grosbach1152cc02011-12-21 22:30:16 +00007914 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007915 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007916
7917 // Eat the end of statement and any blank lines that follow.
7918 while (getLexer().is(AsmToken::EndOfStatement))
7919 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007920
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007921 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007922 // We really should be checking the next symbol definition even if there's
7923 // stuff in between.
7924 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007925 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007926 }
7927
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007928 // Mark symbol as a thumb symbol.
7929 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7930 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007931 return false;
7932}
7933
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007934/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007935/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007936bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007937 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007938 if (Tok.isNot(AsmToken::Identifier))
7939 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007940 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007941 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007942 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007943 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007944 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007945 else
7946 return Error(L, "unrecognized syntax mode in .syntax directive");
7947
7948 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007949 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007950 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007951
7952 // TODO tell the MC streamer the mode
7953 // getParser().getStreamer().Emit???();
7954 return false;
7955}
7956
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007957/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007958/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007959bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007960 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007961 if (Tok.isNot(AsmToken::Integer))
7962 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007963 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007964 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007965 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007966 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007967 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007968 else
7969 return Error(L, "invalid operand to .code directive");
7970
7971 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007972 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007973 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007974
Evan Cheng284b4672011-07-08 22:36:29 +00007975 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007976 if (!hasThumb())
7977 return Error(L, "target does not support Thumb mode");
7978
Jim Grosbachf471ac32011-09-06 18:46:23 +00007979 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007980 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007981 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007982 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007983 if (!hasARM())
7984 return Error(L, "target does not support ARM mode");
7985
Jim Grosbachf471ac32011-09-06 18:46:23 +00007986 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007987 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007988 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007989 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007990
Kevin Enderby146dcf22009-10-15 20:48:48 +00007991 return false;
7992}
7993
Jim Grosbachab5830e2011-12-14 02:16:11 +00007994/// parseDirectiveReq
7995/// ::= name .req registername
7996bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7997 Parser.Lex(); // Eat the '.req' token.
7998 unsigned Reg;
7999 SMLoc SRegLoc, ERegLoc;
8000 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008001 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008002 return Error(SRegLoc, "register name expected");
8003 }
8004
8005 // Shouldn't be anything else.
8006 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008007 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008008 return Error(Parser.getTok().getLoc(),
8009 "unexpected input in .req directive.");
8010 }
8011
8012 Parser.Lex(); // Consume the EndOfStatement
8013
8014 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8015 return Error(SRegLoc, "redefinition of '" + Name +
8016 "' does not match original.");
8017
8018 return false;
8019}
8020
8021/// parseDirectiveUneq
8022/// ::= .unreq registername
8023bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8024 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008025 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008026 return Error(L, "unexpected input in .unreq directive.");
8027 }
8028 RegisterReqs.erase(Parser.getTok().getIdentifier());
8029 Parser.Lex(); // Eat the identifier.
8030 return false;
8031}
8032
Jason W Kim135d2442011-12-20 17:38:12 +00008033/// parseDirectiveArch
8034/// ::= .arch token
8035bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8036 return true;
8037}
8038
8039/// parseDirectiveEabiAttr
8040/// ::= .eabi_attribute int, int
8041bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8042 return true;
8043}
8044
Logan Chien4ea23b52013-05-10 16:17:24 +00008045/// parseDirectiveFnStart
8046/// ::= .fnstart
8047bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8048 if (FnStartLoc.isValid()) {
8049 Error(L, ".fnstart starts before the end of previous one");
8050 Error(FnStartLoc, "previous .fnstart starts here");
8051 return true;
8052 }
8053
8054 FnStartLoc = L;
8055 getParser().getStreamer().EmitFnStart();
8056 return false;
8057}
8058
8059/// parseDirectiveFnEnd
8060/// ::= .fnend
8061bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8062 // Check the ordering of unwind directives
8063 if (!FnStartLoc.isValid())
8064 return Error(L, ".fnstart must precede .fnend directive");
8065
8066 // Reset the unwind directives parser state
8067 resetUnwindDirectiveParserState();
8068
8069 getParser().getStreamer().EmitFnEnd();
8070 return false;
8071}
8072
8073/// parseDirectiveCantUnwind
8074/// ::= .cantunwind
8075bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8076 // Check the ordering of unwind directives
8077 CantUnwindLoc = L;
8078 if (!FnStartLoc.isValid())
8079 return Error(L, ".fnstart must precede .cantunwind directive");
8080 if (HandlerDataLoc.isValid()) {
8081 Error(L, ".cantunwind can't be used with .handlerdata directive");
8082 Error(HandlerDataLoc, ".handlerdata was specified here");
8083 return true;
8084 }
8085 if (PersonalityLoc.isValid()) {
8086 Error(L, ".cantunwind can't be used with .personality directive");
8087 Error(PersonalityLoc, ".personality was specified here");
8088 return true;
8089 }
8090
8091 getParser().getStreamer().EmitCantUnwind();
8092 return false;
8093}
8094
8095/// parseDirectivePersonality
8096/// ::= .personality name
8097bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8098 // Check the ordering of unwind directives
8099 PersonalityLoc = L;
8100 if (!FnStartLoc.isValid())
8101 return Error(L, ".fnstart must precede .personality directive");
8102 if (CantUnwindLoc.isValid()) {
8103 Error(L, ".personality can't be used with .cantunwind directive");
8104 Error(CantUnwindLoc, ".cantunwind was specified here");
8105 return true;
8106 }
8107 if (HandlerDataLoc.isValid()) {
8108 Error(L, ".personality must precede .handlerdata directive");
8109 Error(HandlerDataLoc, ".handlerdata was specified here");
8110 return true;
8111 }
8112
8113 // Parse the name of the personality routine
8114 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8115 Parser.eatToEndOfStatement();
8116 return Error(L, "unexpected input in .personality directive.");
8117 }
8118 StringRef Name(Parser.getTok().getIdentifier());
8119 Parser.Lex();
8120
8121 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8122 getParser().getStreamer().EmitPersonality(PR);
8123 return false;
8124}
8125
8126/// parseDirectiveHandlerData
8127/// ::= .handlerdata
8128bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8129 // Check the ordering of unwind directives
8130 HandlerDataLoc = L;
8131 if (!FnStartLoc.isValid())
8132 return Error(L, ".fnstart must precede .personality directive");
8133 if (CantUnwindLoc.isValid()) {
8134 Error(L, ".handlerdata can't be used with .cantunwind directive");
8135 Error(CantUnwindLoc, ".cantunwind was specified here");
8136 return true;
8137 }
8138
8139 getParser().getStreamer().EmitHandlerData();
8140 return false;
8141}
8142
8143/// parseDirectiveSetFP
8144/// ::= .setfp fpreg, spreg [, offset]
8145bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8146 // Check the ordering of unwind directives
8147 if (!FnStartLoc.isValid())
8148 return Error(L, ".fnstart must precede .setfp directive");
8149 if (HandlerDataLoc.isValid())
8150 return Error(L, ".setfp must precede .handlerdata directive");
8151
8152 // Parse fpreg
8153 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8154 int NewFPReg = tryParseRegister();
8155 if (NewFPReg == -1)
8156 return Error(NewFPRegLoc, "frame pointer register expected");
8157
8158 // Consume comma
8159 if (!Parser.getTok().is(AsmToken::Comma))
8160 return Error(Parser.getTok().getLoc(), "comma expected");
8161 Parser.Lex(); // skip comma
8162
8163 // Parse spreg
8164 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8165 int NewSPReg = tryParseRegister();
8166 if (NewSPReg == -1)
8167 return Error(NewSPRegLoc, "stack pointer register expected");
8168
8169 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8170 return Error(NewSPRegLoc,
8171 "register should be either $sp or the latest fp register");
8172
8173 // Update the frame pointer register
8174 FPReg = NewFPReg;
8175
8176 // Parse offset
8177 int64_t Offset = 0;
8178 if (Parser.getTok().is(AsmToken::Comma)) {
8179 Parser.Lex(); // skip comma
8180
8181 if (Parser.getTok().isNot(AsmToken::Hash) &&
8182 Parser.getTok().isNot(AsmToken::Dollar)) {
8183 return Error(Parser.getTok().getLoc(), "'#' expected");
8184 }
8185 Parser.Lex(); // skip hash token.
8186
8187 const MCExpr *OffsetExpr;
8188 SMLoc ExLoc = Parser.getTok().getLoc();
8189 SMLoc EndLoc;
8190 if (getParser().parseExpression(OffsetExpr, EndLoc))
8191 return Error(ExLoc, "malformed setfp offset");
8192 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8193 if (!CE)
8194 return Error(ExLoc, "setfp offset must be an immediate");
8195
8196 Offset = CE->getValue();
8197 }
8198
8199 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8200 static_cast<unsigned>(NewSPReg),
8201 Offset);
8202 return false;
8203}
8204
8205/// parseDirective
8206/// ::= .pad offset
8207bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8208 // Check the ordering of unwind directives
8209 if (!FnStartLoc.isValid())
8210 return Error(L, ".fnstart must precede .pad directive");
8211 if (HandlerDataLoc.isValid())
8212 return Error(L, ".pad must precede .handlerdata directive");
8213
8214 // Parse the offset
8215 if (Parser.getTok().isNot(AsmToken::Hash) &&
8216 Parser.getTok().isNot(AsmToken::Dollar)) {
8217 return Error(Parser.getTok().getLoc(), "'#' expected");
8218 }
8219 Parser.Lex(); // skip hash token.
8220
8221 const MCExpr *OffsetExpr;
8222 SMLoc ExLoc = Parser.getTok().getLoc();
8223 SMLoc EndLoc;
8224 if (getParser().parseExpression(OffsetExpr, EndLoc))
8225 return Error(ExLoc, "malformed pad offset");
8226 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8227 if (!CE)
8228 return Error(ExLoc, "pad offset must be an immediate");
8229
8230 getParser().getStreamer().EmitPad(CE->getValue());
8231 return false;
8232}
8233
8234/// parseDirectiveRegSave
8235/// ::= .save { registers }
8236/// ::= .vsave { registers }
8237bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8238 // Check the ordering of unwind directives
8239 if (!FnStartLoc.isValid())
8240 return Error(L, ".fnstart must precede .save or .vsave directives");
8241 if (HandlerDataLoc.isValid())
8242 return Error(L, ".save or .vsave must precede .handlerdata directive");
8243
8244 // Parse the register list
8245 SmallVector<MCParsedAsmOperand*, 1> Operands;
8246 if (parseRegisterList(Operands))
8247 return true;
8248 ARMOperand *Op = (ARMOperand*)Operands[0];
8249 if (!IsVector && !Op->isRegList())
8250 return Error(L, ".save expects GPR registers");
8251 if (IsVector && !Op->isDPRRegList())
8252 return Error(L, ".vsave expects DPR registers");
8253
8254 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8255 return false;
8256}
8257
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008258/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008259extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008260 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8261 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008262}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008263
Chris Lattner3e4582a2010-09-06 19:11:01 +00008264#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008265#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008266#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008267#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008268
8269// Define this matcher function after the auto-generated include so we
8270// have the match class enum definitions.
8271unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8272 unsigned Kind) {
8273 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8274 // If the kind is a token for a literal immediate, check if our asm
8275 // operand matches. This is for InstAliases which have a fixed-value
8276 // immediate in the syntax.
8277 if (Kind == MCK__35_0 && Op->isImm()) {
8278 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8279 if (!CE)
8280 return Match_InvalidOperand;
8281 if (CE->getValue() == 0)
8282 return Match_Success;
8283 }
8284 return Match_InvalidOperand;
8285}