blob: 6d885a0d91827ed6925a8544aae4f352776f231c [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 cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000224 bool validateInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000226 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000228 bool shouldOmitCCOutOperand(StringRef Mnemonic,
229 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000230 bool shouldOmitPredicateOperand(StringRef Mnemonic,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000232
Kevin Enderbyccab3172009-09-15 00:27:25 +0000233public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000234 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000235 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000236 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000237 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000238 Match_RequiresThumb2,
239#define GET_OPERAND_DIAGNOSTIC_TYPES
240#include "ARMGenAsmMatcher.inc"
241
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000242 };
243
Evan Cheng91111d22011-07-09 05:47:46 +0000244 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000245 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000247
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000248 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000249 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000250
Evan Cheng4d1ca962011-07-08 01:53:10 +0000251 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000252 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000253
254 // Not in an ITBlock to start with.
255 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000256
257 // Set ELF header flags.
258 // FIXME: This should eventually end up somewhere else where more
259 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000260 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
261 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
262 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000263 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000264
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000265 // Implementation of the MCTargetAsmParser interface:
266 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000267 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
268 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000269 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000270 bool ParseDirective(AsmToken DirectiveID);
271
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000272 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000273 unsigned checkTargetMatchPredicate(MCInst &Inst);
274
Chad Rosier49963552012-10-13 00:26:04 +0000275 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000276 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000277 MCStreamer &Out, unsigned &ErrorInfo,
278 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000279};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000280} // end anonymous namespace
281
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000282namespace {
283
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000284/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000285/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000286class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000287 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000288 k_CondCode,
289 k_CCOut,
290 k_ITCondMask,
291 k_CoprocNum,
292 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000293 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000294 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000295 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000296 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000297 k_Memory,
298 k_PostIndexRegister,
299 k_MSRMask,
300 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000301 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000302 k_Register,
303 k_RegisterList,
304 k_DPRRegisterList,
305 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000306 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000307 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000308 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000309 k_ShiftedRegister,
310 k_ShiftedImmediate,
311 k_ShifterImmediate,
312 k_RotateImmediate,
313 k_BitfieldDescriptor,
314 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000315 } Kind;
316
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000317 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000318 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000319
Eric Christopher8996c5d2013-03-15 00:42:55 +0000320 struct CCOp {
321 ARMCC::CondCodes Val;
322 };
323
324 struct CopOp {
325 unsigned Val;
326 };
327
328 struct CoprocOptionOp {
329 unsigned Val;
330 };
331
332 struct ITMaskOp {
333 unsigned Mask:4;
334 };
335
336 struct MBOptOp {
337 ARM_MB::MemBOpt Val;
338 };
339
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000340 struct ISBOptOp {
341 ARM_ISB::InstSyncBOpt Val;
342 };
343
Eric Christopher8996c5d2013-03-15 00:42:55 +0000344 struct IFlagsOp {
345 ARM_PROC::IFlags Val;
346 };
347
348 struct MMaskOp {
349 unsigned Val;
350 };
351
352 struct TokOp {
353 const char *Data;
354 unsigned Length;
355 };
356
357 struct RegOp {
358 unsigned RegNum;
359 };
360
361 // A vector register list is a sequential list of 1 to 4 registers.
362 struct VectorListOp {
363 unsigned RegNum;
364 unsigned Count;
365 unsigned LaneIndex;
366 bool isDoubleSpaced;
367 };
368
369 struct VectorIndexOp {
370 unsigned Val;
371 };
372
373 struct ImmOp {
374 const MCExpr *Val;
375 };
376
377 /// Combined record for all forms of ARM address expressions.
378 struct MemoryOp {
379 unsigned BaseRegNum;
380 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
381 // was specified.
382 const MCConstantExpr *OffsetImm; // Offset immediate value
383 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
384 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
385 unsigned ShiftImm; // shift for OffsetReg.
386 unsigned Alignment; // 0 = no alignment specified
387 // n = alignment in bytes (2, 4, 8, 16, or 32)
388 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
389 };
390
391 struct PostIdxRegOp {
392 unsigned RegNum;
393 bool isAdd;
394 ARM_AM::ShiftOpc ShiftTy;
395 unsigned ShiftImm;
396 };
397
398 struct ShifterImmOp {
399 bool isASR;
400 unsigned Imm;
401 };
402
403 struct RegShiftedRegOp {
404 ARM_AM::ShiftOpc ShiftTy;
405 unsigned SrcReg;
406 unsigned ShiftReg;
407 unsigned ShiftImm;
408 };
409
410 struct RegShiftedImmOp {
411 ARM_AM::ShiftOpc ShiftTy;
412 unsigned SrcReg;
413 unsigned ShiftImm;
414 };
415
416 struct RotImmOp {
417 unsigned Imm;
418 };
419
420 struct BitfieldOp {
421 unsigned LSB;
422 unsigned Width;
423 };
424
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000425 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000426 struct CCOp CC;
427 struct CopOp Cop;
428 struct CoprocOptionOp CoprocOption;
429 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000430 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000431 struct ITMaskOp ITMask;
432 struct IFlagsOp IFlags;
433 struct MMaskOp MMask;
434 struct TokOp Tok;
435 struct RegOp Reg;
436 struct VectorListOp VectorList;
437 struct VectorIndexOp VectorIndex;
438 struct ImmOp Imm;
439 struct MemoryOp Memory;
440 struct PostIdxRegOp PostIdxReg;
441 struct ShifterImmOp ShifterImm;
442 struct RegShiftedRegOp RegShiftedReg;
443 struct RegShiftedImmOp RegShiftedImm;
444 struct RotImmOp RotImm;
445 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000446 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000447
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000448 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
449public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000450 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
451 Kind = o.Kind;
452 StartLoc = o.StartLoc;
453 EndLoc = o.EndLoc;
454 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000455 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000456 CC = o.CC;
457 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000458 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000459 ITMask = o.ITMask;
460 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000462 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_CCOut:
465 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000466 Reg = o.Reg;
467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000468 case k_RegisterList:
469 case k_DPRRegisterList:
470 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000471 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000472 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000473 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000474 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000475 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000476 VectorList = o.VectorList;
477 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000478 case k_CoprocNum:
479 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000480 Cop = o.Cop;
481 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000482 case k_CoprocOption:
483 CoprocOption = o.CoprocOption;
484 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000485 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000486 Imm = o.Imm;
487 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000488 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000489 MBOpt = o.MBOpt;
490 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000491 case k_InstSyncBarrierOpt:
492 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000493 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000494 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000496 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000497 PostIdxReg = o.PostIdxReg;
498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000500 MMask = o.MMask;
501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000503 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000505 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000506 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000508 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000509 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000510 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000511 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000512 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000514 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000515 RotImm = o.RotImm;
516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000517 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000518 Bitfield = o.Bitfield;
519 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000520 case k_VectorIndex:
521 VectorIndex = o.VectorIndex;
522 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000523 }
524 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000525
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000526 /// getStartLoc - Get the location of the first token of this operand.
527 SMLoc getStartLoc() const { return StartLoc; }
528 /// getEndLoc - Get the location of the last token of this operand.
529 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000530 /// getLocRange - Get the range between the first and last token of this
531 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000532 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
533
Daniel Dunbard8042b72010-08-11 06:36:53 +0000534 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000535 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000536 return CC.Val;
537 }
538
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000539 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000540 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000541 return Cop.Val;
542 }
543
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000544 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000546 return StringRef(Tok.Data, Tok.Length);
547 }
548
549 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000550 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000551 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000552 }
553
Bill Wendlingbed94652010-11-09 23:28:44 +0000554 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000555 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
556 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000557 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000558 }
559
Kevin Enderbyf5079942009-10-13 22:19:02 +0000560 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000561 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000562 return Imm.Val;
563 }
564
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000565 unsigned getVectorIndex() const {
566 assert(Kind == k_VectorIndex && "Invalid access!");
567 return VectorIndex.Val;
568 }
569
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000570 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000572 return MBOpt.Val;
573 }
574
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000575 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
576 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
577 return ISBOpt.Val;
578 }
579
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000580 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000582 return IFlags.Val;
583 }
584
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000585 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000586 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000587 return MMask.Val;
588 }
589
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 bool isCoprocNum() const { return Kind == k_CoprocNum; }
591 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000592 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000593 bool isCondCode() const { return Kind == k_CondCode; }
594 bool isCCOut() const { return Kind == k_CCOut; }
595 bool isITMask() const { return Kind == k_ITCondMask; }
596 bool isITCondCode() const { return Kind == k_CondCode; }
597 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000598 // checks whether this operand is an unsigned offset which fits is a field
599 // of specified width and scaled by a specific number of bits
600 template<unsigned width, unsigned scale>
601 bool isUnsignedOffset() const {
602 if (!isImm()) return false;
603 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
604 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
605 int64_t Val = CE->getValue();
606 int64_t Align = 1LL << scale;
607 int64_t Max = Align * ((1LL << width) - 1);
608 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
609 }
610 return false;
611 }
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000612 // checks whether this operand is a memory operand computed as an offset
613 // applied to PC. the offset may have 8 bits of magnitude and is represented
614 // with two bits of shift. textually it may be either [pc, #imm], #imm or
615 // relocable expression...
616 bool isThumbMemPC() const {
617 int64_t Val = 0;
618 if (isImm()) {
619 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
621 if (!CE) return false;
622 Val = CE->getValue();
623 }
624 else if (isMem()) {
625 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
626 if(Memory.BaseRegNum != ARM::PC) return false;
627 Val = Memory.OffsetImm->getValue();
628 }
629 else return false;
630 return ((Val % 4) == 0) && (Val >= -1020) && (Val <= 1020);
631 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000632 bool isFPImm() const {
633 if (!isImm()) return false;
634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
635 if (!CE) return false;
636 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
637 return Val != -1;
638 }
Jim Grosbachea231912011-12-22 22:19:05 +0000639 bool isFBits16() const {
640 if (!isImm()) return false;
641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
642 if (!CE) return false;
643 int64_t Value = CE->getValue();
644 return Value >= 0 && Value <= 16;
645 }
646 bool isFBits32() const {
647 if (!isImm()) return false;
648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int64_t Value = CE->getValue();
651 return Value >= 1 && Value <= 32;
652 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000653 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000654 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
659 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000660 bool isImm0_4() const {
661 if (!isImm()) return false;
662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value >= 0 && Value < 5;
666 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000667 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000668 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +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 >= 0 && Value <= 1020;
673 }
674 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000675 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
680 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000681 bool isImm0_508s4Neg() const {
682 if (!isImm()) return false;
683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = -CE->getValue();
686 // explicitly exclude zero. we want that to use the normal 0_508 version.
687 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
688 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000689 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000690 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return Value >= 0 && Value < 256;
695 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000696 bool isImm0_4095() const {
697 if (!isImm()) return false;
698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return Value >= 0 && Value < 4096;
702 }
703 bool isImm0_4095Neg() const {
704 if (!isImm()) return false;
705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = -CE->getValue();
708 return Value > 0 && Value < 4096;
709 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000710 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000711 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value >= 0 && Value < 2;
716 }
717 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000718 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = CE->getValue();
722 return Value >= 0 && Value < 4;
723 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000724 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000725 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value >= 0 && Value < 8;
730 }
731 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000732 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 16;
737 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000738 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value >= 0 && Value < 32;
744 }
Jim Grosbach00326402011-12-08 01:30:04 +0000745 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 64;
751 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000752 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value == 8;
758 }
759 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 if (!CE) return false;
763 int64_t Value = CE->getValue();
764 return Value == 16;
765 }
766 bool isImm32() 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 == 32;
772 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000773 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value > 0 && Value <= 8;
779 }
780 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value > 0 && Value <= 16;
786 }
787 bool isShrImm32() 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 <= 32;
793 }
794 bool isShrImm64() 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 <= 64;
800 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000801 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value > 0 && Value < 8;
807 }
808 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value > 0 && Value < 16;
814 }
815 bool isImm1_31() 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 < 32;
821 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000822 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000823 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value > 0 && Value < 17;
828 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000829 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000830 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value > 0 && Value < 33;
835 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000836 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value >= 0 && Value < 33;
842 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000843 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value >= 0 && Value < 65536;
849 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000850 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 // If it's not a constant expression, it'll generate a fixup and be
854 // handled later.
855 if (!CE) return true;
856 int64_t Value = CE->getValue();
857 return Value >= 0 && Value < 65536;
858 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000859 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000860 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
862 if (!CE) return false;
863 int64_t Value = CE->getValue();
864 return Value >= 0 && Value <= 0xffffff;
865 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000866 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000867 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
869 if (!CE) return false;
870 int64_t Value = CE->getValue();
871 return Value > 0 && Value < 33;
872 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000873 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000874 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value < 32;
879 }
880 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value > 0 && Value <= 32;
886 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000887 bool isAdrLabel() const {
888 // If we have an immediate that's not a constant, treat it as a label
889 // reference needing a fixup. If it is a constant, but it can't fit
890 // into shift immediate encoding, we reject it.
891 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
892 else return (isARMSOImm() || isARMSOImmNeg());
893 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000894 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000895 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return ARM_AM::getSOImmVal(Value) != -1;
900 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000901 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000902 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Value = CE->getValue();
906 return ARM_AM::getSOImmVal(~Value) != -1;
907 }
Jim Grosbach30506252011-12-08 00:31:07 +0000908 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000909 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
911 if (!CE) return false;
912 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000913 // Only use this when not representable as a plain so_imm.
914 return ARM_AM::getSOImmVal(Value) == -1 &&
915 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000916 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000917 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000918 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
920 if (!CE) return false;
921 int64_t Value = CE->getValue();
922 return ARM_AM::getT2SOImmVal(Value) != -1;
923 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000924 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000925 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
927 if (!CE) return false;
928 int64_t Value = CE->getValue();
929 return ARM_AM::getT2SOImmVal(~Value) != -1;
930 }
Jim Grosbach30506252011-12-08 00:31:07 +0000931 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000932 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000936 // Only use this when not representable as a plain so_imm.
937 return ARM_AM::getT2SOImmVal(Value) == -1 &&
938 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000939 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000940 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000941 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return Value == 1 || Value == 0;
946 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000947 bool isReg() const { return Kind == k_Register; }
948 bool isRegList() const { return Kind == k_RegisterList; }
949 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
950 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
951 bool isToken() const { return Kind == k_Token; }
952 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000953 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000954 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000955 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
956 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
957 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
958 bool isRotImm() const { return Kind == k_RotateImmediate; }
959 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
960 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000961 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000962 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000963 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000964 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000965 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000966 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000967 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000968 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
969 (alignOK || Memory.Alignment == 0);
970 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000971 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000972 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000973 return false;
974 // Base register must be PC.
975 if (Memory.BaseRegNum != ARM::PC)
976 return false;
977 // Immediate offset in range [-4095, 4095].
978 if (!Memory.OffsetImm) return true;
979 int64_t Val = Memory.OffsetImm->getValue();
980 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
981 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000982 bool isAlignedMemory() const {
983 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000984 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000985 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000986 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000987 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000988 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000989 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000990 if (!Memory.OffsetImm) return true;
991 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000992 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000993 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000994 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000995 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000996 // Immediate offset in range [-4095, 4095].
997 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
998 if (!CE) return false;
999 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001000 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001001 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001002 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001003 // If we have an immediate that's not a constant, treat it as a label
1004 // reference needing a fixup. If it is a constant, it's something else
1005 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001006 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001007 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001008 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001009 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001010 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001011 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001012 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001013 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001014 if (!Memory.OffsetImm) return true;
1015 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001016 // The #-0 offset is encoded as INT32_MIN, and we have to check
1017 // for this too.
1018 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001019 }
1020 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001021 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001022 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001023 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001024 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1025 // Immediate offset in range [-255, 255].
1026 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1027 if (!CE) return false;
1028 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001029 // Special case, #-0 is INT32_MIN.
1030 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001031 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001032 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001033 // If we have an immediate that's not a constant, treat it as a label
1034 // reference needing a fixup. If it is a constant, it's something else
1035 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001036 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001037 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001038 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001039 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001040 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001041 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001042 if (!Memory.OffsetImm) return true;
1043 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001044 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001045 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001046 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001047 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001048 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001049 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001050 return false;
1051 return true;
1052 }
1053 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001054 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001055 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1056 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001057 return false;
1058 return true;
1059 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001060 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001061 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001062 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001063 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001064 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001065 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001066 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001067 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001068 return false;
1069 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001070 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001071 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001072 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001073 return false;
1074 return true;
1075 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001076 bool isMemThumbRR() const {
1077 // Thumb reg+reg addressing is simple. Just two registers, a base and
1078 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001079 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001080 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001081 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001082 return isARMLowRegister(Memory.BaseRegNum) &&
1083 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001084 }
1085 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001086 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001087 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001088 return false;
1089 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001090 if (!Memory.OffsetImm) return true;
1091 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001092 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1093 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001094 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001095 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001096 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001097 return false;
1098 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001099 if (!Memory.OffsetImm) return true;
1100 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001101 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1102 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001103 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001104 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001105 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001106 return false;
1107 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001108 if (!Memory.OffsetImm) return true;
1109 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001110 return Val >= 0 && Val <= 31;
1111 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001112 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001113 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001114 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001115 return false;
1116 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001117 if (!Memory.OffsetImm) return true;
1118 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001119 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001120 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001121 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001122 // If we have an immediate that's not a constant, treat it as a label
1123 // reference needing a fixup. If it is a constant, it's something else
1124 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001125 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001126 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001128 return false;
1129 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001130 if (!Memory.OffsetImm) return true;
1131 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001132 // Special case, #-0 is INT32_MIN.
1133 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001134 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001135 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001136 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001137 return false;
1138 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001139 if (!Memory.OffsetImm) return true;
1140 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001141 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1142 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001143 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001144 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001145 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001146 // Base reg of PC isn't allowed for these encodings.
1147 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001148 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001149 if (!Memory.OffsetImm) return true;
1150 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001151 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001152 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001153 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001154 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001155 return false;
1156 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001157 if (!Memory.OffsetImm) return true;
1158 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001159 return Val >= 0 && Val < 256;
1160 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001161 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001162 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001163 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001164 // Base reg of PC isn't allowed for these encodings.
1165 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001166 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001167 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001168 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001169 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001170 }
1171 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001172 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001173 return false;
1174 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001175 if (!Memory.OffsetImm) return true;
1176 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001177 return (Val >= 0 && Val < 4096);
1178 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001179 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001180 // If we have an immediate that's not a constant, treat it as a label
1181 // reference needing a fixup. If it is a constant, it's something else
1182 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001183 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001184 return true;
1185
Chad Rosier41099832012-09-11 23:02:35 +00001186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001187 return false;
1188 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001191 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001192 }
1193 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001194 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001195 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1196 if (!CE) return false;
1197 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001198 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001199 }
Jim Grosbach93981412011-10-11 21:55:36 +00001200 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001201 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1203 if (!CE) return false;
1204 int64_t Val = CE->getValue();
1205 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1206 (Val == INT32_MIN);
1207 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001208
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001209 bool isMSRMask() const { return Kind == k_MSRMask; }
1210 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001211
Jim Grosbach741cd732011-10-17 22:26:03 +00001212 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001213 bool isSingleSpacedVectorList() const {
1214 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1215 }
1216 bool isDoubleSpacedVectorList() const {
1217 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1218 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001219 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001220 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001221 return VectorList.Count == 1;
1222 }
1223
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001224 bool isVecListDPair() const {
1225 if (!isSingleSpacedVectorList()) return false;
1226 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1227 .contains(VectorList.RegNum));
1228 }
1229
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001230 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001231 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001232 return VectorList.Count == 3;
1233 }
1234
Jim Grosbach846bcff2011-10-21 20:35:01 +00001235 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001236 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001237 return VectorList.Count == 4;
1238 }
1239
Jim Grosbache5307f92012-03-05 21:43:40 +00001240 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001241 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001242 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1243 .contains(VectorList.RegNum));
1244 }
1245
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001246 bool isVecListThreeQ() const {
1247 if (!isDoubleSpacedVectorList()) return false;
1248 return VectorList.Count == 3;
1249 }
1250
Jim Grosbach1e946a42012-01-24 00:43:12 +00001251 bool isVecListFourQ() const {
1252 if (!isDoubleSpacedVectorList()) return false;
1253 return VectorList.Count == 4;
1254 }
1255
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001256 bool isSingleSpacedVectorAllLanes() const {
1257 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1258 }
1259 bool isDoubleSpacedVectorAllLanes() const {
1260 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1261 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001262 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001263 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001264 return VectorList.Count == 1;
1265 }
1266
Jim Grosbach13a292c2012-03-06 22:01:44 +00001267 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001268 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001269 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1270 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001271 }
1272
Jim Grosbached428bc2012-03-06 23:10:38 +00001273 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001274 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001275 return VectorList.Count == 2;
1276 }
1277
Jim Grosbachb78403c2012-01-24 23:47:04 +00001278 bool isVecListThreeDAllLanes() const {
1279 if (!isSingleSpacedVectorAllLanes()) return false;
1280 return VectorList.Count == 3;
1281 }
1282
1283 bool isVecListThreeQAllLanes() const {
1284 if (!isDoubleSpacedVectorAllLanes()) return false;
1285 return VectorList.Count == 3;
1286 }
1287
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001288 bool isVecListFourDAllLanes() const {
1289 if (!isSingleSpacedVectorAllLanes()) return false;
1290 return VectorList.Count == 4;
1291 }
1292
1293 bool isVecListFourQAllLanes() const {
1294 if (!isDoubleSpacedVectorAllLanes()) return false;
1295 return VectorList.Count == 4;
1296 }
1297
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001298 bool isSingleSpacedVectorIndexed() const {
1299 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1300 }
1301 bool isDoubleSpacedVectorIndexed() const {
1302 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1303 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001304 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001305 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001306 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1307 }
1308
Jim Grosbachda511042011-12-14 23:35:06 +00001309 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001310 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001311 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1312 }
1313
1314 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001315 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001316 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1317 }
1318
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001319 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001320 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001321 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1322 }
1323
Jim Grosbachda511042011-12-14 23:35:06 +00001324 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001325 if (!isSingleSpacedVectorIndexed()) return false;
1326 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1327 }
1328
1329 bool isVecListTwoQWordIndexed() const {
1330 if (!isDoubleSpacedVectorIndexed()) return false;
1331 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1332 }
1333
1334 bool isVecListTwoQHWordIndexed() const {
1335 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001336 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1337 }
1338
1339 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001340 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001341 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1342 }
1343
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001344 bool isVecListThreeDByteIndexed() const {
1345 if (!isSingleSpacedVectorIndexed()) return false;
1346 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1347 }
1348
1349 bool isVecListThreeDHWordIndexed() const {
1350 if (!isSingleSpacedVectorIndexed()) return false;
1351 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1352 }
1353
1354 bool isVecListThreeQWordIndexed() const {
1355 if (!isDoubleSpacedVectorIndexed()) return false;
1356 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1357 }
1358
1359 bool isVecListThreeQHWordIndexed() const {
1360 if (!isDoubleSpacedVectorIndexed()) return false;
1361 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1362 }
1363
1364 bool isVecListThreeDWordIndexed() const {
1365 if (!isSingleSpacedVectorIndexed()) return false;
1366 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1367 }
1368
Jim Grosbach14952a02012-01-24 18:37:25 +00001369 bool isVecListFourDByteIndexed() const {
1370 if (!isSingleSpacedVectorIndexed()) return false;
1371 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1372 }
1373
1374 bool isVecListFourDHWordIndexed() const {
1375 if (!isSingleSpacedVectorIndexed()) return false;
1376 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1377 }
1378
1379 bool isVecListFourQWordIndexed() const {
1380 if (!isDoubleSpacedVectorIndexed()) return false;
1381 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1382 }
1383
1384 bool isVecListFourQHWordIndexed() const {
1385 if (!isDoubleSpacedVectorIndexed()) return false;
1386 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1387 }
1388
1389 bool isVecListFourDWordIndexed() const {
1390 if (!isSingleSpacedVectorIndexed()) return false;
1391 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1392 }
1393
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001394 bool isVectorIndex8() const {
1395 if (Kind != k_VectorIndex) return false;
1396 return VectorIndex.Val < 8;
1397 }
1398 bool isVectorIndex16() const {
1399 if (Kind != k_VectorIndex) return false;
1400 return VectorIndex.Val < 4;
1401 }
1402 bool isVectorIndex32() const {
1403 if (Kind != k_VectorIndex) return false;
1404 return VectorIndex.Val < 2;
1405 }
1406
Jim Grosbach741cd732011-10-17 22:26:03 +00001407 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001408 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001409 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1410 // Must be a constant.
1411 if (!CE) return false;
1412 int64_t Value = CE->getValue();
1413 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1414 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001415 return Value >= 0 && Value < 256;
1416 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001417
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001418 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001419 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001420 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1421 // Must be a constant.
1422 if (!CE) return false;
1423 int64_t Value = CE->getValue();
1424 // i16 value in the range [0,255] or [0x0100, 0xff00]
1425 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1426 }
1427
Jim Grosbach8211c052011-10-18 00:22:00 +00001428 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001429 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1431 // Must be a constant.
1432 if (!CE) return false;
1433 int64_t Value = CE->getValue();
1434 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1435 return (Value >= 0 && Value < 256) ||
1436 (Value >= 0x0100 && Value <= 0xff00) ||
1437 (Value >= 0x010000 && Value <= 0xff0000) ||
1438 (Value >= 0x01000000 && Value <= 0xff000000);
1439 }
1440
1441 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001442 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001443 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1444 // Must be a constant.
1445 if (!CE) return false;
1446 int64_t Value = CE->getValue();
1447 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1448 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1449 return (Value >= 0 && Value < 256) ||
1450 (Value >= 0x0100 && Value <= 0xff00) ||
1451 (Value >= 0x010000 && Value <= 0xff0000) ||
1452 (Value >= 0x01000000 && Value <= 0xff000000) ||
1453 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1454 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1455 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001456 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001457 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001458 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1459 // Must be a constant.
1460 if (!CE) return false;
1461 int64_t Value = ~CE->getValue();
1462 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1463 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1464 return (Value >= 0 && Value < 256) ||
1465 (Value >= 0x0100 && Value <= 0xff00) ||
1466 (Value >= 0x010000 && Value <= 0xff0000) ||
1467 (Value >= 0x01000000 && Value <= 0xff000000) ||
1468 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1469 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1470 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001471
Jim Grosbache4454e02011-10-18 16:18:11 +00001472 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001473 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001474 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1475 // Must be a constant.
1476 if (!CE) return false;
1477 uint64_t Value = CE->getValue();
1478 // i64 value with each byte being either 0 or 0xff.
1479 for (unsigned i = 0; i < 8; ++i)
1480 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1481 return true;
1482 }
1483
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001484 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001485 // Add as immediates when possible. Null MCExpr = 0.
1486 if (Expr == 0)
1487 Inst.addOperand(MCOperand::CreateImm(0));
1488 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001489 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1490 else
1491 Inst.addOperand(MCOperand::CreateExpr(Expr));
1492 }
1493
Daniel Dunbard8042b72010-08-11 06:36:53 +00001494 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001495 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001496 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001497 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1498 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001499 }
1500
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001501 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1502 assert(N == 1 && "Invalid number of operands!");
1503 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1504 }
1505
Jim Grosbach48399582011-10-12 17:34:41 +00001506 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1509 }
1510
1511 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1514 }
1515
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001516 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1517 assert(N == 1 && "Invalid number of operands!");
1518 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1519 }
1520
1521 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1522 assert(N == 1 && "Invalid number of operands!");
1523 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1524 }
1525
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001526 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 Inst.addOperand(MCOperand::CreateReg(getReg()));
1529 }
1530
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001531 void addRegOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && "Invalid number of operands!");
1533 Inst.addOperand(MCOperand::CreateReg(getReg()));
1534 }
1535
Jim Grosbachac798e12011-07-25 20:49:51 +00001536 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001537 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001538 assert(isRegShiftedReg() &&
1539 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001540 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1541 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001542 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001543 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001544 }
1545
Jim Grosbachac798e12011-07-25 20:49:51 +00001546 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001547 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001548 assert(isRegShiftedImm() &&
1549 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001550 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001551 // Shift of #32 is encoded as 0 where permitted
1552 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001553 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001554 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001555 }
1556
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001557 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001558 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001559 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1560 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001561 }
1562
Bill Wendling8d2aa032010-11-08 23:49:57 +00001563 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001564 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001565 const SmallVectorImpl<unsigned> &RegList = getRegList();
1566 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001567 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1568 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001569 }
1570
Bill Wendling9898ac92010-11-17 04:32:08 +00001571 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1572 addRegListOperands(Inst, N);
1573 }
1574
1575 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1576 addRegListOperands(Inst, N);
1577 }
1578
Jim Grosbach833b9d32011-07-27 20:15:40 +00001579 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1580 assert(N == 1 && "Invalid number of operands!");
1581 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1582 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1583 }
1584
Jim Grosbach864b6092011-07-28 21:34:26 +00001585 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1586 assert(N == 1 && "Invalid number of operands!");
1587 // Munge the lsb/width into a bitfield mask.
1588 unsigned lsb = Bitfield.LSB;
1589 unsigned width = Bitfield.Width;
1590 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1591 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1592 (32 - (lsb + width)));
1593 Inst.addOperand(MCOperand::CreateImm(Mask));
1594 }
1595
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001596 void addImmOperands(MCInst &Inst, unsigned N) const {
1597 assert(N == 1 && "Invalid number of operands!");
1598 addExpr(Inst, getImm());
1599 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001600
Jim Grosbachea231912011-12-22 22:19:05 +00001601 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1604 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1605 }
1606
1607 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1610 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1611 }
1612
Jim Grosbache7fbce72011-10-03 23:38:36 +00001613 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1614 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1616 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1617 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001618 }
1619
Jim Grosbach7db8d692011-09-08 22:07:06 +00001620 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1621 assert(N == 1 && "Invalid number of operands!");
1622 // FIXME: We really want to scale the value here, but the LDRD/STRD
1623 // instruction don't encode operands that way yet.
1624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1625 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1626 }
1627
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001628 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 // The immediate is scaled by four in the encoding and is stored
1631 // in the MCInst as such. Lop off the low two bits here.
1632 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1633 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1634 }
1635
Jim Grosbach930f2f62012-04-05 20:57:13 +00001636 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1637 assert(N == 1 && "Invalid number of operands!");
1638 // The immediate is scaled by four in the encoding and is stored
1639 // in the MCInst as such. Lop off the low two bits here.
1640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1641 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1642 }
1643
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001644 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1645 assert(N == 1 && "Invalid number of operands!");
1646 // The immediate is scaled by four in the encoding and is stored
1647 // in the MCInst as such. Lop off the low two bits here.
1648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1649 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1650 }
1651
Jim Grosbach475c6db2011-07-25 23:09:14 +00001652 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 // The constant encodes as the immediate-1, and we store in the instruction
1655 // the bits as encoded, so subtract off one here.
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1658 }
1659
Jim Grosbach801e0a32011-07-22 23:16:18 +00001660 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 // The constant encodes as the immediate-1, and we store in the instruction
1663 // the bits as encoded, so subtract off one here.
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1666 }
1667
Jim Grosbach46dd4132011-08-17 21:51:27 +00001668 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 // The constant encodes as the immediate, except for 32, which encodes as
1671 // zero.
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 unsigned Imm = CE->getValue();
1674 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1675 }
1676
Jim Grosbach27c1e252011-07-21 17:23:04 +00001677 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1678 assert(N == 1 && "Invalid number of operands!");
1679 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1680 // the instruction as well.
1681 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1682 int Val = CE->getValue();
1683 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1684 }
1685
Jim Grosbachb009a872011-10-28 22:36:30 +00001686 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1687 assert(N == 1 && "Invalid number of operands!");
1688 // The operand is actually a t2_so_imm, but we have its bitwise
1689 // negation in the assembly source, so twiddle it here.
1690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1691 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1692 }
1693
Jim Grosbach30506252011-12-08 00:31:07 +00001694 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1695 assert(N == 1 && "Invalid number of operands!");
1696 // The operand is actually a t2_so_imm, but we have its
1697 // negation in the assembly source, so twiddle it here.
1698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1699 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1700 }
1701
Jim Grosbach930f2f62012-04-05 20:57:13 +00001702 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1703 assert(N == 1 && "Invalid number of operands!");
1704 // The operand is actually an imm0_4095, but we have its
1705 // negation in the assembly source, so twiddle it here.
1706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1707 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1708 }
1709
Mihai Popad36cbaa2013-07-03 09:21:44 +00001710 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1711 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1712 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1713 return;
1714 }
1715
1716 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1717 assert(SR && "Unknown value type!");
1718 Inst.addOperand(MCOperand::CreateExpr(SR));
1719 }
1720
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001721 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1722 assert(N == 1 && "Invalid number of operands!");
1723 if (isImm()) {
1724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1725 if (CE) {
1726 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
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 return;
1734 }
1735
1736 assert(isMem() && "Unknown value type!");
1737 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1738 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1739 }
1740
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001741 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1742 assert(N == 1 && "Invalid number of operands!");
1743 // The operand is actually a so_imm, but we have its bitwise
1744 // negation in the assembly source, so twiddle it here.
1745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1746 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1747 }
1748
Jim Grosbach30506252011-12-08 00:31:07 +00001749 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 // The operand is actually a so_imm, but we have its
1752 // negation in the assembly source, so twiddle it here.
1753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1754 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1755 }
1756
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001757 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1758 assert(N == 1 && "Invalid number of operands!");
1759 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1760 }
1761
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001762 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1763 assert(N == 1 && "Invalid number of operands!");
1764 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1765 }
1766
Jim Grosbachd3595712011-08-03 23:50:40 +00001767 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1768 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001769 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001770 }
1771
Jim Grosbach94298a92012-01-18 22:46:46 +00001772 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1773 assert(N == 1 && "Invalid number of operands!");
1774 int32_t Imm = Memory.OffsetImm->getValue();
1775 // FIXME: Handle #-0
1776 if (Imm == INT32_MIN) Imm = 0;
1777 Inst.addOperand(MCOperand::CreateImm(Imm));
1778 }
1779
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001780 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1781 assert(N == 1 && "Invalid number of operands!");
1782 assert(isImm() && "Not an immediate!");
1783
1784 // If we have an immediate that's not a constant, treat it as a label
1785 // reference needing a fixup.
1786 if (!isa<MCConstantExpr>(getImm())) {
1787 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1788 return;
1789 }
1790
1791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1792 int Val = CE->getValue();
1793 Inst.addOperand(MCOperand::CreateImm(Val));
1794 }
1795
Jim Grosbacha95ec992011-10-11 17:29:55 +00001796 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 2 && "Invalid number of operands!");
1798 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1799 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1800 }
1801
Jim Grosbachd3595712011-08-03 23:50:40 +00001802 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1803 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001804 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1805 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001806 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1807 // Special case for #-0
1808 if (Val == INT32_MIN) Val = 0;
1809 if (Val < 0) Val = -Val;
1810 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1811 } else {
1812 // For register offset, we encode the shift type and negation flag
1813 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001814 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1815 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001816 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001817 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1818 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001819 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001820 }
1821
Jim Grosbachcd17c122011-08-04 23:01:30 +00001822 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1823 assert(N == 2 && "Invalid number of operands!");
1824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1825 assert(CE && "non-constant AM2OffsetImm operand!");
1826 int32_t Val = CE->getValue();
1827 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1828 // Special case for #-0
1829 if (Val == INT32_MIN) Val = 0;
1830 if (Val < 0) Val = -Val;
1831 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1832 Inst.addOperand(MCOperand::CreateReg(0));
1833 Inst.addOperand(MCOperand::CreateImm(Val));
1834 }
1835
Jim Grosbach5b96b802011-08-10 20:29:19 +00001836 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1837 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001838 // If we have an immediate that's not a constant, treat it as a label
1839 // reference needing a fixup. If it is a constant, it's something else
1840 // and we reject it.
1841 if (isImm()) {
1842 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1843 Inst.addOperand(MCOperand::CreateReg(0));
1844 Inst.addOperand(MCOperand::CreateImm(0));
1845 return;
1846 }
1847
Jim Grosbach871dff72011-10-11 15:59:20 +00001848 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1849 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001850 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1851 // Special case for #-0
1852 if (Val == INT32_MIN) Val = 0;
1853 if (Val < 0) Val = -Val;
1854 Val = ARM_AM::getAM3Opc(AddSub, Val);
1855 } else {
1856 // For register offset, we encode the shift type and negation flag
1857 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001858 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001859 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001860 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1861 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001862 Inst.addOperand(MCOperand::CreateImm(Val));
1863 }
1864
1865 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1866 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001867 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001868 int32_t Val =
1869 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1870 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1871 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001872 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001873 }
1874
1875 // Constant offset.
1876 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1877 int32_t Val = CE->getValue();
1878 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1879 // Special case for #-0
1880 if (Val == INT32_MIN) Val = 0;
1881 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001882 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001883 Inst.addOperand(MCOperand::CreateReg(0));
1884 Inst.addOperand(MCOperand::CreateImm(Val));
1885 }
1886
Jim Grosbachd3595712011-08-03 23:50:40 +00001887 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1888 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001889 // If we have an immediate that's not a constant, treat it as a label
1890 // reference needing a fixup. If it is a constant, it's something else
1891 // and we reject it.
1892 if (isImm()) {
1893 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1894 Inst.addOperand(MCOperand::CreateImm(0));
1895 return;
1896 }
1897
Jim Grosbachd3595712011-08-03 23:50:40 +00001898 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001899 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001900 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1901 // Special case for #-0
1902 if (Val == INT32_MIN) Val = 0;
1903 if (Val < 0) Val = -Val;
1904 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001905 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001906 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001907 }
1908
Jim Grosbach7db8d692011-09-08 22:07:06 +00001909 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1910 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001911 // If we have an immediate that's not a constant, treat it as a label
1912 // reference needing a fixup. If it is a constant, it's something else
1913 // and we reject it.
1914 if (isImm()) {
1915 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1916 Inst.addOperand(MCOperand::CreateImm(0));
1917 return;
1918 }
1919
Jim Grosbach871dff72011-10-11 15:59:20 +00001920 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1921 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001922 Inst.addOperand(MCOperand::CreateImm(Val));
1923 }
1924
Jim Grosbacha05627e2011-09-09 18:37:27 +00001925 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1926 assert(N == 2 && "Invalid number of operands!");
1927 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001928 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1929 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001930 Inst.addOperand(MCOperand::CreateImm(Val));
1931 }
1932
Jim Grosbachd3595712011-08-03 23:50:40 +00001933 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1934 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001935 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1936 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001937 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001938 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001939
Jim Grosbach2392c532011-09-07 23:39:14 +00001940 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1941 addMemImm8OffsetOperands(Inst, N);
1942 }
1943
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001944 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001945 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001946 }
1947
1948 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1949 assert(N == 2 && "Invalid number of operands!");
1950 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001951 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001952 addExpr(Inst, getImm());
1953 Inst.addOperand(MCOperand::CreateImm(0));
1954 return;
1955 }
1956
1957 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001958 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1959 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001960 Inst.addOperand(MCOperand::CreateImm(Val));
1961 }
1962
Jim Grosbachd3595712011-08-03 23:50:40 +00001963 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001965 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001966 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001967 addExpr(Inst, getImm());
1968 Inst.addOperand(MCOperand::CreateImm(0));
1969 return;
1970 }
1971
1972 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001973 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1974 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001975 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001976 }
Bill Wendling811c9362010-11-30 07:44:32 +00001977
Jim Grosbach05541f42011-09-19 22:21:13 +00001978 void addMemTBBOperands(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
1984 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1985 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001986 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1987 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001988 }
1989
Jim Grosbachd3595712011-08-03 23:50:40 +00001990 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001992 unsigned Val =
1993 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1994 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001995 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1996 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001997 Inst.addOperand(MCOperand::CreateImm(Val));
1998 }
1999
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002000 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2001 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002002 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2003 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2004 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002005 }
2006
Jim Grosbachd3595712011-08-03 23:50:40 +00002007 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2008 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002009 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2010 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002011 }
2012
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002013 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2014 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002015 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2016 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002017 Inst.addOperand(MCOperand::CreateImm(Val));
2018 }
2019
Jim Grosbach26d35872011-08-19 18:55:51 +00002020 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2021 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002022 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2023 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002024 Inst.addOperand(MCOperand::CreateImm(Val));
2025 }
2026
Jim Grosbacha32c7532011-08-19 18:49:59 +00002027 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2028 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002029 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2030 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002031 Inst.addOperand(MCOperand::CreateImm(Val));
2032 }
2033
Jim Grosbach23983d62011-08-19 18:13:48 +00002034 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2035 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002036 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2037 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002038 Inst.addOperand(MCOperand::CreateImm(Val));
2039 }
2040
Jim Grosbachd3595712011-08-03 23:50:40 +00002041 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2042 assert(N == 1 && "Invalid number of operands!");
2043 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2044 assert(CE && "non-constant post-idx-imm8 operand!");
2045 int Imm = CE->getValue();
2046 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002047 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002048 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2049 Inst.addOperand(MCOperand::CreateImm(Imm));
2050 }
2051
Jim Grosbach93981412011-10-11 21:55:36 +00002052 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2055 assert(CE && "non-constant post-idx-imm8s4 operand!");
2056 int Imm = CE->getValue();
2057 bool isAdd = Imm >= 0;
2058 if (Imm == INT32_MIN) Imm = 0;
2059 // Immediate is scaled by 4.
2060 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2061 Inst.addOperand(MCOperand::CreateImm(Imm));
2062 }
2063
Jim Grosbachd3595712011-08-03 23:50:40 +00002064 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 2 && "Invalid number of operands!");
2066 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002067 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2068 }
2069
2070 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2071 assert(N == 2 && "Invalid number of operands!");
2072 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2073 // The sign, shift type, and shift amount are encoded in a single operand
2074 // using the AM2 encoding helpers.
2075 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2076 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2077 PostIdxReg.ShiftTy);
2078 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002079 }
2080
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002081 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2082 assert(N == 1 && "Invalid number of operands!");
2083 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2084 }
2085
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002086 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2087 assert(N == 1 && "Invalid number of operands!");
2088 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2089 }
2090
Jim Grosbach182b6a02011-11-29 23:51:09 +00002091 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002092 assert(N == 1 && "Invalid number of operands!");
2093 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2094 }
2095
Jim Grosbach04945c42011-12-02 00:35:16 +00002096 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2097 assert(N == 2 && "Invalid number of operands!");
2098 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2099 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2100 }
2101
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002102 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2103 assert(N == 1 && "Invalid number of operands!");
2104 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2105 }
2106
2107 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2108 assert(N == 1 && "Invalid number of operands!");
2109 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2110 }
2111
2112 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2113 assert(N == 1 && "Invalid number of operands!");
2114 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2115 }
2116
Jim Grosbach741cd732011-10-17 22:26:03 +00002117 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2118 assert(N == 1 && "Invalid number of operands!");
2119 // The immediate encodes the type of constant as well as the value.
2120 // Mask in that this is an i8 splat.
2121 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2122 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2123 }
2124
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002125 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2126 assert(N == 1 && "Invalid number of operands!");
2127 // The immediate encodes the type of constant as well as the value.
2128 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2129 unsigned Value = CE->getValue();
2130 if (Value >= 256)
2131 Value = (Value >> 8) | 0xa00;
2132 else
2133 Value |= 0x800;
2134 Inst.addOperand(MCOperand::CreateImm(Value));
2135 }
2136
Jim Grosbach8211c052011-10-18 00:22:00 +00002137 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 // The immediate encodes the type of constant as well as the value.
2140 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2141 unsigned Value = CE->getValue();
2142 if (Value >= 256 && Value <= 0xff00)
2143 Value = (Value >> 8) | 0x200;
2144 else if (Value > 0xffff && Value <= 0xff0000)
2145 Value = (Value >> 16) | 0x400;
2146 else if (Value > 0xffffff)
2147 Value = (Value >> 24) | 0x600;
2148 Inst.addOperand(MCOperand::CreateImm(Value));
2149 }
2150
2151 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2152 assert(N == 1 && "Invalid number of operands!");
2153 // The immediate encodes the type of constant as well as the value.
2154 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2155 unsigned Value = CE->getValue();
2156 if (Value >= 256 && Value <= 0xffff)
2157 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2158 else if (Value > 0xffff && Value <= 0xffffff)
2159 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2160 else if (Value > 0xffffff)
2161 Value = (Value >> 24) | 0x600;
2162 Inst.addOperand(MCOperand::CreateImm(Value));
2163 }
2164
Jim Grosbach045b6c72011-12-19 23:51:07 +00002165 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2166 assert(N == 1 && "Invalid number of operands!");
2167 // The immediate encodes the type of constant as well as the value.
2168 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2169 unsigned Value = ~CE->getValue();
2170 if (Value >= 256 && Value <= 0xffff)
2171 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2172 else if (Value > 0xffff && Value <= 0xffffff)
2173 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2174 else if (Value > 0xffffff)
2175 Value = (Value >> 24) | 0x600;
2176 Inst.addOperand(MCOperand::CreateImm(Value));
2177 }
2178
Jim Grosbache4454e02011-10-18 16:18:11 +00002179 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2180 assert(N == 1 && "Invalid number of operands!");
2181 // The immediate encodes the type of constant as well as the value.
2182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2183 uint64_t Value = CE->getValue();
2184 unsigned Imm = 0;
2185 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2186 Imm |= (Value & 1) << i;
2187 }
2188 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2189 }
2190
Jim Grosbach602aa902011-07-13 15:34:57 +00002191 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002192
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002193 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002194 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002195 Op->ITMask.Mask = Mask;
2196 Op->StartLoc = S;
2197 Op->EndLoc = S;
2198 return Op;
2199 }
2200
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002201 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002202 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002203 Op->CC.Val = CC;
2204 Op->StartLoc = S;
2205 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002206 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002207 }
2208
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002209 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002210 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002211 Op->Cop.Val = CopVal;
2212 Op->StartLoc = S;
2213 Op->EndLoc = S;
2214 return Op;
2215 }
2216
2217 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002218 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002219 Op->Cop.Val = CopVal;
2220 Op->StartLoc = S;
2221 Op->EndLoc = S;
2222 return Op;
2223 }
2224
Jim Grosbach48399582011-10-12 17:34:41 +00002225 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2226 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2227 Op->Cop.Val = Val;
2228 Op->StartLoc = S;
2229 Op->EndLoc = E;
2230 return Op;
2231 }
2232
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002233 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002234 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002235 Op->Reg.RegNum = RegNum;
2236 Op->StartLoc = S;
2237 Op->EndLoc = S;
2238 return Op;
2239 }
2240
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002241 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002242 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002243 Op->Tok.Data = Str.data();
2244 Op->Tok.Length = Str.size();
2245 Op->StartLoc = S;
2246 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002247 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002248 }
2249
Bill Wendling2063b842010-11-18 23:43:05 +00002250 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002251 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002252 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002253 Op->StartLoc = S;
2254 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002255 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002256 }
2257
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002258 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2259 unsigned SrcReg,
2260 unsigned ShiftReg,
2261 unsigned ShiftImm,
2262 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002263 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002264 Op->RegShiftedReg.ShiftTy = ShTy;
2265 Op->RegShiftedReg.SrcReg = SrcReg;
2266 Op->RegShiftedReg.ShiftReg = ShiftReg;
2267 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002268 Op->StartLoc = S;
2269 Op->EndLoc = E;
2270 return Op;
2271 }
2272
Owen Andersonb595ed02011-07-21 18:54:16 +00002273 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2274 unsigned SrcReg,
2275 unsigned ShiftImm,
2276 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002277 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002278 Op->RegShiftedImm.ShiftTy = ShTy;
2279 Op->RegShiftedImm.SrcReg = SrcReg;
2280 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002281 Op->StartLoc = S;
2282 Op->EndLoc = E;
2283 return Op;
2284 }
2285
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002286 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002287 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002288 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002289 Op->ShifterImm.isASR = isASR;
2290 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002291 Op->StartLoc = S;
2292 Op->EndLoc = E;
2293 return Op;
2294 }
2295
Jim Grosbach833b9d32011-07-27 20:15:40 +00002296 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002297 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002298 Op->RotImm.Imm = Imm;
2299 Op->StartLoc = S;
2300 Op->EndLoc = E;
2301 return Op;
2302 }
2303
Jim Grosbach864b6092011-07-28 21:34:26 +00002304 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2305 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002306 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002307 Op->Bitfield.LSB = LSB;
2308 Op->Bitfield.Width = Width;
2309 Op->StartLoc = S;
2310 Op->EndLoc = E;
2311 return Op;
2312 }
2313
Bill Wendling2cae3272010-11-09 22:44:22 +00002314 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002315 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002316 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002317 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002318 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002319
Chad Rosierfa705ee2013-07-01 20:49:23 +00002320 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002321 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002322 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002323 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002324 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002325
Chad Rosierfa705ee2013-07-01 20:49:23 +00002326 // Sort based on the register encoding values.
2327 array_pod_sort(Regs.begin(), Regs.end());
2328
Bill Wendling9898ac92010-11-17 04:32:08 +00002329 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002330 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002331 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002332 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002333 Op->StartLoc = StartLoc;
2334 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002335 return Op;
2336 }
2337
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002338 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002339 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002340 ARMOperand *Op = new ARMOperand(k_VectorList);
2341 Op->VectorList.RegNum = RegNum;
2342 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002343 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002344 Op->StartLoc = S;
2345 Op->EndLoc = E;
2346 return Op;
2347 }
2348
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002349 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002350 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002351 SMLoc S, SMLoc E) {
2352 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2353 Op->VectorList.RegNum = RegNum;
2354 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002355 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002356 Op->StartLoc = S;
2357 Op->EndLoc = E;
2358 return Op;
2359 }
2360
Jim Grosbach04945c42011-12-02 00:35:16 +00002361 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002362 unsigned Index,
2363 bool isDoubleSpaced,
2364 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002365 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2366 Op->VectorList.RegNum = RegNum;
2367 Op->VectorList.Count = Count;
2368 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002369 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002370 Op->StartLoc = S;
2371 Op->EndLoc = E;
2372 return Op;
2373 }
2374
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002375 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2376 MCContext &Ctx) {
2377 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2378 Op->VectorIndex.Val = Idx;
2379 Op->StartLoc = S;
2380 Op->EndLoc = E;
2381 return Op;
2382 }
2383
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002384 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002385 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002386 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002387 Op->StartLoc = S;
2388 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002389 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002390 }
2391
Jim Grosbachd3595712011-08-03 23:50:40 +00002392 static ARMOperand *CreateMem(unsigned BaseRegNum,
2393 const MCConstantExpr *OffsetImm,
2394 unsigned OffsetRegNum,
2395 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002396 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002397 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002398 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002399 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002400 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002401 Op->Memory.BaseRegNum = BaseRegNum;
2402 Op->Memory.OffsetImm = OffsetImm;
2403 Op->Memory.OffsetRegNum = OffsetRegNum;
2404 Op->Memory.ShiftType = ShiftType;
2405 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002406 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002407 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002408 Op->StartLoc = S;
2409 Op->EndLoc = E;
2410 return Op;
2411 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002412
Jim Grosbachc320c852011-08-05 21:28:30 +00002413 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2414 ARM_AM::ShiftOpc ShiftTy,
2415 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002416 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002417 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002418 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002419 Op->PostIdxReg.isAdd = isAdd;
2420 Op->PostIdxReg.ShiftTy = ShiftTy;
2421 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002422 Op->StartLoc = S;
2423 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002424 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002425 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002426
2427 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002428 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002429 Op->MBOpt.Val = Opt;
2430 Op->StartLoc = S;
2431 Op->EndLoc = S;
2432 return Op;
2433 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002434
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002435 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2436 SMLoc S) {
2437 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2438 Op->ISBOpt.Val = Opt;
2439 Op->StartLoc = S;
2440 Op->EndLoc = S;
2441 return Op;
2442 }
2443
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002444 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002445 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002446 Op->IFlags.Val = IFlags;
2447 Op->StartLoc = S;
2448 Op->EndLoc = S;
2449 return Op;
2450 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002451
2452 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002453 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002454 Op->MMask.Val = MMask;
2455 Op->StartLoc = S;
2456 Op->EndLoc = S;
2457 return Op;
2458 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002459};
2460
2461} // end anonymous namespace.
2462
Jim Grosbach602aa902011-07-13 15:34:57 +00002463void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002464 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002465 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002466 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002468 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002469 OS << "<ccout " << getReg() << ">";
2470 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002471 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002472 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002473 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2474 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2475 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002476 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2477 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2478 break;
2479 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002480 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002481 OS << "<coprocessor number: " << getCoproc() << ">";
2482 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002483 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002484 OS << "<coprocessor register: " << getCoproc() << ">";
2485 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002486 case k_CoprocOption:
2487 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002489 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002490 OS << "<mask: " << getMSRMask() << ">";
2491 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002492 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002493 getImm()->print(OS);
2494 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002495 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002496 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2497 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002498 case k_InstSyncBarrierOpt:
2499 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2500 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002501 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002502 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002503 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002504 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002505 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002506 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002507 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2508 << PostIdxReg.RegNum;
2509 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2510 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2511 << PostIdxReg.ShiftImm;
2512 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002514 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002515 OS << "<ARM_PROC::";
2516 unsigned IFlags = getProcIFlags();
2517 for (int i=2; i >= 0; --i)
2518 if (IFlags & (1 << i))
2519 OS << ARM_PROC::IFlagsToString(1 << i);
2520 OS << ">";
2521 break;
2522 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002523 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002524 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002525 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002526 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002527 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2528 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002530 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002531 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002532 << RegShiftedReg.SrcReg << " "
2533 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2534 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002536 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002537 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002538 << RegShiftedImm.SrcReg << " "
2539 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2540 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002541 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002542 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002543 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2544 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002545 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002546 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2547 << ", width: " << Bitfield.Width << ">";
2548 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002549 case k_RegisterList:
2550 case k_DPRRegisterList:
2551 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002552 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002553
Bill Wendlingbed94652010-11-09 23:28:44 +00002554 const SmallVectorImpl<unsigned> &RegList = getRegList();
2555 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002556 I = RegList.begin(), E = RegList.end(); I != E; ) {
2557 OS << *I;
2558 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002559 }
2560
2561 OS << ">";
2562 break;
2563 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002564 case k_VectorList:
2565 OS << "<vector_list " << VectorList.Count << " * "
2566 << VectorList.RegNum << ">";
2567 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002568 case k_VectorListAllLanes:
2569 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2570 << VectorList.RegNum << ">";
2571 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002572 case k_VectorListIndexed:
2573 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2574 << VectorList.Count << " * " << VectorList.RegNum << ">";
2575 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002576 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002577 OS << "'" << getToken() << "'";
2578 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002579 case k_VectorIndex:
2580 OS << "<vectorindex " << getVectorIndex() << ">";
2581 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002582 }
2583}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002584
2585/// @name Auto-generated Match Functions
2586/// {
2587
2588static unsigned MatchRegisterName(StringRef Name);
2589
2590/// }
2591
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002592bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2593 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002594 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002595 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002596 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002597
2598 return (RegNo == (unsigned)-1);
2599}
2600
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002601/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002602/// and if it is a register name the token is eaten and the register number is
2603/// returned. Otherwise return -1.
2604///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002605int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002606 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002607 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002608
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002609 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002610 unsigned RegNum = MatchRegisterName(lowerCase);
2611 if (!RegNum) {
2612 RegNum = StringSwitch<unsigned>(lowerCase)
2613 .Case("r13", ARM::SP)
2614 .Case("r14", ARM::LR)
2615 .Case("r15", ARM::PC)
2616 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002617 // Additional register name aliases for 'gas' compatibility.
2618 .Case("a1", ARM::R0)
2619 .Case("a2", ARM::R1)
2620 .Case("a3", ARM::R2)
2621 .Case("a4", ARM::R3)
2622 .Case("v1", ARM::R4)
2623 .Case("v2", ARM::R5)
2624 .Case("v3", ARM::R6)
2625 .Case("v4", ARM::R7)
2626 .Case("v5", ARM::R8)
2627 .Case("v6", ARM::R9)
2628 .Case("v7", ARM::R10)
2629 .Case("v8", ARM::R11)
2630 .Case("sb", ARM::R9)
2631 .Case("sl", ARM::R10)
2632 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002633 .Default(0);
2634 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002635 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002636 // Check for aliases registered via .req. Canonicalize to lower case.
2637 // That's more consistent since register names are case insensitive, and
2638 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2639 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002640 // If no match, return failure.
2641 if (Entry == RegisterReqs.end())
2642 return -1;
2643 Parser.Lex(); // Eat identifier token.
2644 return Entry->getValue();
2645 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002646
Chris Lattner44e5981c2010-10-30 04:09:10 +00002647 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002648
Chris Lattner44e5981c2010-10-30 04:09:10 +00002649 return RegNum;
2650}
Jim Grosbach99710a82010-11-01 16:44:21 +00002651
Jim Grosbachbb24c592011-07-13 18:49:30 +00002652// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2653// If a recoverable error occurs, return 1. If an irrecoverable error
2654// occurs, return -1. An irrecoverable error is one where tokens have been
2655// consumed in the process of trying to parse the shifter (i.e., when it is
2656// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002657int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002658 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2659 SMLoc S = Parser.getTok().getLoc();
2660 const AsmToken &Tok = Parser.getTok();
2661 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2662
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002663 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002664 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002665 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002666 .Case("lsl", ARM_AM::lsl)
2667 .Case("lsr", ARM_AM::lsr)
2668 .Case("asr", ARM_AM::asr)
2669 .Case("ror", ARM_AM::ror)
2670 .Case("rrx", ARM_AM::rrx)
2671 .Default(ARM_AM::no_shift);
2672
2673 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002674 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002675
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002676 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002677
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002678 // The source register for the shift has already been added to the
2679 // operand list, so we need to pop it off and combine it into the shifted
2680 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002681 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002682 if (!PrevOp->isReg())
2683 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2684 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002685
2686 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002687 int64_t Imm = 0;
2688 int ShiftReg = 0;
2689 if (ShiftTy == ARM_AM::rrx) {
2690 // RRX Doesn't have an explicit shift amount. The encoder expects
2691 // the shift register to be the same as the source register. Seems odd,
2692 // but OK.
2693 ShiftReg = SrcReg;
2694 } else {
2695 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002696 if (Parser.getTok().is(AsmToken::Hash) ||
2697 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002698 Parser.Lex(); // Eat hash.
2699 SMLoc ImmLoc = Parser.getTok().getLoc();
2700 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002701 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002702 Error(ImmLoc, "invalid immediate shift value");
2703 return -1;
2704 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002705 // The expression must be evaluatable as an immediate.
2706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002707 if (!CE) {
2708 Error(ImmLoc, "invalid immediate shift value");
2709 return -1;
2710 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002711 // Range check the immediate.
2712 // lsl, ror: 0 <= imm <= 31
2713 // lsr, asr: 0 <= imm <= 32
2714 Imm = CE->getValue();
2715 if (Imm < 0 ||
2716 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2717 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002718 Error(ImmLoc, "immediate shift value out of range");
2719 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002720 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002721 // shift by zero is a nop. Always send it through as lsl.
2722 // ('as' compatibility)
2723 if (Imm == 0)
2724 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002725 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002726 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002727 EndLoc = Parser.getTok().getEndLoc();
2728 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002729 if (ShiftReg == -1) {
2730 Error (L, "expected immediate or register in shift operand");
2731 return -1;
2732 }
2733 } else {
2734 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002735 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002736 return -1;
2737 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002738 }
2739
Owen Andersonb595ed02011-07-21 18:54:16 +00002740 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2741 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002742 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002743 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002744 else
2745 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002746 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002747
Jim Grosbachbb24c592011-07-13 18:49:30 +00002748 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002749}
2750
2751
Bill Wendling2063b842010-11-18 23:43:05 +00002752/// Try to parse a register name. The token must be an Identifier when called.
2753/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2754/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002755///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002756/// TODO this is likely to change to allow different register types and or to
2757/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002758bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002759tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002760 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002761 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002762 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002763 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002764
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002765 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2766 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002767
Chris Lattner44e5981c2010-10-30 04:09:10 +00002768 const AsmToken &ExclaimTok = Parser.getTok();
2769 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002770 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2771 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002772 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002773 return false;
2774 }
2775
2776 // Also check for an index operand. This is only legal for vector registers,
2777 // but that'll get caught OK in operand matching, so we don't need to
2778 // explicitly filter everything else out here.
2779 if (Parser.getTok().is(AsmToken::LBrac)) {
2780 SMLoc SIdx = Parser.getTok().getLoc();
2781 Parser.Lex(); // Eat left bracket token.
2782
2783 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002784 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002785 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002786 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002787 if (!MCE)
2788 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002789
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002790 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002791 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002792
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002793 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002794 Parser.Lex(); // Eat right bracket token.
2795
2796 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2797 SIdx, E,
2798 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002799 }
2800
Bill Wendling2063b842010-11-18 23:43:05 +00002801 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002802}
2803
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002804/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2805/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2806/// "c5", ...
2807static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002808 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2809 // but efficient.
2810 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002811 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002812 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002813 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002814 return -1;
2815 switch (Name[1]) {
2816 default: return -1;
2817 case '0': return 0;
2818 case '1': return 1;
2819 case '2': return 2;
2820 case '3': return 3;
2821 case '4': return 4;
2822 case '5': return 5;
2823 case '6': return 6;
2824 case '7': return 7;
2825 case '8': return 8;
2826 case '9': return 9;
2827 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002828 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002829 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002830 return -1;
2831 switch (Name[2]) {
2832 default: return -1;
2833 case '0': return 10;
2834 case '1': return 11;
2835 case '2': return 12;
2836 case '3': return 13;
2837 case '4': return 14;
2838 case '5': return 15;
2839 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002840 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002841}
2842
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002843/// parseITCondCode - Try to parse a condition code for an IT instruction.
2844ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2845parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2846 SMLoc S = Parser.getTok().getLoc();
2847 const AsmToken &Tok = Parser.getTok();
2848 if (!Tok.is(AsmToken::Identifier))
2849 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002850 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002851 .Case("eq", ARMCC::EQ)
2852 .Case("ne", ARMCC::NE)
2853 .Case("hs", ARMCC::HS)
2854 .Case("cs", ARMCC::HS)
2855 .Case("lo", ARMCC::LO)
2856 .Case("cc", ARMCC::LO)
2857 .Case("mi", ARMCC::MI)
2858 .Case("pl", ARMCC::PL)
2859 .Case("vs", ARMCC::VS)
2860 .Case("vc", ARMCC::VC)
2861 .Case("hi", ARMCC::HI)
2862 .Case("ls", ARMCC::LS)
2863 .Case("ge", ARMCC::GE)
2864 .Case("lt", ARMCC::LT)
2865 .Case("gt", ARMCC::GT)
2866 .Case("le", ARMCC::LE)
2867 .Case("al", ARMCC::AL)
2868 .Default(~0U);
2869 if (CC == ~0U)
2870 return MatchOperand_NoMatch;
2871 Parser.Lex(); // Eat the token.
2872
2873 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2874
2875 return MatchOperand_Success;
2876}
2877
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002878/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002879/// token must be an Identifier when called, and if it is a coprocessor
2880/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002881ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002882parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002883 SMLoc S = Parser.getTok().getLoc();
2884 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002885 if (Tok.isNot(AsmToken::Identifier))
2886 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002887
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002888 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002889 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002890 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002891
2892 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002893 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002894 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002895}
2896
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002897/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002898/// token must be an Identifier when called, and if it is a coprocessor
2899/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002900ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002901parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002902 SMLoc S = Parser.getTok().getLoc();
2903 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002904 if (Tok.isNot(AsmToken::Identifier))
2905 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002906
2907 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2908 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002909 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002910
2911 Parser.Lex(); // Eat identifier token.
2912 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002913 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002914}
2915
Jim Grosbach48399582011-10-12 17:34:41 +00002916/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2917/// coproc_option : '{' imm0_255 '}'
2918ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2919parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2920 SMLoc S = Parser.getTok().getLoc();
2921
2922 // If this isn't a '{', this isn't a coprocessor immediate operand.
2923 if (Parser.getTok().isNot(AsmToken::LCurly))
2924 return MatchOperand_NoMatch;
2925 Parser.Lex(); // Eat the '{'
2926
2927 const MCExpr *Expr;
2928 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002929 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002930 Error(Loc, "illegal expression");
2931 return MatchOperand_ParseFail;
2932 }
2933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2934 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2935 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2936 return MatchOperand_ParseFail;
2937 }
2938 int Val = CE->getValue();
2939
2940 // Check for and consume the closing '}'
2941 if (Parser.getTok().isNot(AsmToken::RCurly))
2942 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002943 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002944 Parser.Lex(); // Eat the '}'
2945
2946 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2947 return MatchOperand_Success;
2948}
2949
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002950// For register list parsing, we need to map from raw GPR register numbering
2951// to the enumeration values. The enumeration values aren't sorted by
2952// register number due to our using "sp", "lr" and "pc" as canonical names.
2953static unsigned getNextRegister(unsigned Reg) {
2954 // If this is a GPR, we need to do it manually, otherwise we can rely
2955 // on the sort ordering of the enumeration since the other reg-classes
2956 // are sane.
2957 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2958 return Reg + 1;
2959 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002960 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002961 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2962 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2963 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2964 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2965 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2966 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2967 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2968 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2969 }
2970}
2971
Jim Grosbach85a23432011-11-11 21:27:40 +00002972// Return the low-subreg of a given Q register.
2973static unsigned getDRegFromQReg(unsigned QReg) {
2974 switch (QReg) {
2975 default: llvm_unreachable("expected a Q register!");
2976 case ARM::Q0: return ARM::D0;
2977 case ARM::Q1: return ARM::D2;
2978 case ARM::Q2: return ARM::D4;
2979 case ARM::Q3: return ARM::D6;
2980 case ARM::Q4: return ARM::D8;
2981 case ARM::Q5: return ARM::D10;
2982 case ARM::Q6: return ARM::D12;
2983 case ARM::Q7: return ARM::D14;
2984 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002985 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002986 case ARM::Q10: return ARM::D20;
2987 case ARM::Q11: return ARM::D22;
2988 case ARM::Q12: return ARM::D24;
2989 case ARM::Q13: return ARM::D26;
2990 case ARM::Q14: return ARM::D28;
2991 case ARM::Q15: return ARM::D30;
2992 }
2993}
2994
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002995/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002996bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002997parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002998 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002999 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003000 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003001 Parser.Lex(); // Eat '{' token.
3002 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003003
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003004 // Check the first register in the list to see what register class
3005 // this is a list of.
3006 int Reg = tryParseRegister();
3007 if (Reg == -1)
3008 return Error(RegLoc, "register expected");
3009
Jim Grosbach85a23432011-11-11 21:27:40 +00003010 // The reglist instructions have at most 16 registers, so reserve
3011 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003012 int EReg = 0;
3013 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003014
3015 // Allow Q regs and just interpret them as the two D sub-registers.
3016 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3017 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003018 EReg = MRI->getEncodingValue(Reg);
3019 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003020 ++Reg;
3021 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003022 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003023 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3024 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3025 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3026 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3027 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3028 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3029 else
3030 return Error(RegLoc, "invalid register in register list");
3031
Jim Grosbach85a23432011-11-11 21:27:40 +00003032 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003033 EReg = MRI->getEncodingValue(Reg);
3034 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003035
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003036 // This starts immediately after the first register token in the list,
3037 // so we can see either a comma or a minus (range separator) as a legal
3038 // next token.
3039 while (Parser.getTok().is(AsmToken::Comma) ||
3040 Parser.getTok().is(AsmToken::Minus)) {
3041 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003042 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003043 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003044 int EndReg = tryParseRegister();
3045 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003046 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003047 // Allow Q regs and just interpret them as the two D sub-registers.
3048 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3049 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003050 // If the register is the same as the start reg, there's nothing
3051 // more to do.
3052 if (Reg == EndReg)
3053 continue;
3054 // The register must be in the same register class as the first.
3055 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003056 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003057 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003058 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003059 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003060
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003061 // Add all the registers in the range to the register list.
3062 while (Reg != EndReg) {
3063 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003064 EReg = MRI->getEncodingValue(Reg);
3065 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003066 }
3067 continue;
3068 }
3069 Parser.Lex(); // Eat the comma.
3070 RegLoc = Parser.getTok().getLoc();
3071 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003072 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003073 Reg = tryParseRegister();
3074 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003075 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003076 // Allow Q regs and just interpret them as the two D sub-registers.
3077 bool isQReg = false;
3078 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3079 Reg = getDRegFromQReg(Reg);
3080 isQReg = true;
3081 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003082 // The register must be in the same register class as the first.
3083 if (!RC->contains(Reg))
3084 return Error(RegLoc, "invalid register in register list");
3085 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003086 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003087 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3088 Warning(RegLoc, "register list not in ascending order");
3089 else
3090 return Error(RegLoc, "register list not in ascending order");
3091 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003092 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003093 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3094 ") in register list");
3095 continue;
3096 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003097 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003098 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3099 Reg != OldReg + 1)
3100 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003101 EReg = MRI->getEncodingValue(Reg);
3102 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3103 if (isQReg) {
3104 EReg = MRI->getEncodingValue(++Reg);
3105 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3106 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003107 }
3108
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003109 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003110 return Error(Parser.getTok().getLoc(), "'}' expected");
3111 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003112 Parser.Lex(); // Eat '}' token.
3113
Jim Grosbach18bf3632011-12-13 21:48:29 +00003114 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003115 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003116
3117 // The ARM system instruction variants for LDM/STM have a '^' token here.
3118 if (Parser.getTok().is(AsmToken::Caret)) {
3119 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3120 Parser.Lex(); // Eat '^' token.
3121 }
3122
Bill Wendling2063b842010-11-18 23:43:05 +00003123 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003124}
3125
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003126// Helper function to parse the lane index for vector lists.
3127ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003128parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003129 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003130 if (Parser.getTok().is(AsmToken::LBrac)) {
3131 Parser.Lex(); // Eat the '['.
3132 if (Parser.getTok().is(AsmToken::RBrac)) {
3133 // "Dn[]" is the 'all lanes' syntax.
3134 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003135 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003136 Parser.Lex(); // Eat the ']'.
3137 return MatchOperand_Success;
3138 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003139
3140 // There's an optional '#' token here. Normally there wouldn't be, but
3141 // inline assemble puts one in, and it's friendly to accept that.
3142 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003143 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003144
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003145 const MCExpr *LaneIndex;
3146 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003147 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003148 Error(Loc, "illegal expression");
3149 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003150 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003151 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3152 if (!CE) {
3153 Error(Loc, "lane index must be empty or an integer");
3154 return MatchOperand_ParseFail;
3155 }
3156 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3157 Error(Parser.getTok().getLoc(), "']' expected");
3158 return MatchOperand_ParseFail;
3159 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003160 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003161 Parser.Lex(); // Eat the ']'.
3162 int64_t Val = CE->getValue();
3163
3164 // FIXME: Make this range check context sensitive for .8, .16, .32.
3165 if (Val < 0 || Val > 7) {
3166 Error(Parser.getTok().getLoc(), "lane index out of range");
3167 return MatchOperand_ParseFail;
3168 }
3169 Index = Val;
3170 LaneKind = IndexedLane;
3171 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003172 }
3173 LaneKind = NoLanes;
3174 return MatchOperand_Success;
3175}
3176
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003177// parse a vector register list
3178ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3179parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003180 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003181 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003182 SMLoc S = Parser.getTok().getLoc();
3183 // As an extension (to match gas), support a plain D register or Q register
3184 // (without encosing curly braces) as a single or double entry list,
3185 // respectively.
3186 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003187 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003188 int Reg = tryParseRegister();
3189 if (Reg == -1)
3190 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003191 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003192 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003193 if (Res != MatchOperand_Success)
3194 return Res;
3195 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003196 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003197 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003198 break;
3199 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003200 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3201 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003202 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003203 case IndexedLane:
3204 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003205 LaneIndex,
3206 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003207 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003208 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003209 return MatchOperand_Success;
3210 }
3211 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3212 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003213 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003214 if (Res != MatchOperand_Success)
3215 return Res;
3216 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003217 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003218 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003219 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003220 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 break;
3222 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003223 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3224 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003225 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3226 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003227 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003228 case IndexedLane:
3229 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003230 LaneIndex,
3231 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003232 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003233 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003234 return MatchOperand_Success;
3235 }
3236 Error(S, "vector register expected");
3237 return MatchOperand_ParseFail;
3238 }
3239
3240 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003241 return MatchOperand_NoMatch;
3242
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003243 Parser.Lex(); // Eat '{' token.
3244 SMLoc RegLoc = Parser.getTok().getLoc();
3245
3246 int Reg = tryParseRegister();
3247 if (Reg == -1) {
3248 Error(RegLoc, "register expected");
3249 return MatchOperand_ParseFail;
3250 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003251 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003252 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003253 unsigned FirstReg = Reg;
3254 // The list is of D registers, but we also allow Q regs and just interpret
3255 // them as the two D sub-registers.
3256 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3257 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003258 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3259 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003260 ++Reg;
3261 ++Count;
3262 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003263
3264 SMLoc E;
3265 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003266 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003267
Jim Grosbache891fe82011-11-15 23:19:15 +00003268 while (Parser.getTok().is(AsmToken::Comma) ||
3269 Parser.getTok().is(AsmToken::Minus)) {
3270 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003271 if (!Spacing)
3272 Spacing = 1; // Register range implies a single spaced list.
3273 else if (Spacing == 2) {
3274 Error(Parser.getTok().getLoc(),
3275 "sequential registers in double spaced list");
3276 return MatchOperand_ParseFail;
3277 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003278 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003279 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003280 int EndReg = tryParseRegister();
3281 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003282 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003283 return MatchOperand_ParseFail;
3284 }
3285 // Allow Q regs and just interpret them as the two D sub-registers.
3286 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3287 EndReg = getDRegFromQReg(EndReg) + 1;
3288 // If the register is the same as the start reg, there's nothing
3289 // more to do.
3290 if (Reg == EndReg)
3291 continue;
3292 // The register must be in the same register class as the first.
3293 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003294 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003295 return MatchOperand_ParseFail;
3296 }
3297 // Ranges must go from low to high.
3298 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003299 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003300 return MatchOperand_ParseFail;
3301 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003302 // Parse the lane specifier if present.
3303 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003304 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003305 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3306 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003307 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003308 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003309 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003310 return MatchOperand_ParseFail;
3311 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003312
3313 // Add all the registers in the range to the register list.
3314 Count += EndReg - Reg;
3315 Reg = EndReg;
3316 continue;
3317 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003318 Parser.Lex(); // Eat the comma.
3319 RegLoc = Parser.getTok().getLoc();
3320 int OldReg = Reg;
3321 Reg = tryParseRegister();
3322 if (Reg == -1) {
3323 Error(RegLoc, "register expected");
3324 return MatchOperand_ParseFail;
3325 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003326 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003327 // It's OK to use the enumeration values directly here rather, as the
3328 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003329 //
3330 // The list is of D registers, but we also allow Q regs and just interpret
3331 // them as the two D sub-registers.
3332 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003333 if (!Spacing)
3334 Spacing = 1; // Register range implies a single spaced list.
3335 else if (Spacing == 2) {
3336 Error(RegLoc,
3337 "invalid register in double-spaced list (must be 'D' register')");
3338 return MatchOperand_ParseFail;
3339 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003340 Reg = getDRegFromQReg(Reg);
3341 if (Reg != OldReg + 1) {
3342 Error(RegLoc, "non-contiguous register range");
3343 return MatchOperand_ParseFail;
3344 }
3345 ++Reg;
3346 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003347 // Parse the lane specifier if present.
3348 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003349 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003350 SMLoc LaneLoc = Parser.getTok().getLoc();
3351 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3352 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003353 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003354 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003355 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003356 return MatchOperand_ParseFail;
3357 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003358 continue;
3359 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003360 // Normal D register.
3361 // Figure out the register spacing (single or double) of the list if
3362 // we don't know it already.
3363 if (!Spacing)
3364 Spacing = 1 + (Reg == OldReg + 2);
3365
3366 // Just check that it's contiguous and keep going.
3367 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003368 Error(RegLoc, "non-contiguous register range");
3369 return MatchOperand_ParseFail;
3370 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003371 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003372 // Parse the lane specifier if present.
3373 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003374 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003375 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003376 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003377 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003378 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003379 Error(EndLoc, "mismatched lane index in register list");
3380 return MatchOperand_ParseFail;
3381 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003382 }
3383
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003384 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003385 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003386 return MatchOperand_ParseFail;
3387 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003388 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003389 Parser.Lex(); // Eat '}' token.
3390
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003391 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003392 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003393 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003394 // composite register classes.
3395 if (Count == 2) {
3396 const MCRegisterClass *RC = (Spacing == 1) ?
3397 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3398 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3399 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3400 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003401
Jim Grosbach2f50e922011-12-15 21:44:33 +00003402 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3403 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003404 break;
3405 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003406 // Two-register operands have been converted to the
3407 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003408 if (Count == 2) {
3409 const MCRegisterClass *RC = (Spacing == 1) ?
3410 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3411 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003412 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3413 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003414 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003415 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003416 S, E));
3417 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003418 case IndexedLane:
3419 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003420 LaneIndex,
3421 (Spacing == 2),
3422 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003423 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003424 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003425 return MatchOperand_Success;
3426}
3427
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003428/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003429ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003430parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003431 SMLoc S = Parser.getTok().getLoc();
3432 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003433 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003434
Jiangning Liu288e1af2012-08-02 08:21:27 +00003435 if (Tok.is(AsmToken::Identifier)) {
3436 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003437
Jiangning Liu288e1af2012-08-02 08:21:27 +00003438 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3439 .Case("sy", ARM_MB::SY)
3440 .Case("st", ARM_MB::ST)
3441 .Case("sh", ARM_MB::ISH)
3442 .Case("ish", ARM_MB::ISH)
3443 .Case("shst", ARM_MB::ISHST)
3444 .Case("ishst", ARM_MB::ISHST)
3445 .Case("nsh", ARM_MB::NSH)
3446 .Case("un", ARM_MB::NSH)
3447 .Case("nshst", ARM_MB::NSHST)
3448 .Case("unst", ARM_MB::NSHST)
3449 .Case("osh", ARM_MB::OSH)
3450 .Case("oshst", ARM_MB::OSHST)
3451 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003452
Jiangning Liu288e1af2012-08-02 08:21:27 +00003453 if (Opt == ~0U)
3454 return MatchOperand_NoMatch;
3455
3456 Parser.Lex(); // Eat identifier token.
3457 } else if (Tok.is(AsmToken::Hash) ||
3458 Tok.is(AsmToken::Dollar) ||
3459 Tok.is(AsmToken::Integer)) {
3460 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003461 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003462 SMLoc Loc = Parser.getTok().getLoc();
3463
3464 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003465 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003466 Error(Loc, "illegal expression");
3467 return MatchOperand_ParseFail;
3468 }
3469
3470 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3471 if (!CE) {
3472 Error(Loc, "constant expression expected");
3473 return MatchOperand_ParseFail;
3474 }
3475
3476 int Val = CE->getValue();
3477 if (Val & ~0xf) {
3478 Error(Loc, "immediate value out of range");
3479 return MatchOperand_ParseFail;
3480 }
3481
3482 Opt = ARM_MB::RESERVED_0 + Val;
3483 } else
3484 return MatchOperand_ParseFail;
3485
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003486 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003487 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003488}
3489
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003490/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3491ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3492parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3493 SMLoc S = Parser.getTok().getLoc();
3494 const AsmToken &Tok = Parser.getTok();
3495 unsigned Opt;
3496
3497 if (Tok.is(AsmToken::Identifier)) {
3498 StringRef OptStr = Tok.getString();
3499
3500 if (OptStr.lower() == "sy")
3501 Opt = ARM_ISB::SY;
3502 else
3503 return MatchOperand_NoMatch;
3504
3505 Parser.Lex(); // Eat identifier token.
3506 } else if (Tok.is(AsmToken::Hash) ||
3507 Tok.is(AsmToken::Dollar) ||
3508 Tok.is(AsmToken::Integer)) {
3509 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003510 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003511 SMLoc Loc = Parser.getTok().getLoc();
3512
3513 const MCExpr *ISBarrierID;
3514 if (getParser().parseExpression(ISBarrierID)) {
3515 Error(Loc, "illegal expression");
3516 return MatchOperand_ParseFail;
3517 }
3518
3519 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3520 if (!CE) {
3521 Error(Loc, "constant expression expected");
3522 return MatchOperand_ParseFail;
3523 }
3524
3525 int Val = CE->getValue();
3526 if (Val & ~0xf) {
3527 Error(Loc, "immediate value out of range");
3528 return MatchOperand_ParseFail;
3529 }
3530
3531 Opt = ARM_ISB::RESERVED_0 + Val;
3532 } else
3533 return MatchOperand_ParseFail;
3534
3535 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3536 (ARM_ISB::InstSyncBOpt)Opt, S));
3537 return MatchOperand_Success;
3538}
3539
3540
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003541/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003542ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003543parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003544 SMLoc S = Parser.getTok().getLoc();
3545 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003546 if (!Tok.is(AsmToken::Identifier))
3547 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003548 StringRef IFlagsStr = Tok.getString();
3549
Owen Anderson10c5b122011-10-05 17:16:40 +00003550 // An iflags string of "none" is interpreted to mean that none of the AIF
3551 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003552 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003553 if (IFlagsStr != "none") {
3554 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3555 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3556 .Case("a", ARM_PROC::A)
3557 .Case("i", ARM_PROC::I)
3558 .Case("f", ARM_PROC::F)
3559 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003560
Owen Anderson10c5b122011-10-05 17:16:40 +00003561 // If some specific iflag is already set, it means that some letter is
3562 // present more than once, this is not acceptable.
3563 if (Flag == ~0U || (IFlags & Flag))
3564 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003565
Owen Anderson10c5b122011-10-05 17:16:40 +00003566 IFlags |= Flag;
3567 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003568 }
3569
3570 Parser.Lex(); // Eat identifier token.
3571 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3572 return MatchOperand_Success;
3573}
3574
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003575/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003576ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003577parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003578 SMLoc S = Parser.getTok().getLoc();
3579 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003580 if (!Tok.is(AsmToken::Identifier))
3581 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003582 StringRef Mask = Tok.getString();
3583
James Molloy21efa7d2011-09-28 14:21:38 +00003584 if (isMClass()) {
3585 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003586 std::string Name = Mask.lower();
3587 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003588 // Note: in the documentation:
3589 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3590 // for MSR APSR_nzcvq.
3591 // but we do make it an alias here. This is so to get the "mask encoding"
3592 // bits correct on MSR APSR writes.
3593 //
3594 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3595 // should really only be allowed when writing a special register. Note
3596 // they get dropped in the MRS instruction reading a special register as
3597 // the SYSm field is only 8 bits.
3598 //
3599 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3600 // includes the DSP extension but that is not checked.
3601 .Case("apsr", 0x800)
3602 .Case("apsr_nzcvq", 0x800)
3603 .Case("apsr_g", 0x400)
3604 .Case("apsr_nzcvqg", 0xc00)
3605 .Case("iapsr", 0x801)
3606 .Case("iapsr_nzcvq", 0x801)
3607 .Case("iapsr_g", 0x401)
3608 .Case("iapsr_nzcvqg", 0xc01)
3609 .Case("eapsr", 0x802)
3610 .Case("eapsr_nzcvq", 0x802)
3611 .Case("eapsr_g", 0x402)
3612 .Case("eapsr_nzcvqg", 0xc02)
3613 .Case("xpsr", 0x803)
3614 .Case("xpsr_nzcvq", 0x803)
3615 .Case("xpsr_g", 0x403)
3616 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003617 .Case("ipsr", 0x805)
3618 .Case("epsr", 0x806)
3619 .Case("iepsr", 0x807)
3620 .Case("msp", 0x808)
3621 .Case("psp", 0x809)
3622 .Case("primask", 0x810)
3623 .Case("basepri", 0x811)
3624 .Case("basepri_max", 0x812)
3625 .Case("faultmask", 0x813)
3626 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003627 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003628
James Molloy21efa7d2011-09-28 14:21:38 +00003629 if (FlagsVal == ~0U)
3630 return MatchOperand_NoMatch;
3631
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003632 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003633 // basepri, basepri_max and faultmask only valid for V7m.
3634 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003635
James Molloy21efa7d2011-09-28 14:21:38 +00003636 Parser.Lex(); // Eat identifier token.
3637 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3638 return MatchOperand_Success;
3639 }
3640
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003641 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3642 size_t Start = 0, Next = Mask.find('_');
3643 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003644 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003645 if (Next != StringRef::npos)
3646 Flags = Mask.slice(Next+1, Mask.size());
3647
3648 // FlagsVal contains the complete mask:
3649 // 3-0: Mask
3650 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3651 unsigned FlagsVal = 0;
3652
3653 if (SpecReg == "apsr") {
3654 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003655 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003656 .Case("g", 0x4) // same as CPSR_s
3657 .Case("nzcvqg", 0xc) // same as CPSR_fs
3658 .Default(~0U);
3659
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003660 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003661 if (!Flags.empty())
3662 return MatchOperand_NoMatch;
3663 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003664 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003665 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003666 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003667 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3668 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003669 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003670 for (int i = 0, e = Flags.size(); i != e; ++i) {
3671 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3672 .Case("c", 1)
3673 .Case("x", 2)
3674 .Case("s", 4)
3675 .Case("f", 8)
3676 .Default(~0U);
3677
3678 // If some specific flag is already set, it means that some letter is
3679 // present more than once, this is not acceptable.
3680 if (FlagsVal == ~0U || (FlagsVal & Flag))
3681 return MatchOperand_NoMatch;
3682 FlagsVal |= Flag;
3683 }
3684 } else // No match for special register.
3685 return MatchOperand_NoMatch;
3686
Owen Anderson03a173e2011-10-21 18:43:28 +00003687 // Special register without flags is NOT equivalent to "fc" flags.
3688 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3689 // two lines would enable gas compatibility at the expense of breaking
3690 // round-tripping.
3691 //
3692 // if (!FlagsVal)
3693 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003694
3695 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3696 if (SpecReg == "spsr")
3697 FlagsVal |= 16;
3698
3699 Parser.Lex(); // Eat identifier token.
3700 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3701 return MatchOperand_Success;
3702}
3703
Jim Grosbach27c1e252011-07-21 17:23:04 +00003704ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3705parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3706 int Low, int High) {
3707 const AsmToken &Tok = Parser.getTok();
3708 if (Tok.isNot(AsmToken::Identifier)) {
3709 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3710 return MatchOperand_ParseFail;
3711 }
3712 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003713 std::string LowerOp = Op.lower();
3714 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003715 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3716 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3717 return MatchOperand_ParseFail;
3718 }
3719 Parser.Lex(); // Eat shift type token.
3720
3721 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003722 if (Parser.getTok().isNot(AsmToken::Hash) &&
3723 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003724 Error(Parser.getTok().getLoc(), "'#' expected");
3725 return MatchOperand_ParseFail;
3726 }
3727 Parser.Lex(); // Eat hash token.
3728
3729 const MCExpr *ShiftAmount;
3730 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003731 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003732 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003733 Error(Loc, "illegal expression");
3734 return MatchOperand_ParseFail;
3735 }
3736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3737 if (!CE) {
3738 Error(Loc, "constant expression expected");
3739 return MatchOperand_ParseFail;
3740 }
3741 int Val = CE->getValue();
3742 if (Val < Low || Val > High) {
3743 Error(Loc, "immediate value out of range");
3744 return MatchOperand_ParseFail;
3745 }
3746
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003747 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003748
3749 return MatchOperand_Success;
3750}
3751
Jim Grosbach0a547702011-07-22 17:44:50 +00003752ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3753parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3754 const AsmToken &Tok = Parser.getTok();
3755 SMLoc S = Tok.getLoc();
3756 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003757 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003758 return MatchOperand_ParseFail;
3759 }
Tim Northover4d141442013-05-31 15:58:45 +00003760 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003761 .Case("be", 1)
3762 .Case("le", 0)
3763 .Default(-1);
3764 Parser.Lex(); // Eat the token.
3765
3766 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003767 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003768 return MatchOperand_ParseFail;
3769 }
3770 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3771 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003772 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003773 return MatchOperand_Success;
3774}
3775
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003776/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3777/// instructions. Legal values are:
3778/// lsl #n 'n' in [0,31]
3779/// asr #n 'n' in [1,32]
3780/// n == 32 encoded as n == 0.
3781ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3782parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3783 const AsmToken &Tok = Parser.getTok();
3784 SMLoc S = Tok.getLoc();
3785 if (Tok.isNot(AsmToken::Identifier)) {
3786 Error(S, "shift operator 'asr' or 'lsl' expected");
3787 return MatchOperand_ParseFail;
3788 }
3789 StringRef ShiftName = Tok.getString();
3790 bool isASR;
3791 if (ShiftName == "lsl" || ShiftName == "LSL")
3792 isASR = false;
3793 else if (ShiftName == "asr" || ShiftName == "ASR")
3794 isASR = true;
3795 else {
3796 Error(S, "shift operator 'asr' or 'lsl' expected");
3797 return MatchOperand_ParseFail;
3798 }
3799 Parser.Lex(); // Eat the operator.
3800
3801 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003802 if (Parser.getTok().isNot(AsmToken::Hash) &&
3803 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003804 Error(Parser.getTok().getLoc(), "'#' expected");
3805 return MatchOperand_ParseFail;
3806 }
3807 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003808 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003809
3810 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003811 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003812 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003813 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003814 return MatchOperand_ParseFail;
3815 }
3816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3817 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003818 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003819 return MatchOperand_ParseFail;
3820 }
3821
3822 int64_t Val = CE->getValue();
3823 if (isASR) {
3824 // Shift amount must be in [1,32]
3825 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003826 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003827 return MatchOperand_ParseFail;
3828 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003829 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3830 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003831 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003832 return MatchOperand_ParseFail;
3833 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003834 if (Val == 32) Val = 0;
3835 } else {
3836 // Shift amount must be in [1,32]
3837 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003838 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003839 return MatchOperand_ParseFail;
3840 }
3841 }
3842
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003843 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003844
3845 return MatchOperand_Success;
3846}
3847
Jim Grosbach833b9d32011-07-27 20:15:40 +00003848/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3849/// of instructions. Legal values are:
3850/// ror #n 'n' in {0, 8, 16, 24}
3851ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3852parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3853 const AsmToken &Tok = Parser.getTok();
3854 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003855 if (Tok.isNot(AsmToken::Identifier))
3856 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003857 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003858 if (ShiftName != "ror" && ShiftName != "ROR")
3859 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003860 Parser.Lex(); // Eat the operator.
3861
3862 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003863 if (Parser.getTok().isNot(AsmToken::Hash) &&
3864 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003865 Error(Parser.getTok().getLoc(), "'#' expected");
3866 return MatchOperand_ParseFail;
3867 }
3868 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003869 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003870
3871 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003872 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003873 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003874 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003875 return MatchOperand_ParseFail;
3876 }
3877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3878 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003879 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003880 return MatchOperand_ParseFail;
3881 }
3882
3883 int64_t Val = CE->getValue();
3884 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3885 // normally, zero is represented in asm by omitting the rotate operand
3886 // entirely.
3887 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003888 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003889 return MatchOperand_ParseFail;
3890 }
3891
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003892 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003893
3894 return MatchOperand_Success;
3895}
3896
Jim Grosbach864b6092011-07-28 21:34:26 +00003897ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3898parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3899 SMLoc S = Parser.getTok().getLoc();
3900 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003901 if (Parser.getTok().isNot(AsmToken::Hash) &&
3902 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003903 Error(Parser.getTok().getLoc(), "'#' expected");
3904 return MatchOperand_ParseFail;
3905 }
3906 Parser.Lex(); // Eat hash token.
3907
3908 const MCExpr *LSBExpr;
3909 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003910 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003911 Error(E, "malformed immediate expression");
3912 return MatchOperand_ParseFail;
3913 }
3914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3915 if (!CE) {
3916 Error(E, "'lsb' operand must be an immediate");
3917 return MatchOperand_ParseFail;
3918 }
3919
3920 int64_t LSB = CE->getValue();
3921 // The LSB must be in the range [0,31]
3922 if (LSB < 0 || LSB > 31) {
3923 Error(E, "'lsb' operand must be in the range [0,31]");
3924 return MatchOperand_ParseFail;
3925 }
3926 E = Parser.getTok().getLoc();
3927
3928 // Expect another immediate operand.
3929 if (Parser.getTok().isNot(AsmToken::Comma)) {
3930 Error(Parser.getTok().getLoc(), "too few operands");
3931 return MatchOperand_ParseFail;
3932 }
3933 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003934 if (Parser.getTok().isNot(AsmToken::Hash) &&
3935 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003936 Error(Parser.getTok().getLoc(), "'#' expected");
3937 return MatchOperand_ParseFail;
3938 }
3939 Parser.Lex(); // Eat hash token.
3940
3941 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003942 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003943 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003944 Error(E, "malformed immediate expression");
3945 return MatchOperand_ParseFail;
3946 }
3947 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3948 if (!CE) {
3949 Error(E, "'width' operand must be an immediate");
3950 return MatchOperand_ParseFail;
3951 }
3952
3953 int64_t Width = CE->getValue();
3954 // The LSB must be in the range [1,32-lsb]
3955 if (Width < 1 || Width > 32 - LSB) {
3956 Error(E, "'width' operand must be in the range [1,32-lsb]");
3957 return MatchOperand_ParseFail;
3958 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003959
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003960 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003961
3962 return MatchOperand_Success;
3963}
3964
Jim Grosbachd3595712011-08-03 23:50:40 +00003965ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3966parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3967 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003968 // postidx_reg := '+' register {, shift}
3969 // | '-' register {, shift}
3970 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003971
3972 // This method must return MatchOperand_NoMatch without consuming any tokens
3973 // in the case where there is no match, as other alternatives take other
3974 // parse methods.
3975 AsmToken Tok = Parser.getTok();
3976 SMLoc S = Tok.getLoc();
3977 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003978 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003979 if (Tok.is(AsmToken::Plus)) {
3980 Parser.Lex(); // Eat the '+' token.
3981 haveEaten = true;
3982 } else if (Tok.is(AsmToken::Minus)) {
3983 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003984 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003985 haveEaten = true;
3986 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003987
3988 SMLoc E = Parser.getTok().getEndLoc();
3989 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003990 if (Reg == -1) {
3991 if (!haveEaten)
3992 return MatchOperand_NoMatch;
3993 Error(Parser.getTok().getLoc(), "register expected");
3994 return MatchOperand_ParseFail;
3995 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003996
Jim Grosbachc320c852011-08-05 21:28:30 +00003997 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3998 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003999 if (Parser.getTok().is(AsmToken::Comma)) {
4000 Parser.Lex(); // Eat the ','.
4001 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4002 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004003
4004 // FIXME: Only approximates end...may include intervening whitespace.
4005 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004006 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004007
4008 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4009 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004010
4011 return MatchOperand_Success;
4012}
4013
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004014ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4015parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4016 // Check for a post-index addressing register operand. Specifically:
4017 // am3offset := '+' register
4018 // | '-' register
4019 // | register
4020 // | # imm
4021 // | # + imm
4022 // | # - imm
4023
4024 // This method must return MatchOperand_NoMatch without consuming any tokens
4025 // in the case where there is no match, as other alternatives take other
4026 // parse methods.
4027 AsmToken Tok = Parser.getTok();
4028 SMLoc S = Tok.getLoc();
4029
4030 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004031 if (Parser.getTok().is(AsmToken::Hash) ||
4032 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004033 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004034 // Explicitly look for a '-', as we need to encode negative zero
4035 // differently.
4036 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4037 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004038 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004039 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004040 return MatchOperand_ParseFail;
4041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4042 if (!CE) {
4043 Error(S, "constant expression expected");
4044 return MatchOperand_ParseFail;
4045 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004046 // Negative zero is encoded as the flag value INT32_MIN.
4047 int32_t Val = CE->getValue();
4048 if (isNegative && Val == 0)
4049 Val = INT32_MIN;
4050
4051 Operands.push_back(
4052 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4053
4054 return MatchOperand_Success;
4055 }
4056
4057
4058 bool haveEaten = false;
4059 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004060 if (Tok.is(AsmToken::Plus)) {
4061 Parser.Lex(); // Eat the '+' token.
4062 haveEaten = true;
4063 } else if (Tok.is(AsmToken::Minus)) {
4064 Parser.Lex(); // Eat the '-' token.
4065 isAdd = false;
4066 haveEaten = true;
4067 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004068
4069 Tok = Parser.getTok();
4070 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004071 if (Reg == -1) {
4072 if (!haveEaten)
4073 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004074 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004075 return MatchOperand_ParseFail;
4076 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004077
4078 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004079 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004080
4081 return MatchOperand_Success;
4082}
4083
Tim Northovereb5e4d52013-07-22 09:06:12 +00004084/// Convert parsed operands to MCInst. Needed here because this instruction
4085/// only has two register operands, but multiplication is commutative so
4086/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004087void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004088cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004089 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004090 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4091 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004092 // If we have a three-operand form, make sure to set Rn to be the operand
4093 // that isn't the same as Rd.
4094 unsigned RegOp = 4;
4095 if (Operands.size() == 6 &&
4096 ((ARMOperand*)Operands[4])->getReg() ==
4097 ((ARMOperand*)Operands[3])->getReg())
4098 RegOp = 5;
4099 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4100 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004101 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004102}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004103
Bill Wendlinge18980a2010-11-06 22:36:58 +00004104/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004105/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004106bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004107parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004108 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004109 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004110 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004111 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004112 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004113
Sean Callanan936b0d32010-01-19 21:44:56 +00004114 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004115 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004116 if (BaseRegNum == -1)
4117 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004118
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004119 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004120 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004121 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4122 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004123 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004124
Jim Grosbachd3595712011-08-03 23:50:40 +00004125 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004126 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004127 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004128
Jim Grosbachd3595712011-08-03 23:50:40 +00004129 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004130 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004131
Jim Grosbach40700e02011-09-19 18:42:21 +00004132 // If there's a pre-indexing writeback marker, '!', just add it as a token
4133 // operand. It's rather odd, but syntactically valid.
4134 if (Parser.getTok().is(AsmToken::Exclaim)) {
4135 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4136 Parser.Lex(); // Eat the '!'.
4137 }
4138
Jim Grosbachd3595712011-08-03 23:50:40 +00004139 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004140 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004141
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004142 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4143 "Lost colon or comma in memory operand?!");
4144 if (Tok.is(AsmToken::Comma)) {
4145 Parser.Lex(); // Eat the comma.
4146 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004147
Jim Grosbacha95ec992011-10-11 17:29:55 +00004148 // If we have a ':', it's an alignment specifier.
4149 if (Parser.getTok().is(AsmToken::Colon)) {
4150 Parser.Lex(); // Eat the ':'.
4151 E = Parser.getTok().getLoc();
4152
4153 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004154 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004155 return true;
4156
4157 // The expression has to be a constant. Memory references with relocations
4158 // don't come through here, as they use the <label> forms of the relevant
4159 // instructions.
4160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4161 if (!CE)
4162 return Error (E, "constant expression expected");
4163
4164 unsigned Align = 0;
4165 switch (CE->getValue()) {
4166 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004167 return Error(E,
4168 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4169 case 16: Align = 2; break;
4170 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004171 case 64: Align = 8; break;
4172 case 128: Align = 16; break;
4173 case 256: Align = 32; break;
4174 }
4175
4176 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004177 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004178 return Error(Parser.getTok().getLoc(), "']' expected");
4179 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004180 Parser.Lex(); // Eat right bracket token.
4181
4182 // Don't worry about range checking the value here. That's handled by
4183 // the is*() predicates.
4184 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4185 ARM_AM::no_shift, 0, Align,
4186 false, S, E));
4187
4188 // If there's a pre-indexing writeback marker, '!', just add it as a token
4189 // operand.
4190 if (Parser.getTok().is(AsmToken::Exclaim)) {
4191 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4192 Parser.Lex(); // Eat the '!'.
4193 }
4194
4195 return false;
4196 }
4197
4198 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004199 // offset. Be friendly and also accept a plain integer (without a leading
4200 // hash) for gas compatibility.
4201 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004202 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004203 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004204 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004205 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004206 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004207
Owen Anderson967674d2011-08-29 19:36:44 +00004208 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004209 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004210 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004211 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004212
4213 // The expression has to be a constant. Memory references with relocations
4214 // don't come through here, as they use the <label> forms of the relevant
4215 // instructions.
4216 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4217 if (!CE)
4218 return Error (E, "constant expression expected");
4219
Owen Anderson967674d2011-08-29 19:36:44 +00004220 // If the constant was #-0, represent it as INT32_MIN.
4221 int32_t Val = CE->getValue();
4222 if (isNegative && Val == 0)
4223 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4224
Jim Grosbachd3595712011-08-03 23:50:40 +00004225 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004226 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004227 return Error(Parser.getTok().getLoc(), "']' expected");
4228 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004229 Parser.Lex(); // Eat right bracket token.
4230
4231 // Don't worry about range checking the value here. That's handled by
4232 // the is*() predicates.
4233 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004234 ARM_AM::no_shift, 0, 0,
4235 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004236
4237 // If there's a pre-indexing writeback marker, '!', just add it as a token
4238 // operand.
4239 if (Parser.getTok().is(AsmToken::Exclaim)) {
4240 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4241 Parser.Lex(); // Eat the '!'.
4242 }
4243
4244 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004245 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004246
4247 // The register offset is optionally preceded by a '+' or '-'
4248 bool isNegative = false;
4249 if (Parser.getTok().is(AsmToken::Minus)) {
4250 isNegative = true;
4251 Parser.Lex(); // Eat the '-'.
4252 } else if (Parser.getTok().is(AsmToken::Plus)) {
4253 // Nothing to do.
4254 Parser.Lex(); // Eat the '+'.
4255 }
4256
4257 E = Parser.getTok().getLoc();
4258 int OffsetRegNum = tryParseRegister();
4259 if (OffsetRegNum == -1)
4260 return Error(E, "register expected");
4261
4262 // If there's a shift operator, handle it.
4263 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004264 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004265 if (Parser.getTok().is(AsmToken::Comma)) {
4266 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004267 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004268 return true;
4269 }
4270
4271 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004272 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004273 return Error(Parser.getTok().getLoc(), "']' expected");
4274 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004275 Parser.Lex(); // Eat right bracket token.
4276
4277 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004278 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004279 S, E));
4280
Jim Grosbachc320c852011-08-05 21:28:30 +00004281 // If there's a pre-indexing writeback marker, '!', just add it as a token
4282 // operand.
4283 if (Parser.getTok().is(AsmToken::Exclaim)) {
4284 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4285 Parser.Lex(); // Eat the '!'.
4286 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004287
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004288 return false;
4289}
4290
Jim Grosbachd3595712011-08-03 23:50:40 +00004291/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004292/// ( lsl | lsr | asr | ror ) , # shift_amount
4293/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004294/// return true if it parses a shift otherwise it returns false.
4295bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4296 unsigned &Amount) {
4297 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004298 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004299 if (Tok.isNot(AsmToken::Identifier))
4300 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004301 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004302 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4303 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004304 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004305 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004306 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004307 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004308 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004309 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004310 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004311 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004312 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004313 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004314 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004315 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004316
Jim Grosbachd3595712011-08-03 23:50:40 +00004317 // rrx stands alone.
4318 Amount = 0;
4319 if (St != ARM_AM::rrx) {
4320 Loc = Parser.getTok().getLoc();
4321 // A '#' and a shift amount.
4322 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004323 if (HashTok.isNot(AsmToken::Hash) &&
4324 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004325 return Error(HashTok.getLoc(), "'#' expected");
4326 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004327
Jim Grosbachd3595712011-08-03 23:50:40 +00004328 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004329 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004330 return true;
4331 // Range check the immediate.
4332 // lsl, ror: 0 <= imm <= 31
4333 // lsr, asr: 0 <= imm <= 32
4334 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4335 if (!CE)
4336 return Error(Loc, "shift amount must be an immediate");
4337 int64_t Imm = CE->getValue();
4338 if (Imm < 0 ||
4339 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4340 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4341 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004342 // If <ShiftTy> #0, turn it into a no_shift.
4343 if (Imm == 0)
4344 St = ARM_AM::lsl;
4345 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4346 if (Imm == 32)
4347 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004348 Amount = Imm;
4349 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004350
4351 return false;
4352}
4353
Jim Grosbache7fbce72011-10-03 23:38:36 +00004354/// parseFPImm - A floating point immediate expression operand.
4355ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4356parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004357 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004358 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004359 // integer only.
4360 //
4361 // This routine still creates a generic Immediate operand, containing
4362 // a bitcast of the 64-bit floating point value. The various operands
4363 // that accept floats can check whether the value is valid for them
4364 // via the standard is*() predicates.
4365
Jim Grosbache7fbce72011-10-03 23:38:36 +00004366 SMLoc S = Parser.getTok().getLoc();
4367
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004368 if (Parser.getTok().isNot(AsmToken::Hash) &&
4369 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004370 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004371
4372 // Disambiguate the VMOV forms that can accept an FP immediate.
4373 // vmov.f32 <sreg>, #imm
4374 // vmov.f64 <dreg>, #imm
4375 // vmov.f32 <dreg>, #imm @ vector f32x2
4376 // vmov.f32 <qreg>, #imm @ vector f32x4
4377 //
4378 // There are also the NEON VMOV instructions which expect an
4379 // integer constant. Make sure we don't try to parse an FPImm
4380 // for these:
4381 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4382 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4383 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4384 TyOp->getToken() != ".f64"))
4385 return MatchOperand_NoMatch;
4386
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004387 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004388
4389 // Handle negation, as that still comes through as a separate token.
4390 bool isNegative = false;
4391 if (Parser.getTok().is(AsmToken::Minus)) {
4392 isNegative = true;
4393 Parser.Lex();
4394 }
4395 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004396 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004397 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004398 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004399 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4400 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004401 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004402 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004403 Operands.push_back(ARMOperand::CreateImm(
4404 MCConstantExpr::Create(IntVal, getContext()),
4405 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004406 return MatchOperand_Success;
4407 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004408 // Also handle plain integers. Instructions which allow floating point
4409 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004410 if (Tok.is(AsmToken::Integer)) {
4411 int64_t Val = Tok.getIntVal();
4412 Parser.Lex(); // Eat the token.
4413 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004414 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004415 return MatchOperand_ParseFail;
4416 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004417 double RealVal = ARM_AM::getFPImmFloat(Val);
4418 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4419 Operands.push_back(ARMOperand::CreateImm(
4420 MCConstantExpr::Create(Val, getContext()), S,
4421 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004422 return MatchOperand_Success;
4423 }
4424
Jim Grosbach235c8d22012-01-19 02:47:30 +00004425 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004426 return MatchOperand_ParseFail;
4427}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004428
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004429/// Parse a arm instruction operand. For now this parses the operand regardless
4430/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004431bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004432 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004433 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004434
4435 // Check if the current operand has a custom associated parser, if so, try to
4436 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004437 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4438 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004439 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004440 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4441 // there was a match, but an error occurred, in which case, just return that
4442 // the operand parsing failed.
4443 if (ResTy == MatchOperand_ParseFail)
4444 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004445
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004446 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004447 default:
4448 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004449 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004450 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004451 // If we've seen a branch mnemonic, the next operand must be a label. This
4452 // is true even if the label is a register name. So "br r1" means branch to
4453 // label "r1".
4454 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4455 if (!ExpectLabel) {
4456 if (!tryParseRegisterWithWriteBack(Operands))
4457 return false;
4458 int Res = tryParseShiftRegister(Operands);
4459 if (Res == 0) // success
4460 return false;
4461 else if (Res == -1) // irrecoverable error
4462 return true;
4463 // If this is VMRS, check for the apsr_nzcv operand.
4464 if (Mnemonic == "vmrs" &&
4465 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4466 S = Parser.getTok().getLoc();
4467 Parser.Lex();
4468 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4469 return false;
4470 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004471 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004472
4473 // Fall though for the Identifier case that is not a register or a
4474 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004475 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004476 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004477 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004478 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004479 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004480 // This was not a register so parse other operands that start with an
4481 // identifier (like labels) as expressions and create them as immediates.
4482 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004483 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004484 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004485 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004486 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004487 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4488 return false;
4489 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004490 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004491 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004492 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004493 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004494 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004495 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004496 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004497 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004498 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004499
4500 if (Parser.getTok().isNot(AsmToken::Colon)) {
4501 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4502 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004503 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004504 return true;
4505 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4506 if (CE) {
4507 int32_t Val = CE->getValue();
4508 if (isNegative && Val == 0)
4509 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4510 }
4511 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4512 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004513
4514 // There can be a trailing '!' on operands that we want as a separate
4515 // '!' Token operand. Handle that here. For example, the compatibilty
4516 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4517 if (Parser.getTok().is(AsmToken::Exclaim)) {
4518 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4519 Parser.getTok().getLoc()));
4520 Parser.Lex(); // Eat exclaim token
4521 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004522 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004523 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004524 // w/ a ':' after the '#', it's just like a plain ':'.
4525 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004526 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004527 case AsmToken::Colon: {
4528 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004529 // FIXME: Check it's an expression prefix,
4530 // e.g. (FOO - :lower16:BAR) isn't legal.
4531 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004532 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004533 return true;
4534
Evan Cheng965b3c72011-01-13 07:58:56 +00004535 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004536 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004537 return true;
4538
Evan Cheng965b3c72011-01-13 07:58:56 +00004539 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004540 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004541 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004542 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004543 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004544 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004545 }
4546}
4547
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004548// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004549// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004550bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004551 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004552
4553 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004554 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004555 Parser.Lex(); // Eat ':'
4556
4557 if (getLexer().isNot(AsmToken::Identifier)) {
4558 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4559 return true;
4560 }
4561
4562 StringRef IDVal = Parser.getTok().getIdentifier();
4563 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004564 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004565 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004566 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004567 } else {
4568 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4569 return true;
4570 }
4571 Parser.Lex();
4572
4573 if (getLexer().isNot(AsmToken::Colon)) {
4574 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4575 return true;
4576 }
4577 Parser.Lex(); // Eat the last ':'
4578 return false;
4579}
4580
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004581/// \brief Given a mnemonic, split out possible predication code and carry
4582/// setting letters to form a canonical mnemonic and flags.
4583//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004584// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004585// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004586StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004587 unsigned &PredicationCode,
4588 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004589 unsigned &ProcessorIMod,
4590 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004591 PredicationCode = ARMCC::AL;
4592 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004593 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004594
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004595 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004596 //
4597 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004598 if ((Mnemonic == "movs" && isThumb()) ||
4599 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4600 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4601 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4602 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004603 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004604 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4605 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004606 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004607 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004608 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4609 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4610 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004611 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004612
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004613 // First, split out any predication code. Ignore mnemonics we know aren't
4614 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004615 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004616 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004617 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004618 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004619 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4620 .Case("eq", ARMCC::EQ)
4621 .Case("ne", ARMCC::NE)
4622 .Case("hs", ARMCC::HS)
4623 .Case("cs", ARMCC::HS)
4624 .Case("lo", ARMCC::LO)
4625 .Case("cc", ARMCC::LO)
4626 .Case("mi", ARMCC::MI)
4627 .Case("pl", ARMCC::PL)
4628 .Case("vs", ARMCC::VS)
4629 .Case("vc", ARMCC::VC)
4630 .Case("hi", ARMCC::HI)
4631 .Case("ls", ARMCC::LS)
4632 .Case("ge", ARMCC::GE)
4633 .Case("lt", ARMCC::LT)
4634 .Case("gt", ARMCC::GT)
4635 .Case("le", ARMCC::LE)
4636 .Case("al", ARMCC::AL)
4637 .Default(~0U);
4638 if (CC != ~0U) {
4639 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4640 PredicationCode = CC;
4641 }
Bill Wendling193961b2010-10-29 23:50:21 +00004642 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004643
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004644 // Next, determine if we have a carry setting bit. We explicitly ignore all
4645 // the instructions we know end in 's'.
4646 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004647 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004648 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4649 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4650 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004651 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004652 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004653 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004654 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004655 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004656 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004657 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4658 CarrySetting = true;
4659 }
4660
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004661 // The "cps" instruction can have a interrupt mode operand which is glued into
4662 // the mnemonic. Check if this is the case, split it and parse the imod op
4663 if (Mnemonic.startswith("cps")) {
4664 // Split out any imod code.
4665 unsigned IMod =
4666 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4667 .Case("ie", ARM_PROC::IE)
4668 .Case("id", ARM_PROC::ID)
4669 .Default(~0U);
4670 if (IMod != ~0U) {
4671 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4672 ProcessorIMod = IMod;
4673 }
4674 }
4675
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004676 // The "it" instruction has the condition mask on the end of the mnemonic.
4677 if (Mnemonic.startswith("it")) {
4678 ITMask = Mnemonic.slice(2, Mnemonic.size());
4679 Mnemonic = Mnemonic.slice(0, 2);
4680 }
4681
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004682 return Mnemonic;
4683}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004684
4685/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4686/// inclusion of carry set or predication code operands.
4687//
4688// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004689void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004690getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004691 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004692 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4693 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004694 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004695 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004696 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004697 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004698 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004699 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004700 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004701 Mnemonic == "mla" || Mnemonic == "smlal" ||
4702 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004703 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004704 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004705 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004706
Tim Northover2c45a382013-06-26 16:52:40 +00004707 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4708 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4709 Mnemonic == "trap" || Mnemonic == "setend" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004710 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4711 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004712 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4713 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4714 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004715 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004716 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004717 } else if (!isThumb()) {
4718 // Some instructions are only predicable in Thumb mode
4719 CanAcceptPredicationCode
4720 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4721 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4722 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4723 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4724 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4725 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4726 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4727 } else if (isThumbOne()) {
4728 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004729 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004730 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004731}
4732
Jim Grosbach7283da92011-08-16 21:12:37 +00004733bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4734 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004735 // FIXME: This is all horribly hacky. We really need a better way to deal
4736 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004737
4738 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4739 // another does not. Specifically, the MOVW instruction does not. So we
4740 // special case it here and remove the defaulted (non-setting) cc_out
4741 // operand if that's the instruction we're trying to match.
4742 //
4743 // We do this as post-processing of the explicit operands rather than just
4744 // conditionally adding the cc_out in the first place because we need
4745 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004746 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004747 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4748 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4749 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4750 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004751
4752 // Register-register 'add' for thumb does not have a cc_out operand
4753 // when there are only two register operands.
4754 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4755 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4756 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4757 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4758 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004759 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004760 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4761 // have to check the immediate range here since Thumb2 has a variant
4762 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004763 if (((isThumb() && Mnemonic == "add") ||
4764 (isThumbTwo() && Mnemonic == "sub")) &&
4765 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004766 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4767 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4768 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004769 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004770 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004771 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004772 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004773 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4774 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004775 // selecting via the generic "add" mnemonic, so to know that we
4776 // should remove the cc_out operand, we have to explicitly check that
4777 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004778 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4779 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004780 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4781 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4782 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4783 // Nest conditions rather than one big 'if' statement for readability.
4784 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004785 // If both registers are low, we're in an IT block, and the immediate is
4786 // in range, we should use encoding T1 instead, which has a cc_out.
4787 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004788 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004789 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4790 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4791 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004792 // Check against T3. If the second register is the PC, this is an
4793 // alternate form of ADR, which uses encoding T4, so check for that too.
4794 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4795 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4796 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004797
4798 // Otherwise, we use encoding T4, which does not have a cc_out
4799 // operand.
4800 return true;
4801 }
4802
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004803 // The thumb2 multiply instruction doesn't have a CCOut register, so
4804 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4805 // use the 16-bit encoding or not.
4806 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4807 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4808 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4809 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4810 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4811 // If the registers aren't low regs, the destination reg isn't the
4812 // same as one of the source regs, or the cc_out operand is zero
4813 // outside of an IT block, we have to use the 32-bit encoding, so
4814 // remove the cc_out operand.
4815 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4816 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004817 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004818 !inITBlock() ||
4819 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4820 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4821 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4822 static_cast<ARMOperand*>(Operands[4])->getReg())))
4823 return true;
4824
Jim Grosbachefa7e952011-11-15 19:55:16 +00004825 // Also check the 'mul' syntax variant that doesn't specify an explicit
4826 // destination register.
4827 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4828 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4829 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4830 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4831 // If the registers aren't low regs or the cc_out operand is zero
4832 // outside of an IT block, we have to use the 32-bit encoding, so
4833 // remove the cc_out operand.
4834 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4835 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4836 !inITBlock()))
4837 return true;
4838
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004839
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004840
Jim Grosbach4b701af2011-08-24 21:42:27 +00004841 // Register-register 'add/sub' for thumb does not have a cc_out operand
4842 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4843 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4844 // right, this will result in better diagnostics (which operand is off)
4845 // anyway.
4846 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4847 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004848 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4849 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004850 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4851 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4852 (Operands.size() == 6 &&
4853 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004854 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004855
Jim Grosbach7283da92011-08-16 21:12:37 +00004856 return false;
4857}
4858
Joey Goulye8602552013-07-19 16:34:16 +00004859bool ARMAsmParser::shouldOmitPredicateOperand(
4860 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4861 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4862 unsigned RegIdx = 3;
4863 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4864 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4865 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4866 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4867 RegIdx = 4;
4868
4869 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4870 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4871 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4872 ARMMCRegisterClasses[ARM::QPRRegClassID]
4873 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4874 return true;
4875 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004876 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004877}
4878
Jim Grosbach12952fe2011-11-11 23:08:10 +00004879static bool isDataTypeToken(StringRef Tok) {
4880 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4881 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4882 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4883 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4884 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4885 Tok == ".f" || Tok == ".d";
4886}
4887
4888// FIXME: This bit should probably be handled via an explicit match class
4889// in the .td files that matches the suffix instead of having it be
4890// a literal string token the way it is now.
4891static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4892 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4893}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004894static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4895 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004896/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004897bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4898 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004899 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004900 // Apply mnemonic aliases before doing anything else, as the destination
4901 // mnemnonic may include suffices and we want to handle them normally.
4902 // The generic tblgen'erated code does this later, at the start of
4903 // MatchInstructionImpl(), but that's too late for aliases that include
4904 // any sort of suffix.
4905 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00004906 unsigned AssemblerDialect = getParser().getAssemblerDialect();
4907 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00004908
Jim Grosbachab5830e2011-12-14 02:16:11 +00004909 // First check for the ARM-specific .req directive.
4910 if (Parser.getTok().is(AsmToken::Identifier) &&
4911 Parser.getTok().getIdentifier() == ".req") {
4912 parseDirectiveReq(Name, NameLoc);
4913 // We always return 'error' for this, as we're done with this
4914 // statement and don't need to match the 'instruction."
4915 return true;
4916 }
4917
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004918 // Create the leading tokens for the mnemonic, split by '.' characters.
4919 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004920 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004921
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004922 // Split out the predication code and carry setting flag from the mnemonic.
4923 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004924 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004925 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004926 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004927 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004928 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004929
Jim Grosbach1c171b12011-08-25 17:23:55 +00004930 // In Thumb1, only the branch (B) instruction can be predicated.
4931 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004932 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00004933 return Error(NameLoc, "conditional execution not supported in Thumb1");
4934 }
4935
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004936 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4937
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004938 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4939 // is the mask as it will be for the IT encoding if the conditional
4940 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4941 // where the conditional bit0 is zero, the instruction post-processing
4942 // will adjust the mask accordingly.
4943 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00004944 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4945 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004946 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004947 return Error(Loc, "too many conditions on IT instruction");
4948 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004949 unsigned Mask = 8;
4950 for (unsigned i = ITMask.size(); i != 0; --i) {
4951 char pos = ITMask[i - 1];
4952 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004953 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004954 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004955 }
4956 Mask >>= 1;
4957 if (ITMask[i - 1] == 't')
4958 Mask |= 8;
4959 }
Jim Grosbached16ec42011-08-29 22:24:09 +00004960 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004961 }
4962
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004963 // FIXME: This is all a pretty gross hack. We should automatically handle
4964 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00004965
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004966 // Next, add the CCOut and ConditionCode operands, if needed.
4967 //
4968 // For mnemonics which can ever incorporate a carry setting bit or predication
4969 // code, our matching model involves us always generating CCOut and
4970 // ConditionCode operands to match the mnemonic "as written" and then we let
4971 // the matcher deal with finding the right instruction or generating an
4972 // appropriate error.
4973 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004974 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004975
Jim Grosbach03a8a162011-07-14 22:04:21 +00004976 // If we had a carry-set on an instruction that can't do that, issue an
4977 // error.
4978 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004979 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004980 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00004981 "' can not set flags, but 's' suffix specified");
4982 }
Jim Grosbach0a547702011-07-22 17:44:50 +00004983 // If we had a predication code on an instruction that can't do that, issue an
4984 // error.
4985 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004986 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00004987 return Error(NameLoc, "instruction '" + Mnemonic +
4988 "' is not predicable, but condition code specified");
4989 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00004990
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004991 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00004992 if (CanAcceptCarrySet) {
4993 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004994 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00004995 Loc));
4996 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004997
4998 // Add the predication code operand, if necessary.
4999 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005000 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5001 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005002 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005003 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005004 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005005
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005006 // Add the processor imod operand, if necessary.
5007 if (ProcessorIMod) {
5008 Operands.push_back(ARMOperand::CreateImm(
5009 MCConstantExpr::Create(ProcessorIMod, getContext()),
5010 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005011 }
5012
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005013 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005014 while (Next != StringRef::npos) {
5015 Start = Next;
5016 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005017 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005018
Jim Grosbach12952fe2011-11-11 23:08:10 +00005019 // Some NEON instructions have an optional datatype suffix that is
5020 // completely ignored. Check for that.
5021 if (isDataTypeToken(ExtraToken) &&
5022 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5023 continue;
5024
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005025 // For for ARM mode generate an error if the .n qualifier is used.
5026 if (ExtraToken == ".n" && !isThumb()) {
5027 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5028 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5029 "arm mode");
5030 }
5031
5032 // The .n qualifier is always discarded as that is what the tables
5033 // and matcher expect. In ARM mode the .w qualifier has no effect,
5034 // so discard it to avoid errors that can be caused by the matcher.
5035 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005036 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5037 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5038 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005039 }
5040
5041 // Read the remaining operands.
5042 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005043 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005044 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005045 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005046 return true;
5047 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005048
5049 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005050 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005051
5052 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005053 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005054 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005055 return true;
5056 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005057 }
5058 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005059
Chris Lattnera2a9d162010-09-11 16:18:25 +00005060 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005061 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005062 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005063 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005064 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005065
Chris Lattner91689c12010-09-08 05:10:46 +00005066 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005067
Jim Grosbach7283da92011-08-16 21:12:37 +00005068 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5069 // do and don't have a cc_out optional-def operand. With some spot-checks
5070 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005071 // parse and adjust accordingly before actually matching. We shouldn't ever
5072 // try to remove a cc_out operand that was explicitly set on the the
5073 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5074 // table driven matcher doesn't fit well with the ARM instruction set.
5075 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005076 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5077 Operands.erase(Operands.begin() + 1);
5078 delete Op;
5079 }
5080
Joey Goulye8602552013-07-19 16:34:16 +00005081 // Some instructions have the same mnemonic, but don't always
5082 // have a predicate. Distinguish them here and delete the
5083 // predicate if needed.
5084 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5085 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5086 Operands.erase(Operands.begin() + 1);
5087 delete Op;
5088 }
5089
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005090 // ARM mode 'blx' need special handling, as the register operand version
5091 // is predicable, but the label operand version is not. So, we can't rely
5092 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005093 // a k_CondCode operand in the list. If we're trying to match the label
5094 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005095 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5096 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5097 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5098 Operands.erase(Operands.begin() + 1);
5099 delete Op;
5100 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005101
Weiming Zhao8f56f882012-11-16 21:55:34 +00005102 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5103 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5104 // a single GPRPair reg operand is used in the .td file to replace the two
5105 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5106 // expressed as a GPRPair, so we have to manually merge them.
5107 // FIXME: We would really like to be able to tablegen'erate this.
5108 if (!isThumb() && Operands.size() > 4 &&
5109 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5110 bool isLoad = (Mnemonic == "ldrexd");
5111 unsigned Idx = isLoad ? 2 : 3;
5112 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5113 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5114
5115 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5116 // Adjust only if Op1 and Op2 are GPRs.
5117 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5118 MRC.contains(Op2->getReg())) {
5119 unsigned Reg1 = Op1->getReg();
5120 unsigned Reg2 = Op2->getReg();
5121 unsigned Rt = MRI->getEncodingValue(Reg1);
5122 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5123
5124 // Rt2 must be Rt + 1 and Rt must be even.
5125 if (Rt + 1 != Rt2 || (Rt & 1)) {
5126 Error(Op2->getStartLoc(), isLoad ?
5127 "destination operands must be sequential" :
5128 "source operands must be sequential");
5129 return true;
5130 }
5131 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5132 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5133 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5134 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5135 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5136 delete Op1;
5137 delete Op2;
5138 }
5139 }
5140
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005141 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005142}
5143
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005144// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005145
5146// return 'true' if register list contains non-low GPR registers,
5147// 'false' otherwise. If Reg is in the register list or is HiReg, set
5148// 'containsReg' to true.
5149static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5150 unsigned HiReg, bool &containsReg) {
5151 containsReg = false;
5152 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5153 unsigned OpReg = Inst.getOperand(i).getReg();
5154 if (OpReg == Reg)
5155 containsReg = true;
5156 // Anything other than a low register isn't legal here.
5157 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5158 return true;
5159 }
5160 return false;
5161}
5162
Jim Grosbacha31f2232011-09-07 18:05:34 +00005163// Check if the specified regisgter is in the register list of the inst,
5164// starting at the indicated operand number.
5165static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5166 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5167 unsigned OpReg = Inst.getOperand(i).getReg();
5168 if (OpReg == Reg)
5169 return true;
5170 }
5171 return false;
5172}
5173
Jim Grosbached16ec42011-08-29 22:24:09 +00005174// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5175// the ARMInsts array) instead. Getting that here requires awkward
5176// API changes, though. Better way?
5177namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005178extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005179}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005180static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005181 return ARMInsts[Opcode];
5182}
5183
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005184// FIXME: We would really like to be able to tablegen'erate this.
5185bool ARMAsmParser::
5186validateInstruction(MCInst &Inst,
5187 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005188 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005189 SMLoc Loc = Operands[0]->getStartLoc();
5190 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005191 // NOTE: BKPT instruction has the interesting property of being
5192 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005193 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005194 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5195 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005196 unsigned bit = 1;
5197 if (ITState.FirstCond)
5198 ITState.FirstCond = false;
5199 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005200 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005201 // The instruction must be predicable.
5202 if (!MCID.isPredicable())
5203 return Error(Loc, "instructions in IT block must be predicable");
5204 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5205 unsigned ITCond = bit ? ITState.Cond :
5206 ARMCC::getOppositeCondition(ITState.Cond);
5207 if (Cond != ITCond) {
5208 // Find the condition code Operand to get its SMLoc information.
5209 SMLoc CondLoc;
5210 for (unsigned i = 1; i < Operands.size(); ++i)
5211 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5212 CondLoc = Operands[i]->getStartLoc();
5213 return Error(CondLoc, "incorrect condition in IT block; got '" +
5214 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5215 "', but expected '" +
5216 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5217 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005218 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005219 } else if (isThumbTwo() && MCID.isPredicable() &&
5220 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005221 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5222 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005223 return Error(Loc, "predicated instructions must be in IT block");
5224
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005225 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005226 case ARM::LDRD:
5227 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005228 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005229 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005230 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5231 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005232 if (Rt2 != Rt + 1)
5233 return Error(Operands[3]->getStartLoc(),
5234 "destination operands must be sequential");
5235 return false;
5236 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005237 case ARM::STRD: {
5238 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005239 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5240 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005241 if (Rt2 != Rt + 1)
5242 return Error(Operands[3]->getStartLoc(),
5243 "source operands must be sequential");
5244 return false;
5245 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005246 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005247 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005248 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005249 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5250 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005251 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005252 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005253 "source operands must be sequential");
5254 return false;
5255 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005256 case ARM::SBFX:
5257 case ARM::UBFX: {
5258 // width must be in range [1, 32-lsb]
5259 unsigned lsb = Inst.getOperand(2).getImm();
5260 unsigned widthm1 = Inst.getOperand(3).getImm();
5261 if (widthm1 >= 32 - lsb)
5262 return Error(Operands[5]->getStartLoc(),
5263 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005264 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005265 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005266 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005267 // If we're parsing Thumb2, the .w variant is available and handles
5268 // most cases that are normally illegal for a Thumb1 LDM
5269 // instruction. We'll make the transformation in processInstruction()
5270 // if necessary.
5271 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005272 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005273 // in the register list.
5274 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005275 bool hasWritebackToken =
5276 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5277 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005278 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005279 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005280 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5281 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005282 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005283 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005284 return Error(Operands[2]->getStartLoc(),
5285 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005286 // If we should not have writeback, there must not be a '!'. This is
5287 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005288 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005289 return Error(Operands[3]->getStartLoc(),
5290 "writeback operator '!' not allowed when base register "
5291 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005292
5293 break;
5294 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005295 case ARM::t2LDMIA_UPD: {
5296 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5297 return Error(Operands[4]->getStartLoc(),
5298 "writeback operator '!' not allowed when base register "
5299 "in register list");
5300 break;
5301 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005302 case ARM::tMUL: {
5303 // The second source operand must be the same register as the destination
5304 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005305 //
5306 // In this case, we must directly check the parsed operands because the
5307 // cvtThumbMultiply() function is written in such a way that it guarantees
5308 // this first statement is always true for the new Inst. Essentially, the
5309 // destination is unconditionally copied into the second source operand
5310 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005311 if (Operands.size() == 6 &&
5312 (((ARMOperand*)Operands[3])->getReg() !=
5313 ((ARMOperand*)Operands[5])->getReg()) &&
5314 (((ARMOperand*)Operands[3])->getReg() !=
5315 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005316 return Error(Operands[3]->getStartLoc(),
5317 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005318 }
5319 break;
5320 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005321 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5322 // so only issue a diagnostic for thumb1. The instructions will be
5323 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005324 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005325 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005326 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5327 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005328 return Error(Operands[2]->getStartLoc(),
5329 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005330 break;
5331 }
5332 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005333 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005334 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5335 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005336 return Error(Operands[2]->getStartLoc(),
5337 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005338 break;
5339 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005340 case ARM::tSTMIA_UPD: {
5341 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005342 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005343 return Error(Operands[4]->getStartLoc(),
5344 "registers must be in range r0-r7");
5345 break;
5346 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005347 case ARM::tADDrSP: {
5348 // If the non-SP source operand and the destination operand are not the
5349 // same, we need thumb2 (for the wide encoding), or we have an error.
5350 if (!isThumbTwo() &&
5351 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5352 return Error(Operands[4]->getStartLoc(),
5353 "source register must be the same as destination");
5354 }
5355 break;
5356 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005357 }
5358
5359 return false;
5360}
5361
Jim Grosbach1a747242012-01-23 23:45:44 +00005362static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005363 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005364 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005365 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005366 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5367 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5368 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5369 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5370 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5371 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5372 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5373 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5374 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005375
5376 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005377 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5378 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5379 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5380 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5381 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005382
Jim Grosbach1e946a42012-01-24 00:43:12 +00005383 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5384 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5385 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5386 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5387 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005388
Jim Grosbach1e946a42012-01-24 00:43:12 +00005389 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5390 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5391 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5392 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5393 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005394
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005395 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005396 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5397 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5398 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5399 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5400 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5401 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5402 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5403 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5404 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5405 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5406 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5407 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5408 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5409 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5410 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005411
Jim Grosbach1a747242012-01-23 23:45:44 +00005412 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005413 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5414 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5415 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5416 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5417 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5418 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5419 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5420 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5421 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5422 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5423 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5424 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5425 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5426 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5427 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5428 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5429 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5430 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005431
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005432 // VST4LN
5433 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5434 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5435 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5436 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5437 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5438 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5439 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5440 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5441 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5442 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5443 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5444 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5445 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5446 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5447 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5448
Jim Grosbachda70eac2012-01-24 00:58:13 +00005449 // VST4
5450 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5451 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5452 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5453 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5454 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5455 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5456 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5457 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5458 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5459 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5460 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5461 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5462 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5463 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5464 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5465 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5466 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5467 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005468 }
5469}
5470
Jim Grosbach1a747242012-01-23 23:45:44 +00005471static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005472 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005473 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005474 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005475 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5476 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5477 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5478 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5479 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5480 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5481 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5482 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5483 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005484
5485 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005486 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5487 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5488 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5489 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5490 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5491 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5492 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5493 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5494 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5495 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5496 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5497 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5498 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5499 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5500 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005501
Jim Grosbachb78403c2012-01-24 23:47:04 +00005502 // VLD3DUP
5503 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5504 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5505 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5506 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5507 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5508 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5509 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5510 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5511 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5512 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5513 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5514 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5515 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5516 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5517 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5518 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5519 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5520 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5521
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005522 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005523 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5524 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5525 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5526 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5527 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5528 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5529 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5530 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5531 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5532 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5533 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5534 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5535 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5536 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5537 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005538
5539 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005540 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5541 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5542 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5543 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5544 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5545 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5546 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5547 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5548 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5549 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5550 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5551 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5552 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5553 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5554 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5555 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5556 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5557 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005558
Jim Grosbach14952a02012-01-24 18:37:25 +00005559 // VLD4LN
5560 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5561 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5562 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5563 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5564 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5565 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5566 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5567 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5568 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5569 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5570 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5571 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5572 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5573 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5574 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5575
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005576 // VLD4DUP
5577 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5578 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5579 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5580 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5581 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5582 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5583 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5584 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5585 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5586 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5587 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5588 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5589 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5590 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5591 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5592 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5593 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5594 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5595
Jim Grosbached561fc2012-01-24 00:43:17 +00005596 // VLD4
5597 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5598 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5599 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5600 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5601 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5602 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5603 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5604 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5605 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5606 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5607 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5608 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5609 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5610 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5611 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5612 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5613 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5614 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005615 }
5616}
5617
Jim Grosbachafad0532011-11-10 23:42:14 +00005618bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005619processInstruction(MCInst &Inst,
5620 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5621 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005622 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5623 case ARM::ADDri: {
5624 if (Inst.getOperand(1).getReg() != ARM::PC ||
5625 Inst.getOperand(5).getReg() != 0)
5626 return false;
5627 MCInst TmpInst;
5628 TmpInst.setOpcode(ARM::ADR);
5629 TmpInst.addOperand(Inst.getOperand(0));
5630 TmpInst.addOperand(Inst.getOperand(2));
5631 TmpInst.addOperand(Inst.getOperand(3));
5632 TmpInst.addOperand(Inst.getOperand(4));
5633 Inst = TmpInst;
5634 return true;
5635 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005636 // Aliases for alternate PC+imm syntax of LDR instructions.
5637 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005638 // Select the narrow version if the immediate will fit.
5639 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005640 Inst.getOperand(1).getImm() <= 0xff &&
5641 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5642 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005643 Inst.setOpcode(ARM::tLDRpci);
5644 else
5645 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005646 return true;
5647 case ARM::t2LDRBpcrel:
5648 Inst.setOpcode(ARM::t2LDRBpci);
5649 return true;
5650 case ARM::t2LDRHpcrel:
5651 Inst.setOpcode(ARM::t2LDRHpci);
5652 return true;
5653 case ARM::t2LDRSBpcrel:
5654 Inst.setOpcode(ARM::t2LDRSBpci);
5655 return true;
5656 case ARM::t2LDRSHpcrel:
5657 Inst.setOpcode(ARM::t2LDRSHpci);
5658 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005659 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005660 case ARM::VST1LNdWB_register_Asm_8:
5661 case ARM::VST1LNdWB_register_Asm_16:
5662 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005663 MCInst TmpInst;
5664 // Shuffle the operands around so the lane index operand is in the
5665 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005666 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005667 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005668 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5669 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5670 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5671 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5672 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5673 TmpInst.addOperand(Inst.getOperand(1)); // lane
5674 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5675 TmpInst.addOperand(Inst.getOperand(6));
5676 Inst = TmpInst;
5677 return true;
5678 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005679
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005680 case ARM::VST2LNdWB_register_Asm_8:
5681 case ARM::VST2LNdWB_register_Asm_16:
5682 case ARM::VST2LNdWB_register_Asm_32:
5683 case ARM::VST2LNqWB_register_Asm_16:
5684 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005685 MCInst TmpInst;
5686 // Shuffle the operands around so the lane index operand is in the
5687 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005688 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005689 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005690 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5691 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5692 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5693 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5694 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5696 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005697 TmpInst.addOperand(Inst.getOperand(1)); // lane
5698 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5699 TmpInst.addOperand(Inst.getOperand(6));
5700 Inst = TmpInst;
5701 return true;
5702 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005703
5704 case ARM::VST3LNdWB_register_Asm_8:
5705 case ARM::VST3LNdWB_register_Asm_16:
5706 case ARM::VST3LNdWB_register_Asm_32:
5707 case ARM::VST3LNqWB_register_Asm_16:
5708 case ARM::VST3LNqWB_register_Asm_32: {
5709 MCInst TmpInst;
5710 // Shuffle the operands around so the lane index operand is in the
5711 // right place.
5712 unsigned Spacing;
5713 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5714 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5715 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5716 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5717 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5718 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5720 Spacing));
5721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5722 Spacing * 2));
5723 TmpInst.addOperand(Inst.getOperand(1)); // lane
5724 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5725 TmpInst.addOperand(Inst.getOperand(6));
5726 Inst = TmpInst;
5727 return true;
5728 }
5729
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005730 case ARM::VST4LNdWB_register_Asm_8:
5731 case ARM::VST4LNdWB_register_Asm_16:
5732 case ARM::VST4LNdWB_register_Asm_32:
5733 case ARM::VST4LNqWB_register_Asm_16:
5734 case ARM::VST4LNqWB_register_Asm_32: {
5735 MCInst TmpInst;
5736 // Shuffle the operands around so the lane index operand is in the
5737 // right place.
5738 unsigned Spacing;
5739 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5740 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5741 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5742 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5743 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5744 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5746 Spacing));
5747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5748 Spacing * 2));
5749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5750 Spacing * 3));
5751 TmpInst.addOperand(Inst.getOperand(1)); // lane
5752 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5753 TmpInst.addOperand(Inst.getOperand(6));
5754 Inst = TmpInst;
5755 return true;
5756 }
5757
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005758 case ARM::VST1LNdWB_fixed_Asm_8:
5759 case ARM::VST1LNdWB_fixed_Asm_16:
5760 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005761 MCInst TmpInst;
5762 // Shuffle the operands around so the lane index operand is in the
5763 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005764 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005765 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005766 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5767 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5768 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5769 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5770 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5771 TmpInst.addOperand(Inst.getOperand(1)); // lane
5772 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5773 TmpInst.addOperand(Inst.getOperand(5));
5774 Inst = TmpInst;
5775 return true;
5776 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005777
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005778 case ARM::VST2LNdWB_fixed_Asm_8:
5779 case ARM::VST2LNdWB_fixed_Asm_16:
5780 case ARM::VST2LNdWB_fixed_Asm_32:
5781 case ARM::VST2LNqWB_fixed_Asm_16:
5782 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005783 MCInst TmpInst;
5784 // Shuffle the operands around so the lane index operand is in the
5785 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005786 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005787 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005788 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5789 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5790 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5791 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5794 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005795 TmpInst.addOperand(Inst.getOperand(1)); // lane
5796 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5797 TmpInst.addOperand(Inst.getOperand(5));
5798 Inst = TmpInst;
5799 return true;
5800 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005801
5802 case ARM::VST3LNdWB_fixed_Asm_8:
5803 case ARM::VST3LNdWB_fixed_Asm_16:
5804 case ARM::VST3LNdWB_fixed_Asm_32:
5805 case ARM::VST3LNqWB_fixed_Asm_16:
5806 case ARM::VST3LNqWB_fixed_Asm_32: {
5807 MCInst TmpInst;
5808 // Shuffle the operands around so the lane index operand is in the
5809 // right place.
5810 unsigned Spacing;
5811 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5812 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5813 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5814 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5815 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5816 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5817 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5818 Spacing));
5819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5820 Spacing * 2));
5821 TmpInst.addOperand(Inst.getOperand(1)); // lane
5822 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5823 TmpInst.addOperand(Inst.getOperand(5));
5824 Inst = TmpInst;
5825 return true;
5826 }
5827
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005828 case ARM::VST4LNdWB_fixed_Asm_8:
5829 case ARM::VST4LNdWB_fixed_Asm_16:
5830 case ARM::VST4LNdWB_fixed_Asm_32:
5831 case ARM::VST4LNqWB_fixed_Asm_16:
5832 case ARM::VST4LNqWB_fixed_Asm_32: {
5833 MCInst TmpInst;
5834 // Shuffle the operands around so the lane index operand is in the
5835 // right place.
5836 unsigned Spacing;
5837 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5838 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5839 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5840 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5841 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5842 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5844 Spacing));
5845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5846 Spacing * 2));
5847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5848 Spacing * 3));
5849 TmpInst.addOperand(Inst.getOperand(1)); // lane
5850 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5851 TmpInst.addOperand(Inst.getOperand(5));
5852 Inst = TmpInst;
5853 return true;
5854 }
5855
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005856 case ARM::VST1LNdAsm_8:
5857 case ARM::VST1LNdAsm_16:
5858 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005859 MCInst TmpInst;
5860 // Shuffle the operands around so the lane index operand is in the
5861 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005862 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005863 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005864 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5865 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5866 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5867 TmpInst.addOperand(Inst.getOperand(1)); // lane
5868 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5869 TmpInst.addOperand(Inst.getOperand(5));
5870 Inst = TmpInst;
5871 return true;
5872 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005873
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005874 case ARM::VST2LNdAsm_8:
5875 case ARM::VST2LNdAsm_16:
5876 case ARM::VST2LNdAsm_32:
5877 case ARM::VST2LNqAsm_16:
5878 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005879 MCInst TmpInst;
5880 // Shuffle the operands around so the lane index operand is in the
5881 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005882 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005883 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005884 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5885 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5886 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5888 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005889 TmpInst.addOperand(Inst.getOperand(1)); // lane
5890 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5891 TmpInst.addOperand(Inst.getOperand(5));
5892 Inst = TmpInst;
5893 return true;
5894 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005895
5896 case ARM::VST3LNdAsm_8:
5897 case ARM::VST3LNdAsm_16:
5898 case ARM::VST3LNdAsm_32:
5899 case ARM::VST3LNqAsm_16:
5900 case ARM::VST3LNqAsm_32: {
5901 MCInst TmpInst;
5902 // Shuffle the operands around so the lane index operand is in the
5903 // right place.
5904 unsigned Spacing;
5905 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5906 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5907 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5908 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5910 Spacing));
5911 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5912 Spacing * 2));
5913 TmpInst.addOperand(Inst.getOperand(1)); // lane
5914 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5915 TmpInst.addOperand(Inst.getOperand(5));
5916 Inst = TmpInst;
5917 return true;
5918 }
5919
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005920 case ARM::VST4LNdAsm_8:
5921 case ARM::VST4LNdAsm_16:
5922 case ARM::VST4LNdAsm_32:
5923 case ARM::VST4LNqAsm_16:
5924 case ARM::VST4LNqAsm_32: {
5925 MCInst TmpInst;
5926 // Shuffle the operands around so the lane index operand is in the
5927 // right place.
5928 unsigned Spacing;
5929 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5930 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5931 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5932 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5934 Spacing));
5935 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5936 Spacing * 2));
5937 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5938 Spacing * 3));
5939 TmpInst.addOperand(Inst.getOperand(1)); // lane
5940 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5941 TmpInst.addOperand(Inst.getOperand(5));
5942 Inst = TmpInst;
5943 return true;
5944 }
5945
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005946 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005947 case ARM::VLD1LNdWB_register_Asm_8:
5948 case ARM::VLD1LNdWB_register_Asm_16:
5949 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00005950 MCInst TmpInst;
5951 // Shuffle the operands around so the lane index operand is in the
5952 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005953 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005954 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00005955 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5956 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5957 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5958 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5959 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5960 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5961 TmpInst.addOperand(Inst.getOperand(1)); // lane
5962 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5963 TmpInst.addOperand(Inst.getOperand(6));
5964 Inst = TmpInst;
5965 return true;
5966 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005967
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005968 case ARM::VLD2LNdWB_register_Asm_8:
5969 case ARM::VLD2LNdWB_register_Asm_16:
5970 case ARM::VLD2LNdWB_register_Asm_32:
5971 case ARM::VLD2LNqWB_register_Asm_16:
5972 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005973 MCInst TmpInst;
5974 // Shuffle the operands around so the lane index operand is in the
5975 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005976 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005977 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005978 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5980 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005981 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5982 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5983 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5984 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5985 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5987 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005988 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 Grosbacha8b444b2012-01-23 21:53:26 +00005995 case ARM::VLD3LNdWB_register_Asm_8:
5996 case ARM::VLD3LNdWB_register_Asm_16:
5997 case ARM::VLD3LNdWB_register_Asm_32:
5998 case ARM::VLD3LNqWB_register_Asm_16:
5999 case ARM::VLD3LNqWB_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;
Jim Grosbach1a747242012-01-23 23:45:44 +00006004 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006005 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6006 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6007 Spacing));
6008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006009 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006010 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6011 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6012 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6013 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6014 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6015 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6016 Spacing));
6017 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006018 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006019 TmpInst.addOperand(Inst.getOperand(1)); // lane
6020 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6021 TmpInst.addOperand(Inst.getOperand(6));
6022 Inst = TmpInst;
6023 return true;
6024 }
6025
Jim Grosbach14952a02012-01-24 18:37:25 +00006026 case ARM::VLD4LNdWB_register_Asm_8:
6027 case ARM::VLD4LNdWB_register_Asm_16:
6028 case ARM::VLD4LNdWB_register_Asm_32:
6029 case ARM::VLD4LNqWB_register_Asm_16:
6030 case ARM::VLD4LNqWB_register_Asm_32: {
6031 MCInst TmpInst;
6032 // Shuffle the operands around so the lane index operand is in the
6033 // right place.
6034 unsigned Spacing;
6035 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6036 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6038 Spacing));
6039 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6040 Spacing * 2));
6041 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6042 Spacing * 3));
6043 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6044 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6045 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6046 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6047 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing));
6050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6051 Spacing * 2));
6052 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6053 Spacing * 3));
6054 TmpInst.addOperand(Inst.getOperand(1)); // lane
6055 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6056 TmpInst.addOperand(Inst.getOperand(6));
6057 Inst = TmpInst;
6058 return true;
6059 }
6060
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006061 case ARM::VLD1LNdWB_fixed_Asm_8:
6062 case ARM::VLD1LNdWB_fixed_Asm_16:
6063 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006064 MCInst TmpInst;
6065 // Shuffle the operands around so the lane index operand is in the
6066 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006067 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006068 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6071 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6072 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6073 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6074 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6075 TmpInst.addOperand(Inst.getOperand(1)); // lane
6076 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6077 TmpInst.addOperand(Inst.getOperand(5));
6078 Inst = TmpInst;
6079 return true;
6080 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006081
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006082 case ARM::VLD2LNdWB_fixed_Asm_8:
6083 case ARM::VLD2LNdWB_fixed_Asm_16:
6084 case ARM::VLD2LNdWB_fixed_Asm_32:
6085 case ARM::VLD2LNqWB_fixed_Asm_16:
6086 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006087 MCInst TmpInst;
6088 // Shuffle the operands around so the lane index operand is in the
6089 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006090 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006091 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006092 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6094 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006095 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6096 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6097 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6098 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6099 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006102 TmpInst.addOperand(Inst.getOperand(1)); // lane
6103 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6104 TmpInst.addOperand(Inst.getOperand(5));
6105 Inst = TmpInst;
6106 return true;
6107 }
6108
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006109 case ARM::VLD3LNdWB_fixed_Asm_8:
6110 case ARM::VLD3LNdWB_fixed_Asm_16:
6111 case ARM::VLD3LNdWB_fixed_Asm_32:
6112 case ARM::VLD3LNqWB_fixed_Asm_16:
6113 case ARM::VLD3LNqWB_fixed_Asm_32: {
6114 MCInst TmpInst;
6115 // Shuffle the operands around so the lane index operand is in the
6116 // right place.
6117 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006118 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006119 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 Spacing));
6122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006123 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006124 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6125 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6126 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6127 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6128 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6129 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6130 Spacing));
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006132 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006133 TmpInst.addOperand(Inst.getOperand(1)); // lane
6134 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6135 TmpInst.addOperand(Inst.getOperand(5));
6136 Inst = TmpInst;
6137 return true;
6138 }
6139
Jim Grosbach14952a02012-01-24 18:37:25 +00006140 case ARM::VLD4LNdWB_fixed_Asm_8:
6141 case ARM::VLD4LNdWB_fixed_Asm_16:
6142 case ARM::VLD4LNdWB_fixed_Asm_32:
6143 case ARM::VLD4LNqWB_fixed_Asm_16:
6144 case ARM::VLD4LNqWB_fixed_Asm_32: {
6145 MCInst TmpInst;
6146 // Shuffle the operands around so the lane index operand is in the
6147 // right place.
6148 unsigned Spacing;
6149 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6150 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6152 Spacing));
6153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6154 Spacing * 2));
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6156 Spacing * 3));
6157 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6158 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6159 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6160 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6161 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6162 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6163 Spacing));
6164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6165 Spacing * 2));
6166 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6167 Spacing * 3));
6168 TmpInst.addOperand(Inst.getOperand(1)); // lane
6169 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6170 TmpInst.addOperand(Inst.getOperand(5));
6171 Inst = TmpInst;
6172 return true;
6173 }
6174
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006175 case ARM::VLD1LNdAsm_8:
6176 case ARM::VLD1LNdAsm_16:
6177 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006178 MCInst TmpInst;
6179 // Shuffle the operands around so the lane index operand is in the
6180 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006181 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006182 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006183 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6184 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6185 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6186 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6187 TmpInst.addOperand(Inst.getOperand(1)); // lane
6188 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6189 TmpInst.addOperand(Inst.getOperand(5));
6190 Inst = TmpInst;
6191 return true;
6192 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006193
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006194 case ARM::VLD2LNdAsm_8:
6195 case ARM::VLD2LNdAsm_16:
6196 case ARM::VLD2LNdAsm_32:
6197 case ARM::VLD2LNqAsm_16:
6198 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006199 MCInst TmpInst;
6200 // Shuffle the operands around so the lane index operand is in the
6201 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006202 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006203 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006204 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006205 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6206 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006207 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6208 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6209 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6211 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006212 TmpInst.addOperand(Inst.getOperand(1)); // lane
6213 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6214 TmpInst.addOperand(Inst.getOperand(5));
6215 Inst = TmpInst;
6216 return true;
6217 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006218
6219 case ARM::VLD3LNdAsm_8:
6220 case ARM::VLD3LNdAsm_16:
6221 case ARM::VLD3LNdAsm_32:
6222 case ARM::VLD3LNqAsm_16:
6223 case ARM::VLD3LNqAsm_32: {
6224 MCInst TmpInst;
6225 // Shuffle the operands around so the lane index operand is in the
6226 // right place.
6227 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006228 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006229 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6231 Spacing));
6232 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006233 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006234 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6235 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6236 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6237 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 Spacing));
6239 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006240 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006241 TmpInst.addOperand(Inst.getOperand(1)); // lane
6242 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6243 TmpInst.addOperand(Inst.getOperand(5));
6244 Inst = TmpInst;
6245 return true;
6246 }
6247
Jim Grosbach14952a02012-01-24 18:37:25 +00006248 case ARM::VLD4LNdAsm_8:
6249 case ARM::VLD4LNdAsm_16:
6250 case ARM::VLD4LNdAsm_32:
6251 case ARM::VLD4LNqAsm_16:
6252 case ARM::VLD4LNqAsm_32: {
6253 MCInst TmpInst;
6254 // Shuffle the operands around so the lane index operand is in the
6255 // right place.
6256 unsigned Spacing;
6257 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6258 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6259 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6260 Spacing));
6261 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6262 Spacing * 2));
6263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 Spacing * 3));
6265 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6266 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6267 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6269 Spacing));
6270 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6271 Spacing * 2));
6272 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 Spacing * 3));
6274 TmpInst.addOperand(Inst.getOperand(1)); // lane
6275 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6276 TmpInst.addOperand(Inst.getOperand(5));
6277 Inst = TmpInst;
6278 return true;
6279 }
6280
Jim Grosbachb78403c2012-01-24 23:47:04 +00006281 // VLD3DUP single 3-element structure to all lanes instructions.
6282 case ARM::VLD3DUPdAsm_8:
6283 case ARM::VLD3DUPdAsm_16:
6284 case ARM::VLD3DUPdAsm_32:
6285 case ARM::VLD3DUPqAsm_8:
6286 case ARM::VLD3DUPqAsm_16:
6287 case ARM::VLD3DUPqAsm_32: {
6288 MCInst TmpInst;
6289 unsigned Spacing;
6290 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6291 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6293 Spacing));
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 Spacing * 2));
6296 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6297 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6298 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6299 TmpInst.addOperand(Inst.getOperand(4));
6300 Inst = TmpInst;
6301 return true;
6302 }
6303
6304 case ARM::VLD3DUPdWB_fixed_Asm_8:
6305 case ARM::VLD3DUPdWB_fixed_Asm_16:
6306 case ARM::VLD3DUPdWB_fixed_Asm_32:
6307 case ARM::VLD3DUPqWB_fixed_Asm_8:
6308 case ARM::VLD3DUPqWB_fixed_Asm_16:
6309 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6310 MCInst TmpInst;
6311 unsigned Spacing;
6312 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6313 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 Spacing));
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 Spacing * 2));
6318 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6319 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6320 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6321 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6322 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6323 TmpInst.addOperand(Inst.getOperand(4));
6324 Inst = TmpInst;
6325 return true;
6326 }
6327
6328 case ARM::VLD3DUPdWB_register_Asm_8:
6329 case ARM::VLD3DUPdWB_register_Asm_16:
6330 case ARM::VLD3DUPdWB_register_Asm_32:
6331 case ARM::VLD3DUPqWB_register_Asm_8:
6332 case ARM::VLD3DUPqWB_register_Asm_16:
6333 case ARM::VLD3DUPqWB_register_Asm_32: {
6334 MCInst TmpInst;
6335 unsigned Spacing;
6336 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6337 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6338 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6339 Spacing));
6340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6341 Spacing * 2));
6342 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6343 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6344 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6345 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6346 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6347 TmpInst.addOperand(Inst.getOperand(5));
6348 Inst = TmpInst;
6349 return true;
6350 }
6351
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006352 // VLD3 multiple 3-element structure instructions.
6353 case ARM::VLD3dAsm_8:
6354 case ARM::VLD3dAsm_16:
6355 case ARM::VLD3dAsm_32:
6356 case ARM::VLD3qAsm_8:
6357 case ARM::VLD3qAsm_16:
6358 case ARM::VLD3qAsm_32: {
6359 MCInst TmpInst;
6360 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006361 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006362 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6363 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6364 Spacing));
6365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6366 Spacing * 2));
6367 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6368 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6369 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6370 TmpInst.addOperand(Inst.getOperand(4));
6371 Inst = TmpInst;
6372 return true;
6373 }
6374
6375 case ARM::VLD3dWB_fixed_Asm_8:
6376 case ARM::VLD3dWB_fixed_Asm_16:
6377 case ARM::VLD3dWB_fixed_Asm_32:
6378 case ARM::VLD3qWB_fixed_Asm_8:
6379 case ARM::VLD3qWB_fixed_Asm_16:
6380 case ARM::VLD3qWB_fixed_Asm_32: {
6381 MCInst TmpInst;
6382 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006383 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +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() +
6388 Spacing * 2));
6389 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6390 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6391 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6392 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6393 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6394 TmpInst.addOperand(Inst.getOperand(4));
6395 Inst = TmpInst;
6396 return true;
6397 }
6398
6399 case ARM::VLD3dWB_register_Asm_8:
6400 case ARM::VLD3dWB_register_Asm_16:
6401 case ARM::VLD3dWB_register_Asm_32:
6402 case ARM::VLD3qWB_register_Asm_8:
6403 case ARM::VLD3qWB_register_Asm_16:
6404 case ARM::VLD3qWB_register_Asm_32: {
6405 MCInst TmpInst;
6406 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006407 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006408 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6409 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 Spacing));
6411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 Spacing * 2));
6413 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6414 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6415 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6416 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6417 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6418 TmpInst.addOperand(Inst.getOperand(5));
6419 Inst = TmpInst;
6420 return true;
6421 }
6422
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006423 // VLD4DUP single 3-element structure to all lanes instructions.
6424 case ARM::VLD4DUPdAsm_8:
6425 case ARM::VLD4DUPdAsm_16:
6426 case ARM::VLD4DUPdAsm_32:
6427 case ARM::VLD4DUPqAsm_8:
6428 case ARM::VLD4DUPqAsm_16:
6429 case ARM::VLD4DUPqAsm_32: {
6430 MCInst TmpInst;
6431 unsigned Spacing;
6432 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6433 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6434 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6435 Spacing));
6436 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6437 Spacing * 2));
6438 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6439 Spacing * 3));
6440 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6441 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6442 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6443 TmpInst.addOperand(Inst.getOperand(4));
6444 Inst = TmpInst;
6445 return true;
6446 }
6447
6448 case ARM::VLD4DUPdWB_fixed_Asm_8:
6449 case ARM::VLD4DUPdWB_fixed_Asm_16:
6450 case ARM::VLD4DUPdWB_fixed_Asm_32:
6451 case ARM::VLD4DUPqWB_fixed_Asm_8:
6452 case ARM::VLD4DUPqWB_fixed_Asm_16:
6453 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6454 MCInst TmpInst;
6455 unsigned Spacing;
6456 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6457 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6458 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6459 Spacing));
6460 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6461 Spacing * 2));
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 Spacing * 3));
6464 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6465 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6466 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6467 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6468 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6469 TmpInst.addOperand(Inst.getOperand(4));
6470 Inst = TmpInst;
6471 return true;
6472 }
6473
6474 case ARM::VLD4DUPdWB_register_Asm_8:
6475 case ARM::VLD4DUPdWB_register_Asm_16:
6476 case ARM::VLD4DUPdWB_register_Asm_32:
6477 case ARM::VLD4DUPqWB_register_Asm_8:
6478 case ARM::VLD4DUPqWB_register_Asm_16:
6479 case ARM::VLD4DUPqWB_register_Asm_32: {
6480 MCInst TmpInst;
6481 unsigned Spacing;
6482 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6483 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6484 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6485 Spacing));
6486 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6487 Spacing * 2));
6488 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 Spacing * 3));
6490 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6491 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6492 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6493 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6494 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6495 TmpInst.addOperand(Inst.getOperand(5));
6496 Inst = TmpInst;
6497 return true;
6498 }
6499
6500 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006501 case ARM::VLD4dAsm_8:
6502 case ARM::VLD4dAsm_16:
6503 case ARM::VLD4dAsm_32:
6504 case ARM::VLD4qAsm_8:
6505 case ARM::VLD4qAsm_16:
6506 case ARM::VLD4qAsm_32: {
6507 MCInst TmpInst;
6508 unsigned Spacing;
6509 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6510 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6511 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6512 Spacing));
6513 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6514 Spacing * 2));
6515 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6516 Spacing * 3));
6517 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6518 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6519 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6520 TmpInst.addOperand(Inst.getOperand(4));
6521 Inst = TmpInst;
6522 return true;
6523 }
6524
6525 case ARM::VLD4dWB_fixed_Asm_8:
6526 case ARM::VLD4dWB_fixed_Asm_16:
6527 case ARM::VLD4dWB_fixed_Asm_32:
6528 case ARM::VLD4qWB_fixed_Asm_8:
6529 case ARM::VLD4qWB_fixed_Asm_16:
6530 case ARM::VLD4qWB_fixed_Asm_32: {
6531 MCInst TmpInst;
6532 unsigned Spacing;
6533 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6534 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 Spacing));
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing * 2));
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing * 3));
6541 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6542 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6543 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6544 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6545 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6546 TmpInst.addOperand(Inst.getOperand(4));
6547 Inst = TmpInst;
6548 return true;
6549 }
6550
6551 case ARM::VLD4dWB_register_Asm_8:
6552 case ARM::VLD4dWB_register_Asm_16:
6553 case ARM::VLD4dWB_register_Asm_32:
6554 case ARM::VLD4qWB_register_Asm_8:
6555 case ARM::VLD4qWB_register_Asm_16:
6556 case ARM::VLD4qWB_register_Asm_32: {
6557 MCInst TmpInst;
6558 unsigned Spacing;
6559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 2));
6565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6566 Spacing * 3));
6567 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6568 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6569 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6570 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6571 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6572 TmpInst.addOperand(Inst.getOperand(5));
6573 Inst = TmpInst;
6574 return true;
6575 }
6576
Jim Grosbach1a747242012-01-23 23:45:44 +00006577 // VST3 multiple 3-element structure instructions.
6578 case ARM::VST3dAsm_8:
6579 case ARM::VST3dAsm_16:
6580 case ARM::VST3dAsm_32:
6581 case ARM::VST3qAsm_8:
6582 case ARM::VST3qAsm_16:
6583 case ARM::VST3qAsm_32: {
6584 MCInst TmpInst;
6585 unsigned Spacing;
6586 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6587 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6588 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6589 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6591 Spacing));
6592 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6593 Spacing * 2));
6594 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6595 TmpInst.addOperand(Inst.getOperand(4));
6596 Inst = TmpInst;
6597 return true;
6598 }
6599
6600 case ARM::VST3dWB_fixed_Asm_8:
6601 case ARM::VST3dWB_fixed_Asm_16:
6602 case ARM::VST3dWB_fixed_Asm_32:
6603 case ARM::VST3qWB_fixed_Asm_8:
6604 case ARM::VST3qWB_fixed_Asm_16:
6605 case ARM::VST3qWB_fixed_Asm_32: {
6606 MCInst TmpInst;
6607 unsigned Spacing;
6608 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6609 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6610 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6611 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6612 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6613 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6614 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6615 Spacing));
6616 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6617 Spacing * 2));
6618 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6619 TmpInst.addOperand(Inst.getOperand(4));
6620 Inst = TmpInst;
6621 return true;
6622 }
6623
6624 case ARM::VST3dWB_register_Asm_8:
6625 case ARM::VST3dWB_register_Asm_16:
6626 case ARM::VST3dWB_register_Asm_32:
6627 case ARM::VST3qWB_register_Asm_8:
6628 case ARM::VST3qWB_register_Asm_16:
6629 case ARM::VST3qWB_register_Asm_32: {
6630 MCInst TmpInst;
6631 unsigned Spacing;
6632 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6633 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6634 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6635 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6636 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6637 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6638 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6639 Spacing));
6640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 Spacing * 2));
6642 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6643 TmpInst.addOperand(Inst.getOperand(5));
6644 Inst = TmpInst;
6645 return true;
6646 }
6647
Jim Grosbachda70eac2012-01-24 00:58:13 +00006648 // VST4 multiple 3-element structure instructions.
6649 case ARM::VST4dAsm_8:
6650 case ARM::VST4dAsm_16:
6651 case ARM::VST4dAsm_32:
6652 case ARM::VST4qAsm_8:
6653 case ARM::VST4qAsm_16:
6654 case ARM::VST4qAsm_32: {
6655 MCInst TmpInst;
6656 unsigned Spacing;
6657 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6658 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6659 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6660 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6662 Spacing));
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6664 Spacing * 2));
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 Spacing * 3));
6667 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6668 TmpInst.addOperand(Inst.getOperand(4));
6669 Inst = TmpInst;
6670 return true;
6671 }
6672
6673 case ARM::VST4dWB_fixed_Asm_8:
6674 case ARM::VST4dWB_fixed_Asm_16:
6675 case ARM::VST4dWB_fixed_Asm_32:
6676 case ARM::VST4qWB_fixed_Asm_8:
6677 case ARM::VST4qWB_fixed_Asm_16:
6678 case ARM::VST4qWB_fixed_Asm_32: {
6679 MCInst TmpInst;
6680 unsigned Spacing;
6681 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6682 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6683 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6684 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6685 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6688 Spacing));
6689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6690 Spacing * 2));
6691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6692 Spacing * 3));
6693 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6694 TmpInst.addOperand(Inst.getOperand(4));
6695 Inst = TmpInst;
6696 return true;
6697 }
6698
6699 case ARM::VST4dWB_register_Asm_8:
6700 case ARM::VST4dWB_register_Asm_16:
6701 case ARM::VST4dWB_register_Asm_32:
6702 case ARM::VST4qWB_register_Asm_8:
6703 case ARM::VST4qWB_register_Asm_16:
6704 case ARM::VST4qWB_register_Asm_32: {
6705 MCInst TmpInst;
6706 unsigned Spacing;
6707 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6708 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6709 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6710 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6711 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6712 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6713 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6714 Spacing));
6715 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6716 Spacing * 2));
6717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6718 Spacing * 3));
6719 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6720 TmpInst.addOperand(Inst.getOperand(5));
6721 Inst = TmpInst;
6722 return true;
6723 }
6724
Jim Grosbachad66de12012-04-11 00:15:16 +00006725 // Handle encoding choice for the shift-immediate instructions.
6726 case ARM::t2LSLri:
6727 case ARM::t2LSRri:
6728 case ARM::t2ASRri: {
6729 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6730 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6731 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6732 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6733 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6734 unsigned NewOpc;
6735 switch (Inst.getOpcode()) {
6736 default: llvm_unreachable("unexpected opcode");
6737 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6738 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6739 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6740 }
6741 // The Thumb1 operands aren't in the same order. Awesome, eh?
6742 MCInst TmpInst;
6743 TmpInst.setOpcode(NewOpc);
6744 TmpInst.addOperand(Inst.getOperand(0));
6745 TmpInst.addOperand(Inst.getOperand(5));
6746 TmpInst.addOperand(Inst.getOperand(1));
6747 TmpInst.addOperand(Inst.getOperand(2));
6748 TmpInst.addOperand(Inst.getOperand(3));
6749 TmpInst.addOperand(Inst.getOperand(4));
6750 Inst = TmpInst;
6751 return true;
6752 }
6753 return false;
6754 }
6755
Jim Grosbach485e5622011-12-13 22:45:11 +00006756 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006757 case ARM::t2MOVsr:
6758 case ARM::t2MOVSsr: {
6759 // Which instruction to expand to depends on the CCOut operand and
6760 // whether we're in an IT block if the register operands are low
6761 // registers.
6762 bool isNarrow = false;
6763 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6764 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6765 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6766 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6767 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6768 isNarrow = true;
6769 MCInst TmpInst;
6770 unsigned newOpc;
6771 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6772 default: llvm_unreachable("unexpected opcode!");
6773 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6774 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6775 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6776 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6777 }
6778 TmpInst.setOpcode(newOpc);
6779 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6780 if (isNarrow)
6781 TmpInst.addOperand(MCOperand::CreateReg(
6782 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6783 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6784 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6785 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6786 TmpInst.addOperand(Inst.getOperand(5));
6787 if (!isNarrow)
6788 TmpInst.addOperand(MCOperand::CreateReg(
6789 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6790 Inst = TmpInst;
6791 return true;
6792 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006793 case ARM::t2MOVsi:
6794 case ARM::t2MOVSsi: {
6795 // Which instruction to expand to depends on the CCOut operand and
6796 // whether we're in an IT block if the register operands are low
6797 // registers.
6798 bool isNarrow = false;
6799 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6800 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6801 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6802 isNarrow = true;
6803 MCInst TmpInst;
6804 unsigned newOpc;
6805 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6806 default: llvm_unreachable("unexpected opcode!");
6807 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6808 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6809 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6810 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006811 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006812 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006813 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6814 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006815 TmpInst.setOpcode(newOpc);
6816 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6817 if (isNarrow)
6818 TmpInst.addOperand(MCOperand::CreateReg(
6819 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6820 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006821 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006822 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006823 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6824 TmpInst.addOperand(Inst.getOperand(4));
6825 if (!isNarrow)
6826 TmpInst.addOperand(MCOperand::CreateReg(
6827 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6828 Inst = TmpInst;
6829 return true;
6830 }
6831 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006832 case ARM::ASRr:
6833 case ARM::LSRr:
6834 case ARM::LSLr:
6835 case ARM::RORr: {
6836 ARM_AM::ShiftOpc ShiftTy;
6837 switch(Inst.getOpcode()) {
6838 default: llvm_unreachable("unexpected opcode!");
6839 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6840 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6841 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6842 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6843 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006844 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6845 MCInst TmpInst;
6846 TmpInst.setOpcode(ARM::MOVsr);
6847 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6848 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6849 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6850 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6851 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6852 TmpInst.addOperand(Inst.getOperand(4));
6853 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6854 Inst = TmpInst;
6855 return true;
6856 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006857 case ARM::ASRi:
6858 case ARM::LSRi:
6859 case ARM::LSLi:
6860 case ARM::RORi: {
6861 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006862 switch(Inst.getOpcode()) {
6863 default: llvm_unreachable("unexpected opcode!");
6864 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6865 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6866 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6867 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6868 }
6869 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006870 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006871 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006872 // A shift by 32 should be encoded as 0 when permitted
6873 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6874 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006875 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006876 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006877 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006878 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6879 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006880 if (Opc == ARM::MOVsi)
6881 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006882 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6883 TmpInst.addOperand(Inst.getOperand(4));
6884 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6885 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006886 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006887 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006888 case ARM::RRXi: {
6889 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6890 MCInst TmpInst;
6891 TmpInst.setOpcode(ARM::MOVsi);
6892 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6893 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6894 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6895 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6896 TmpInst.addOperand(Inst.getOperand(3));
6897 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6898 Inst = TmpInst;
6899 return true;
6900 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006901 case ARM::t2LDMIA_UPD: {
6902 // If this is a load of a single register, then we should use
6903 // a post-indexed LDR instruction instead, per the ARM ARM.
6904 if (Inst.getNumOperands() != 5)
6905 return false;
6906 MCInst TmpInst;
6907 TmpInst.setOpcode(ARM::t2LDR_POST);
6908 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6909 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6910 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6911 TmpInst.addOperand(MCOperand::CreateImm(4));
6912 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6913 TmpInst.addOperand(Inst.getOperand(3));
6914 Inst = TmpInst;
6915 return true;
6916 }
6917 case ARM::t2STMDB_UPD: {
6918 // If this is a store of a single register, then we should use
6919 // a pre-indexed STR instruction instead, per the ARM ARM.
6920 if (Inst.getNumOperands() != 5)
6921 return false;
6922 MCInst TmpInst;
6923 TmpInst.setOpcode(ARM::t2STR_PRE);
6924 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6925 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6926 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6927 TmpInst.addOperand(MCOperand::CreateImm(-4));
6928 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6929 TmpInst.addOperand(Inst.getOperand(3));
6930 Inst = TmpInst;
6931 return true;
6932 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006933 case ARM::LDMIA_UPD:
6934 // If this is a load of a single register via a 'pop', then we should use
6935 // a post-indexed LDR instruction instead, per the ARM ARM.
6936 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6937 Inst.getNumOperands() == 5) {
6938 MCInst TmpInst;
6939 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6940 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6941 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6942 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6943 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6944 TmpInst.addOperand(MCOperand::CreateImm(4));
6945 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6946 TmpInst.addOperand(Inst.getOperand(3));
6947 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006948 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006949 }
6950 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00006951 case ARM::STMDB_UPD:
6952 // If this is a store of a single register via a 'push', then we should use
6953 // a pre-indexed STR instruction instead, per the ARM ARM.
6954 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6955 Inst.getNumOperands() == 5) {
6956 MCInst TmpInst;
6957 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6958 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6959 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6960 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6961 TmpInst.addOperand(MCOperand::CreateImm(-4));
6962 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6963 TmpInst.addOperand(Inst.getOperand(3));
6964 Inst = TmpInst;
6965 }
6966 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00006967 case ARM::t2ADDri12:
6968 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6969 // mnemonic was used (not "addw"), encoding T3 is preferred.
6970 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6971 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6972 break;
6973 Inst.setOpcode(ARM::t2ADDri);
6974 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6975 break;
6976 case ARM::t2SUBri12:
6977 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6978 // mnemonic was used (not "subw"), encoding T3 is preferred.
6979 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6980 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6981 break;
6982 Inst.setOpcode(ARM::t2SUBri);
6983 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6984 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00006985 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00006986 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00006987 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6988 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6989 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00006990 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00006991 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00006992 return true;
6993 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00006994 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00006995 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00006996 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00006997 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6998 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6999 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007000 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007001 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007002 return true;
7003 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007004 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007005 case ARM::t2ADDri:
7006 case ARM::t2SUBri: {
7007 // If the destination and first source operand are the same, and
7008 // the flags are compatible with the current IT status, use encoding T2
7009 // instead of T3. For compatibility with the system 'as'. Make sure the
7010 // wide encoding wasn't explicit.
7011 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007012 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007013 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7014 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7015 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7016 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7017 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7018 break;
7019 MCInst TmpInst;
7020 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7021 ARM::tADDi8 : ARM::tSUBi8);
7022 TmpInst.addOperand(Inst.getOperand(0));
7023 TmpInst.addOperand(Inst.getOperand(5));
7024 TmpInst.addOperand(Inst.getOperand(0));
7025 TmpInst.addOperand(Inst.getOperand(2));
7026 TmpInst.addOperand(Inst.getOperand(3));
7027 TmpInst.addOperand(Inst.getOperand(4));
7028 Inst = TmpInst;
7029 return true;
7030 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007031 case ARM::t2ADDrr: {
7032 // If the destination and first source operand are the same, and
7033 // there's no setting of the flags, use encoding T2 instead of T3.
7034 // Note that this is only for ADD, not SUB. This mirrors the system
7035 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7036 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7037 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007038 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7039 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007040 break;
7041 MCInst TmpInst;
7042 TmpInst.setOpcode(ARM::tADDhirr);
7043 TmpInst.addOperand(Inst.getOperand(0));
7044 TmpInst.addOperand(Inst.getOperand(0));
7045 TmpInst.addOperand(Inst.getOperand(2));
7046 TmpInst.addOperand(Inst.getOperand(3));
7047 TmpInst.addOperand(Inst.getOperand(4));
7048 Inst = TmpInst;
7049 return true;
7050 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007051 case ARM::tADDrSP: {
7052 // If the non-SP source operand and the destination operand are not the
7053 // same, we need to use the 32-bit encoding if it's available.
7054 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7055 Inst.setOpcode(ARM::t2ADDrr);
7056 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7057 return true;
7058 }
7059 break;
7060 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007061 case ARM::tB:
7062 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007063 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007064 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007065 return true;
7066 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007067 break;
7068 case ARM::t2B:
7069 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007070 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007071 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007072 return true;
7073 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007074 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007075 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007076 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007077 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007078 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007079 return true;
7080 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007081 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007082 case ARM::tBcc:
7083 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007084 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007085 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007086 return true;
7087 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007088 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007089 case ARM::tLDMIA: {
7090 // If the register list contains any high registers, or if the writeback
7091 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7092 // instead if we're in Thumb2. Otherwise, this should have generated
7093 // an error in validateInstruction().
7094 unsigned Rn = Inst.getOperand(0).getReg();
7095 bool hasWritebackToken =
7096 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7097 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7098 bool listContainsBase;
7099 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7100 (!listContainsBase && !hasWritebackToken) ||
7101 (listContainsBase && hasWritebackToken)) {
7102 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7103 assert (isThumbTwo());
7104 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7105 // If we're switching to the updating version, we need to insert
7106 // the writeback tied operand.
7107 if (hasWritebackToken)
7108 Inst.insert(Inst.begin(),
7109 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007110 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007111 }
7112 break;
7113 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007114 case ARM::tSTMIA_UPD: {
7115 // If the register list contains any high registers, we need to use
7116 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7117 // should have generated an error in validateInstruction().
7118 unsigned Rn = Inst.getOperand(0).getReg();
7119 bool listContainsBase;
7120 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7121 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7122 assert (isThumbTwo());
7123 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007124 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007125 }
7126 break;
7127 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007128 case ARM::tPOP: {
7129 bool listContainsBase;
7130 // If the register list contains any high registers, we need to use
7131 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7132 // should have generated an error in validateInstruction().
7133 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007134 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007135 assert (isThumbTwo());
7136 Inst.setOpcode(ARM::t2LDMIA_UPD);
7137 // Add the base register and writeback operands.
7138 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7139 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007140 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007141 }
7142 case ARM::tPUSH: {
7143 bool listContainsBase;
7144 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007145 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007146 assert (isThumbTwo());
7147 Inst.setOpcode(ARM::t2STMDB_UPD);
7148 // Add the base register and writeback operands.
7149 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7150 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007151 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007152 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007153 case ARM::t2MOVi: {
7154 // If we can use the 16-bit encoding and the user didn't explicitly
7155 // request the 32-bit variant, transform it here.
7156 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007157 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007158 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7159 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7160 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007161 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7162 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7163 // The operands aren't in the same order for tMOVi8...
7164 MCInst TmpInst;
7165 TmpInst.setOpcode(ARM::tMOVi8);
7166 TmpInst.addOperand(Inst.getOperand(0));
7167 TmpInst.addOperand(Inst.getOperand(4));
7168 TmpInst.addOperand(Inst.getOperand(1));
7169 TmpInst.addOperand(Inst.getOperand(2));
7170 TmpInst.addOperand(Inst.getOperand(3));
7171 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007172 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007173 }
7174 break;
7175 }
7176 case ARM::t2MOVr: {
7177 // If we can use the 16-bit encoding and the user didn't explicitly
7178 // request the 32-bit variant, transform it here.
7179 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7180 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7181 Inst.getOperand(2).getImm() == ARMCC::AL &&
7182 Inst.getOperand(4).getReg() == ARM::CPSR &&
7183 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7184 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7185 // The operands aren't the same for tMOV[S]r... (no cc_out)
7186 MCInst TmpInst;
7187 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7188 TmpInst.addOperand(Inst.getOperand(0));
7189 TmpInst.addOperand(Inst.getOperand(1));
7190 TmpInst.addOperand(Inst.getOperand(2));
7191 TmpInst.addOperand(Inst.getOperand(3));
7192 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007193 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007194 }
7195 break;
7196 }
Jim Grosbach82213192011-09-19 20:29:33 +00007197 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007198 case ARM::t2SXTB:
7199 case ARM::t2UXTH:
7200 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007201 // If we can use the 16-bit encoding and the user didn't explicitly
7202 // request the 32-bit variant, transform it here.
7203 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7204 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7205 Inst.getOperand(2).getImm() == 0 &&
7206 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7207 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007208 unsigned NewOpc;
7209 switch (Inst.getOpcode()) {
7210 default: llvm_unreachable("Illegal opcode!");
7211 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7212 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7213 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7214 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7215 }
Jim Grosbach82213192011-09-19 20:29:33 +00007216 // The operands aren't the same for thumb1 (no rotate operand).
7217 MCInst TmpInst;
7218 TmpInst.setOpcode(NewOpc);
7219 TmpInst.addOperand(Inst.getOperand(0));
7220 TmpInst.addOperand(Inst.getOperand(1));
7221 TmpInst.addOperand(Inst.getOperand(3));
7222 TmpInst.addOperand(Inst.getOperand(4));
7223 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007224 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007225 }
7226 break;
7227 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007228 case ARM::MOVsi: {
7229 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007230 // rrx shifts and asr/lsr of #32 is encoded as 0
7231 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7232 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007233 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7234 // Shifting by zero is accepted as a vanilla 'MOVr'
7235 MCInst TmpInst;
7236 TmpInst.setOpcode(ARM::MOVr);
7237 TmpInst.addOperand(Inst.getOperand(0));
7238 TmpInst.addOperand(Inst.getOperand(1));
7239 TmpInst.addOperand(Inst.getOperand(3));
7240 TmpInst.addOperand(Inst.getOperand(4));
7241 TmpInst.addOperand(Inst.getOperand(5));
7242 Inst = TmpInst;
7243 return true;
7244 }
7245 return false;
7246 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007247 case ARM::ANDrsi:
7248 case ARM::ORRrsi:
7249 case ARM::EORrsi:
7250 case ARM::BICrsi:
7251 case ARM::SUBrsi:
7252 case ARM::ADDrsi: {
7253 unsigned newOpc;
7254 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7255 if (SOpc == ARM_AM::rrx) return false;
7256 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007257 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007258 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7259 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7260 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7261 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7262 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7263 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7264 }
7265 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007266 // The exception is for right shifts, where 0 == 32
7267 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7268 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007269 MCInst TmpInst;
7270 TmpInst.setOpcode(newOpc);
7271 TmpInst.addOperand(Inst.getOperand(0));
7272 TmpInst.addOperand(Inst.getOperand(1));
7273 TmpInst.addOperand(Inst.getOperand(2));
7274 TmpInst.addOperand(Inst.getOperand(4));
7275 TmpInst.addOperand(Inst.getOperand(5));
7276 TmpInst.addOperand(Inst.getOperand(6));
7277 Inst = TmpInst;
7278 return true;
7279 }
7280 return false;
7281 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007282 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007283 case ARM::t2IT: {
7284 // The mask bits for all but the first condition are represented as
7285 // the low bit of the condition code value implies 't'. We currently
7286 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007287 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007288 MCOperand &MO = Inst.getOperand(1);
7289 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007290 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007291 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007292 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007293 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007294 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007295 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007296 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007297
7298 // Set up the IT block state according to the IT instruction we just
7299 // matched.
7300 assert(!inITBlock() && "nested IT blocks?!");
7301 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7302 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7303 ITState.CurPosition = 0;
7304 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007305 break;
7306 }
Richard Bartona39625e2012-07-09 16:12:24 +00007307 case ARM::t2LSLrr:
7308 case ARM::t2LSRrr:
7309 case ARM::t2ASRrr:
7310 case ARM::t2SBCrr:
7311 case ARM::t2RORrr:
7312 case ARM::t2BICrr:
7313 {
Richard Bartond5660372012-07-09 16:14:28 +00007314 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007315 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7316 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7317 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007318 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7319 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007320 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7321 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7322 unsigned NewOpc;
7323 switch (Inst.getOpcode()) {
7324 default: llvm_unreachable("unexpected opcode");
7325 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7326 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7327 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7328 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7329 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7330 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7331 }
7332 MCInst TmpInst;
7333 TmpInst.setOpcode(NewOpc);
7334 TmpInst.addOperand(Inst.getOperand(0));
7335 TmpInst.addOperand(Inst.getOperand(5));
7336 TmpInst.addOperand(Inst.getOperand(1));
7337 TmpInst.addOperand(Inst.getOperand(2));
7338 TmpInst.addOperand(Inst.getOperand(3));
7339 TmpInst.addOperand(Inst.getOperand(4));
7340 Inst = TmpInst;
7341 return true;
7342 }
7343 return false;
7344 }
7345 case ARM::t2ANDrr:
7346 case ARM::t2EORrr:
7347 case ARM::t2ADCrr:
7348 case ARM::t2ORRrr:
7349 {
Richard Bartond5660372012-07-09 16:14:28 +00007350 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007351 // These instructions are special in that they are commutable, so shorter encodings
7352 // are available more often.
7353 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7354 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7355 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7356 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007357 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7358 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007359 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7360 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7361 unsigned NewOpc;
7362 switch (Inst.getOpcode()) {
7363 default: llvm_unreachable("unexpected opcode");
7364 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7365 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7366 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7367 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7368 }
7369 MCInst TmpInst;
7370 TmpInst.setOpcode(NewOpc);
7371 TmpInst.addOperand(Inst.getOperand(0));
7372 TmpInst.addOperand(Inst.getOperand(5));
7373 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7374 TmpInst.addOperand(Inst.getOperand(1));
7375 TmpInst.addOperand(Inst.getOperand(2));
7376 } else {
7377 TmpInst.addOperand(Inst.getOperand(2));
7378 TmpInst.addOperand(Inst.getOperand(1));
7379 }
7380 TmpInst.addOperand(Inst.getOperand(3));
7381 TmpInst.addOperand(Inst.getOperand(4));
7382 Inst = TmpInst;
7383 return true;
7384 }
7385 return false;
7386 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007387 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007388 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007389}
7390
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007391unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7392 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7393 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007394 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007395 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007396 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7397 assert(MCID.hasOptionalDef() &&
7398 "optionally flag setting instruction missing optional def operand");
7399 assert(MCID.NumOperands == Inst.getNumOperands() &&
7400 "operand count mismatch!");
7401 // Find the optional-def operand (cc_out).
7402 unsigned OpNo;
7403 for (OpNo = 0;
7404 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7405 ++OpNo)
7406 ;
7407 // If we're parsing Thumb1, reject it completely.
7408 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7409 return Match_MnemonicFail;
7410 // If we're parsing Thumb2, which form is legal depends on whether we're
7411 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007412 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7413 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007414 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007415 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7416 inITBlock())
7417 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007418 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007419 // Some high-register supporting Thumb1 encodings only allow both registers
7420 // to be from r0-r7 when in Thumb2.
7421 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7422 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7423 isARMLowRegister(Inst.getOperand(2).getReg()))
7424 return Match_RequiresThumb2;
7425 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007426 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007427 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7428 isARMLowRegister(Inst.getOperand(1).getReg()))
7429 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007430 return Match_Success;
7431}
7432
Jim Grosbach5117ef72012-04-24 22:40:08 +00007433static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007434bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007435MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007436 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007437 MCStreamer &Out, unsigned &ErrorInfo,
7438 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007439 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007440 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007441
Chad Rosier2f480a82012-10-12 22:53:36 +00007442 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007443 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007444 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007445 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007446 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007447 // Context sensitive operand constraints aren't handled by the matcher,
7448 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007449 if (validateInstruction(Inst, Operands)) {
7450 // Still progress the IT block, otherwise one wrong condition causes
7451 // nasty cascading errors.
7452 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007453 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007454 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007455
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007456 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007457 // encoding is selected. Loop on it while changes happen so the
7458 // individual transformations can chain off each other. E.g.,
7459 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7460 while (processInstruction(Inst, Operands))
7461 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007462
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007463 // Only move forward at the very end so that everything in validate
7464 // and process gets a consistent answer about whether we're in an IT
7465 // block.
7466 forwardITPosition();
7467
Jim Grosbach82f76d12012-01-25 19:52:01 +00007468 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7469 // doesn't actually encode.
7470 if (Inst.getOpcode() == ARM::ITasm)
7471 return false;
7472
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007473 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007474 Out.EmitInstruction(Inst);
7475 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007476 case Match_MissingFeature: {
7477 assert(ErrorInfo && "Unknown missing feature!");
7478 // Special case the error message for the very common case where only
7479 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7480 std::string Msg = "instruction requires:";
7481 unsigned Mask = 1;
7482 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7483 if (ErrorInfo & Mask) {
7484 Msg += " ";
7485 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7486 }
7487 Mask <<= 1;
7488 }
7489 return Error(IDLoc, Msg);
7490 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007491 case Match_InvalidOperand: {
7492 SMLoc ErrorLoc = IDLoc;
7493 if (ErrorInfo != ~0U) {
7494 if (ErrorInfo >= Operands.size())
7495 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007496
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007497 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7498 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7499 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007500
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007501 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007502 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007503 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007504 return Error(IDLoc, "invalid instruction",
7505 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007506 case Match_RequiresNotITBlock:
7507 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007508 case Match_RequiresITBlock:
7509 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007510 case Match_RequiresV6:
7511 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7512 case Match_RequiresThumb2:
7513 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007514 case Match_ImmRange0_4: {
7515 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7516 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7517 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7518 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007519 case Match_ImmRange0_15: {
7520 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7521 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7522 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7523 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007524 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007525
Eric Christopher91d7b902010-10-29 09:26:59 +00007526 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007527}
7528
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007529/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007530bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7531 StringRef IDVal = DirectiveID.getIdentifier();
7532 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007533 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007534 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007535 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007536 else if (IDVal == ".arm")
7537 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007538 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007539 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007540 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007541 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007542 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007543 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007544 else if (IDVal == ".unreq")
7545 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007546 else if (IDVal == ".arch")
7547 return parseDirectiveArch(DirectiveID.getLoc());
7548 else if (IDVal == ".eabi_attribute")
7549 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007550 else if (IDVal == ".fnstart")
7551 return parseDirectiveFnStart(DirectiveID.getLoc());
7552 else if (IDVal == ".fnend")
7553 return parseDirectiveFnEnd(DirectiveID.getLoc());
7554 else if (IDVal == ".cantunwind")
7555 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7556 else if (IDVal == ".personality")
7557 return parseDirectivePersonality(DirectiveID.getLoc());
7558 else if (IDVal == ".handlerdata")
7559 return parseDirectiveHandlerData(DirectiveID.getLoc());
7560 else if (IDVal == ".setfp")
7561 return parseDirectiveSetFP(DirectiveID.getLoc());
7562 else if (IDVal == ".pad")
7563 return parseDirectivePad(DirectiveID.getLoc());
7564 else if (IDVal == ".save")
7565 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7566 else if (IDVal == ".vsave")
7567 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007568 return true;
7569}
7570
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007571/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007572/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007573bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007574 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7575 for (;;) {
7576 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007577 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007578 return true;
7579
Eric Christopherbf7bc492013-01-09 03:52:05 +00007580 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007581
7582 if (getLexer().is(AsmToken::EndOfStatement))
7583 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007584
Kevin Enderbyccab3172009-09-15 00:27:25 +00007585 // FIXME: Improve diagnostic.
7586 if (getLexer().isNot(AsmToken::Comma))
7587 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007588 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007589 }
7590 }
7591
Sean Callanana83fd7d2010-01-19 20:27:46 +00007592 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007593 return false;
7594}
7595
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007596/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007597/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007598bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007599 if (getLexer().isNot(AsmToken::EndOfStatement))
7600 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007601 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007602
Tim Northovera2292d02013-06-10 23:20:58 +00007603 if (!hasThumb())
7604 return Error(L, "target does not support Thumb mode");
7605
Jim Grosbach7f882392011-12-07 18:04:19 +00007606 if (!isThumb())
7607 SwitchMode();
7608 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7609 return false;
7610}
7611
7612/// parseDirectiveARM
7613/// ::= .arm
7614bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7615 if (getLexer().isNot(AsmToken::EndOfStatement))
7616 return Error(L, "unexpected token in directive");
7617 Parser.Lex();
7618
Tim Northovera2292d02013-06-10 23:20:58 +00007619 if (!hasARM())
7620 return Error(L, "target does not support ARM mode");
7621
Jim Grosbach7f882392011-12-07 18:04:19 +00007622 if (isThumb())
7623 SwitchMode();
7624 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007625 return false;
7626}
7627
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007628/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007629/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007630bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007631 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7632 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007633 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007634 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007635
Jim Grosbach1152cc02011-12-21 22:30:16 +00007636 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007637 // ELF doesn't
7638 if (isMachO) {
7639 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007640 if (Tok.isNot(AsmToken::EndOfStatement)) {
7641 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7642 return Error(L, "unexpected token in .thumb_func directive");
7643 Name = Tok.getIdentifier();
7644 Parser.Lex(); // Consume the identifier token.
7645 needFuncName = false;
7646 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007647 }
7648
Jim Grosbach1152cc02011-12-21 22:30:16 +00007649 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007650 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007651
7652 // Eat the end of statement and any blank lines that follow.
7653 while (getLexer().is(AsmToken::EndOfStatement))
7654 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007655
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007656 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007657 // We really should be checking the next symbol definition even if there's
7658 // stuff in between.
7659 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007660 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007661 }
7662
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007663 // Mark symbol as a thumb symbol.
7664 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7665 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007666 return false;
7667}
7668
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007669/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007670/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007671bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007672 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007673 if (Tok.isNot(AsmToken::Identifier))
7674 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007675 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007676 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007677 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007678 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007679 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007680 else
7681 return Error(L, "unrecognized syntax mode in .syntax directive");
7682
7683 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007684 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007685 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007686
7687 // TODO tell the MC streamer the mode
7688 // getParser().getStreamer().Emit???();
7689 return false;
7690}
7691
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007692/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007693/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007694bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007695 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007696 if (Tok.isNot(AsmToken::Integer))
7697 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007698 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007699 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007700 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007701 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007702 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007703 else
7704 return Error(L, "invalid operand to .code directive");
7705
7706 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007707 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007708 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007709
Evan Cheng284b4672011-07-08 22:36:29 +00007710 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007711 if (!hasThumb())
7712 return Error(L, "target does not support Thumb mode");
7713
Jim Grosbachf471ac32011-09-06 18:46:23 +00007714 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007715 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007716 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007717 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007718 if (!hasARM())
7719 return Error(L, "target does not support ARM mode");
7720
Jim Grosbachf471ac32011-09-06 18:46:23 +00007721 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007722 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007723 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007724 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007725
Kevin Enderby146dcf22009-10-15 20:48:48 +00007726 return false;
7727}
7728
Jim Grosbachab5830e2011-12-14 02:16:11 +00007729/// parseDirectiveReq
7730/// ::= name .req registername
7731bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7732 Parser.Lex(); // Eat the '.req' token.
7733 unsigned Reg;
7734 SMLoc SRegLoc, ERegLoc;
7735 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007736 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007737 return Error(SRegLoc, "register name expected");
7738 }
7739
7740 // Shouldn't be anything else.
7741 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007742 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007743 return Error(Parser.getTok().getLoc(),
7744 "unexpected input in .req directive.");
7745 }
7746
7747 Parser.Lex(); // Consume the EndOfStatement
7748
7749 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7750 return Error(SRegLoc, "redefinition of '" + Name +
7751 "' does not match original.");
7752
7753 return false;
7754}
7755
7756/// parseDirectiveUneq
7757/// ::= .unreq registername
7758bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7759 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007760 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007761 return Error(L, "unexpected input in .unreq directive.");
7762 }
7763 RegisterReqs.erase(Parser.getTok().getIdentifier());
7764 Parser.Lex(); // Eat the identifier.
7765 return false;
7766}
7767
Jason W Kim135d2442011-12-20 17:38:12 +00007768/// parseDirectiveArch
7769/// ::= .arch token
7770bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7771 return true;
7772}
7773
7774/// parseDirectiveEabiAttr
7775/// ::= .eabi_attribute int, int
7776bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7777 return true;
7778}
7779
Logan Chien4ea23b52013-05-10 16:17:24 +00007780/// parseDirectiveFnStart
7781/// ::= .fnstart
7782bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7783 if (FnStartLoc.isValid()) {
7784 Error(L, ".fnstart starts before the end of previous one");
7785 Error(FnStartLoc, "previous .fnstart starts here");
7786 return true;
7787 }
7788
7789 FnStartLoc = L;
7790 getParser().getStreamer().EmitFnStart();
7791 return false;
7792}
7793
7794/// parseDirectiveFnEnd
7795/// ::= .fnend
7796bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7797 // Check the ordering of unwind directives
7798 if (!FnStartLoc.isValid())
7799 return Error(L, ".fnstart must precede .fnend directive");
7800
7801 // Reset the unwind directives parser state
7802 resetUnwindDirectiveParserState();
7803
7804 getParser().getStreamer().EmitFnEnd();
7805 return false;
7806}
7807
7808/// parseDirectiveCantUnwind
7809/// ::= .cantunwind
7810bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7811 // Check the ordering of unwind directives
7812 CantUnwindLoc = L;
7813 if (!FnStartLoc.isValid())
7814 return Error(L, ".fnstart must precede .cantunwind directive");
7815 if (HandlerDataLoc.isValid()) {
7816 Error(L, ".cantunwind can't be used with .handlerdata directive");
7817 Error(HandlerDataLoc, ".handlerdata was specified here");
7818 return true;
7819 }
7820 if (PersonalityLoc.isValid()) {
7821 Error(L, ".cantunwind can't be used with .personality directive");
7822 Error(PersonalityLoc, ".personality was specified here");
7823 return true;
7824 }
7825
7826 getParser().getStreamer().EmitCantUnwind();
7827 return false;
7828}
7829
7830/// parseDirectivePersonality
7831/// ::= .personality name
7832bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7833 // Check the ordering of unwind directives
7834 PersonalityLoc = L;
7835 if (!FnStartLoc.isValid())
7836 return Error(L, ".fnstart must precede .personality directive");
7837 if (CantUnwindLoc.isValid()) {
7838 Error(L, ".personality can't be used with .cantunwind directive");
7839 Error(CantUnwindLoc, ".cantunwind was specified here");
7840 return true;
7841 }
7842 if (HandlerDataLoc.isValid()) {
7843 Error(L, ".personality must precede .handlerdata directive");
7844 Error(HandlerDataLoc, ".handlerdata was specified here");
7845 return true;
7846 }
7847
7848 // Parse the name of the personality routine
7849 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7850 Parser.eatToEndOfStatement();
7851 return Error(L, "unexpected input in .personality directive.");
7852 }
7853 StringRef Name(Parser.getTok().getIdentifier());
7854 Parser.Lex();
7855
7856 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7857 getParser().getStreamer().EmitPersonality(PR);
7858 return false;
7859}
7860
7861/// parseDirectiveHandlerData
7862/// ::= .handlerdata
7863bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7864 // Check the ordering of unwind directives
7865 HandlerDataLoc = L;
7866 if (!FnStartLoc.isValid())
7867 return Error(L, ".fnstart must precede .personality directive");
7868 if (CantUnwindLoc.isValid()) {
7869 Error(L, ".handlerdata can't be used with .cantunwind directive");
7870 Error(CantUnwindLoc, ".cantunwind was specified here");
7871 return true;
7872 }
7873
7874 getParser().getStreamer().EmitHandlerData();
7875 return false;
7876}
7877
7878/// parseDirectiveSetFP
7879/// ::= .setfp fpreg, spreg [, offset]
7880bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
7881 // Check the ordering of unwind directives
7882 if (!FnStartLoc.isValid())
7883 return Error(L, ".fnstart must precede .setfp directive");
7884 if (HandlerDataLoc.isValid())
7885 return Error(L, ".setfp must precede .handlerdata directive");
7886
7887 // Parse fpreg
7888 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
7889 int NewFPReg = tryParseRegister();
7890 if (NewFPReg == -1)
7891 return Error(NewFPRegLoc, "frame pointer register expected");
7892
7893 // Consume comma
7894 if (!Parser.getTok().is(AsmToken::Comma))
7895 return Error(Parser.getTok().getLoc(), "comma expected");
7896 Parser.Lex(); // skip comma
7897
7898 // Parse spreg
7899 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
7900 int NewSPReg = tryParseRegister();
7901 if (NewSPReg == -1)
7902 return Error(NewSPRegLoc, "stack pointer register expected");
7903
7904 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
7905 return Error(NewSPRegLoc,
7906 "register should be either $sp or the latest fp register");
7907
7908 // Update the frame pointer register
7909 FPReg = NewFPReg;
7910
7911 // Parse offset
7912 int64_t Offset = 0;
7913 if (Parser.getTok().is(AsmToken::Comma)) {
7914 Parser.Lex(); // skip comma
7915
7916 if (Parser.getTok().isNot(AsmToken::Hash) &&
7917 Parser.getTok().isNot(AsmToken::Dollar)) {
7918 return Error(Parser.getTok().getLoc(), "'#' expected");
7919 }
7920 Parser.Lex(); // skip hash token.
7921
7922 const MCExpr *OffsetExpr;
7923 SMLoc ExLoc = Parser.getTok().getLoc();
7924 SMLoc EndLoc;
7925 if (getParser().parseExpression(OffsetExpr, EndLoc))
7926 return Error(ExLoc, "malformed setfp offset");
7927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7928 if (!CE)
7929 return Error(ExLoc, "setfp offset must be an immediate");
7930
7931 Offset = CE->getValue();
7932 }
7933
7934 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
7935 static_cast<unsigned>(NewSPReg),
7936 Offset);
7937 return false;
7938}
7939
7940/// parseDirective
7941/// ::= .pad offset
7942bool ARMAsmParser::parseDirectivePad(SMLoc L) {
7943 // Check the ordering of unwind directives
7944 if (!FnStartLoc.isValid())
7945 return Error(L, ".fnstart must precede .pad directive");
7946 if (HandlerDataLoc.isValid())
7947 return Error(L, ".pad must precede .handlerdata directive");
7948
7949 // Parse the offset
7950 if (Parser.getTok().isNot(AsmToken::Hash) &&
7951 Parser.getTok().isNot(AsmToken::Dollar)) {
7952 return Error(Parser.getTok().getLoc(), "'#' expected");
7953 }
7954 Parser.Lex(); // skip hash token.
7955
7956 const MCExpr *OffsetExpr;
7957 SMLoc ExLoc = Parser.getTok().getLoc();
7958 SMLoc EndLoc;
7959 if (getParser().parseExpression(OffsetExpr, EndLoc))
7960 return Error(ExLoc, "malformed pad offset");
7961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7962 if (!CE)
7963 return Error(ExLoc, "pad offset must be an immediate");
7964
7965 getParser().getStreamer().EmitPad(CE->getValue());
7966 return false;
7967}
7968
7969/// parseDirectiveRegSave
7970/// ::= .save { registers }
7971/// ::= .vsave { registers }
7972bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
7973 // Check the ordering of unwind directives
7974 if (!FnStartLoc.isValid())
7975 return Error(L, ".fnstart must precede .save or .vsave directives");
7976 if (HandlerDataLoc.isValid())
7977 return Error(L, ".save or .vsave must precede .handlerdata directive");
7978
7979 // Parse the register list
7980 SmallVector<MCParsedAsmOperand*, 1> Operands;
7981 if (parseRegisterList(Operands))
7982 return true;
7983 ARMOperand *Op = (ARMOperand*)Operands[0];
7984 if (!IsVector && !Op->isRegList())
7985 return Error(L, ".save expects GPR registers");
7986 if (IsVector && !Op->isDPRRegList())
7987 return Error(L, ".vsave expects DPR registers");
7988
7989 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
7990 return false;
7991}
7992
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007993/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007994extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007995 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7996 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007997}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007998
Chris Lattner3e4582a2010-09-06 19:11:01 +00007999#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008000#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008001#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008002#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008003
8004// Define this matcher function after the auto-generated include so we
8005// have the match class enum definitions.
8006unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8007 unsigned Kind) {
8008 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8009 // If the kind is a token for a literal immediate, check if our asm
8010 // operand matches. This is for InstAliases which have a fixed-value
8011 // immediate in the syntax.
8012 if (Kind == MCK__35_0 && Op->isImm()) {
8013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8014 if (!CE)
8015 return Match_InvalidOperand;
8016 if (CE->getValue() == 0)
8017 return Match_Success;
8018 }
8019 return Match_InvalidOperand;
8020}