blob: 6c9e445346be4d18eeb8abe10704ea0f877bf688 [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
Logan Chien8cbb80d2013-10-28 17:51:12 +000010#include "ARMBuildAttrs.h"
11#include "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000012#include "ARMFeatures.h"
Evan Cheng11424442011-07-26 00:24:13 +000013#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000015#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "MCTargetDesc/ARMBaseInfo.h"
17#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000018#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000019#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000020#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000021#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000022#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000023#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000024#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000025#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000026#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000027#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000028#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/MC/MCExpr.h"
30#include "llvm/MC/MCInst.h"
31#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000032#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000033#include "llvm/MC/MCParser/MCAsmLexer.h"
34#include "llvm/MC/MCParser/MCAsmParser.h"
35#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
36#include "llvm/MC/MCRegisterInfo.h"
37#include "llvm/MC/MCStreamer.h"
38#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000039#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000040#include "llvm/Support/MathExtras.h"
41#include "llvm/Support/SourceMgr.h"
42#include "llvm/Support/TargetRegistry.h"
43#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000044
Kevin Enderbyccab3172009-09-15 00:27:25 +000045using namespace llvm;
46
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000047namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000048
49class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000050
Jim Grosbach04945c42011-12-02 00:35:16 +000051enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000052
Evan Cheng11424442011-07-26 00:24:13 +000053class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000054 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000055 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +000056 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000057 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000058
Rafael Espindolaa17151a2013-10-08 13:08:17 +000059 ARMTargetStreamer &getTargetStreamer() {
60 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
61 return static_cast<ARMTargetStreamer &>(TS);
62 }
63
Logan Chien4ea23b52013-05-10 16:17:24 +000064 // Unwind directives state
65 SMLoc FnStartLoc;
66 SMLoc CantUnwindLoc;
67 SMLoc PersonalityLoc;
68 SMLoc HandlerDataLoc;
69 int FPReg;
70 void resetUnwindDirectiveParserState() {
71 FnStartLoc = SMLoc();
72 CantUnwindLoc = SMLoc();
73 PersonalityLoc = SMLoc();
74 HandlerDataLoc = SMLoc();
75 FPReg = -1;
76 }
77
Jim Grosbachab5830e2011-12-14 02:16:11 +000078 // Map of register aliases registers via the .req directive.
79 StringMap<unsigned> RegisterReqs;
80
Tim Northover1744d0a2013-10-25 12:49:50 +000081 bool NextSymbolIsThumb;
82
Jim Grosbached16ec42011-08-29 22:24:09 +000083 struct {
84 ARMCC::CondCodes Cond; // Condition for IT block.
85 unsigned Mask:4; // Condition mask for instructions.
86 // Starting at first 1 (from lsb).
87 // '1' condition as indicated in IT.
88 // '0' inverse of condition (else).
89 // Count of instructions in IT block is
90 // 4 - trailingzeroes(mask)
91
92 bool FirstCond; // Explicit flag for when we're parsing the
93 // First instruction in the IT block. It's
94 // implied in the mask, so needs special
95 // handling.
96
97 unsigned CurPosition; // Current position in parsing of IT
98 // block. In range [0,3]. Initialized
99 // according to count of instructions in block.
100 // ~0U if no active IT block.
101 } ITState;
102 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000103 void forwardITPosition() {
104 if (!inITBlock()) return;
105 // Move to the next instruction in the IT block, if there is one. If not,
106 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000107 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000108 if (++ITState.CurPosition == 5 - TZ)
109 ITState.CurPosition = ~0U; // Done with the IT block after this.
110 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000111
112
Kevin Enderbyccab3172009-09-15 00:27:25 +0000113 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000114 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
115
Benjamin Kramer673824b2012-04-15 17:04:27 +0000116 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000117 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000118 return Parser.Warning(L, Msg, Ranges);
119 }
120 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000121 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000122 return Parser.Error(L, Msg, Ranges);
123 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000124
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000125 int tryParseRegister();
126 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000127 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000128 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000129 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000130 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
131 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000132 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
133 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000134 bool parseDirectiveWord(unsigned Size, SMLoc L);
135 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000136 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000137 bool parseDirectiveThumbFunc(SMLoc L);
138 bool parseDirectiveCode(SMLoc L);
139 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000140 bool parseDirectiveReq(StringRef Name, SMLoc L);
141 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000142 bool parseDirectiveArch(SMLoc L);
143 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000144 bool parseDirectiveCPU(SMLoc L);
145 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000146 bool parseDirectiveFnStart(SMLoc L);
147 bool parseDirectiveFnEnd(SMLoc L);
148 bool parseDirectiveCantUnwind(SMLoc L);
149 bool parseDirectivePersonality(SMLoc L);
150 bool parseDirectiveHandlerData(SMLoc L);
151 bool parseDirectiveSetFP(SMLoc L);
152 bool parseDirectivePad(SMLoc L);
153 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000154 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
Kevin Enderby146dcf22009-10-15 20:48:48 +0000155
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000156 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000157 bool &CarrySetting, unsigned &ProcessorIMod,
158 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000159 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
160 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000161 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000162
Evan Cheng4d1ca962011-07-08 01:53:10 +0000163 bool isThumb() const {
164 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000165 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000166 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000167 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000168 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000169 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000170 bool isThumbTwo() const {
171 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
172 }
Tim Northovera2292d02013-06-10 23:20:58 +0000173 bool hasThumb() const {
174 return STI.getFeatureBits() & ARM::HasV4TOps;
175 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000176 bool hasV6Ops() const {
177 return STI.getFeatureBits() & ARM::HasV6Ops;
178 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000179 bool hasV6MOps() const {
180 return STI.getFeatureBits() & ARM::HasV6MOps;
181 }
James Molloy21efa7d2011-09-28 14:21:38 +0000182 bool hasV7Ops() const {
183 return STI.getFeatureBits() & ARM::HasV7Ops;
184 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000185 bool hasV8Ops() const {
186 return STI.getFeatureBits() & ARM::HasV8Ops;
187 }
Tim Northovera2292d02013-06-10 23:20:58 +0000188 bool hasARM() const {
189 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
190 }
191
Evan Cheng284b4672011-07-08 22:36:29 +0000192 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000193 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
194 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000195 }
James Molloy21efa7d2011-09-28 14:21:38 +0000196 bool isMClass() const {
197 return STI.getFeatureBits() & ARM::FeatureMClass;
198 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000199
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000200 /// @name Auto-generated Match Functions
201 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000202
Chris Lattner3e4582a2010-09-06 19:11:01 +0000203#define GET_ASSEMBLER_HEADER
204#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000205
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000206 /// }
207
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000208 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000209 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000210 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000211 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000212 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000213 OperandMatchResultTy parseCoprocOptionOperand(
214 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000215 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000216 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000217 OperandMatchResultTy parseInstSyncBarrierOptOperand(
218 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000219 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000220 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000221 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000222 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000223 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
224 StringRef Op, int Low, int High);
225 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
226 return parsePKHImm(O, "lsl", 0, 31);
227 }
228 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
229 return parsePKHImm(O, "asr", 1, 32);
230 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000231 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000232 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000233 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000234 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000235 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000236 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000237 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000238 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000239 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
240 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000241
242 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000243 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000244 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000245 void cvtThumbBranches(MCInst &Inst,
246 const SmallVectorImpl<MCParsedAsmOperand*> &);
247
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000248 bool validateInstruction(MCInst &Inst,
249 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000250 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000251 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000252 bool shouldOmitCCOutOperand(StringRef Mnemonic,
253 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000254 bool shouldOmitPredicateOperand(StringRef Mnemonic,
255 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000256public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000257 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000258 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000259 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000260 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000261 Match_RequiresThumb2,
262#define GET_OPERAND_DIAGNOSTIC_TYPES
263#include "ARMGenAsmMatcher.inc"
264
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000265 };
266
Joey Gouly0e76fa72013-09-12 10:28:05 +0000267 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
268 const MCInstrInfo &MII)
269 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000270 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000271
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000272 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000273 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000274
Evan Cheng4d1ca962011-07-08 01:53:10 +0000275 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000276 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000277
278 // Not in an ITBlock to start with.
279 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000280
281 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000282 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000283
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000284 // Implementation of the MCTargetAsmParser interface:
285 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000286 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
287 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000288 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000289 bool ParseDirective(AsmToken DirectiveID);
290
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000291 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000292 unsigned checkTargetMatchPredicate(MCInst &Inst);
293
Chad Rosier49963552012-10-13 00:26:04 +0000294 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000295 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000296 MCStreamer &Out, unsigned &ErrorInfo,
297 bool MatchingInlineAsm);
Tim Northover1744d0a2013-10-25 12:49:50 +0000298 void onLabelParsed(MCSymbol *Symbol);
299
Kevin Enderbyccab3172009-09-15 00:27:25 +0000300};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000301} // end anonymous namespace
302
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000303namespace {
304
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000305/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000306/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000307class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000308 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000309 k_CondCode,
310 k_CCOut,
311 k_ITCondMask,
312 k_CoprocNum,
313 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000314 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000315 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000316 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000317 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000318 k_Memory,
319 k_PostIndexRegister,
320 k_MSRMask,
321 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000322 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000323 k_Register,
324 k_RegisterList,
325 k_DPRRegisterList,
326 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000327 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000328 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000329 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000330 k_ShiftedRegister,
331 k_ShiftedImmediate,
332 k_ShifterImmediate,
333 k_RotateImmediate,
334 k_BitfieldDescriptor,
335 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000336 } Kind;
337
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000338 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000339 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000340
Eric Christopher8996c5d2013-03-15 00:42:55 +0000341 struct CCOp {
342 ARMCC::CondCodes Val;
343 };
344
345 struct CopOp {
346 unsigned Val;
347 };
348
349 struct CoprocOptionOp {
350 unsigned Val;
351 };
352
353 struct ITMaskOp {
354 unsigned Mask:4;
355 };
356
357 struct MBOptOp {
358 ARM_MB::MemBOpt Val;
359 };
360
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000361 struct ISBOptOp {
362 ARM_ISB::InstSyncBOpt Val;
363 };
364
Eric Christopher8996c5d2013-03-15 00:42:55 +0000365 struct IFlagsOp {
366 ARM_PROC::IFlags Val;
367 };
368
369 struct MMaskOp {
370 unsigned Val;
371 };
372
373 struct TokOp {
374 const char *Data;
375 unsigned Length;
376 };
377
378 struct RegOp {
379 unsigned RegNum;
380 };
381
382 // A vector register list is a sequential list of 1 to 4 registers.
383 struct VectorListOp {
384 unsigned RegNum;
385 unsigned Count;
386 unsigned LaneIndex;
387 bool isDoubleSpaced;
388 };
389
390 struct VectorIndexOp {
391 unsigned Val;
392 };
393
394 struct ImmOp {
395 const MCExpr *Val;
396 };
397
398 /// Combined record for all forms of ARM address expressions.
399 struct MemoryOp {
400 unsigned BaseRegNum;
401 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
402 // was specified.
403 const MCConstantExpr *OffsetImm; // Offset immediate value
404 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
405 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
406 unsigned ShiftImm; // shift for OffsetReg.
407 unsigned Alignment; // 0 = no alignment specified
408 // n = alignment in bytes (2, 4, 8, 16, or 32)
409 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
410 };
411
412 struct PostIdxRegOp {
413 unsigned RegNum;
414 bool isAdd;
415 ARM_AM::ShiftOpc ShiftTy;
416 unsigned ShiftImm;
417 };
418
419 struct ShifterImmOp {
420 bool isASR;
421 unsigned Imm;
422 };
423
424 struct RegShiftedRegOp {
425 ARM_AM::ShiftOpc ShiftTy;
426 unsigned SrcReg;
427 unsigned ShiftReg;
428 unsigned ShiftImm;
429 };
430
431 struct RegShiftedImmOp {
432 ARM_AM::ShiftOpc ShiftTy;
433 unsigned SrcReg;
434 unsigned ShiftImm;
435 };
436
437 struct RotImmOp {
438 unsigned Imm;
439 };
440
441 struct BitfieldOp {
442 unsigned LSB;
443 unsigned Width;
444 };
445
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000446 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000447 struct CCOp CC;
448 struct CopOp Cop;
449 struct CoprocOptionOp CoprocOption;
450 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000451 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000452 struct ITMaskOp ITMask;
453 struct IFlagsOp IFlags;
454 struct MMaskOp MMask;
455 struct TokOp Tok;
456 struct RegOp Reg;
457 struct VectorListOp VectorList;
458 struct VectorIndexOp VectorIndex;
459 struct ImmOp Imm;
460 struct MemoryOp Memory;
461 struct PostIdxRegOp PostIdxReg;
462 struct ShifterImmOp ShifterImm;
463 struct RegShiftedRegOp RegShiftedReg;
464 struct RegShiftedImmOp RegShiftedImm;
465 struct RotImmOp RotImm;
466 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000467 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000468
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000469 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
470public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000471 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
472 Kind = o.Kind;
473 StartLoc = o.StartLoc;
474 EndLoc = o.EndLoc;
475 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000476 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000477 CC = o.CC;
478 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000479 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000480 ITMask = o.ITMask;
481 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000482 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000483 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000484 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000485 case k_CCOut:
486 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000487 Reg = o.Reg;
488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_RegisterList:
490 case k_DPRRegisterList:
491 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000492 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000493 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000494 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000495 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000496 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000497 VectorList = o.VectorList;
498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_CoprocNum:
500 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000501 Cop = o.Cop;
502 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000503 case k_CoprocOption:
504 CoprocOption = o.CoprocOption;
505 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000506 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000507 Imm = o.Imm;
508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000510 MBOpt = o.MBOpt;
511 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000512 case k_InstSyncBarrierOpt:
513 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000514 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000515 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000517 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000518 PostIdxReg = o.PostIdxReg;
519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000520 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000521 MMask = o.MMask;
522 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000523 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000524 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000525 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000526 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000527 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000528 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000529 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000530 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000531 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000532 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000533 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000534 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000535 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000536 RotImm = o.RotImm;
537 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000538 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000539 Bitfield = o.Bitfield;
540 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000541 case k_VectorIndex:
542 VectorIndex = o.VectorIndex;
543 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000544 }
545 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000546
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000547 /// getStartLoc - Get the location of the first token of this operand.
548 SMLoc getStartLoc() const { return StartLoc; }
549 /// getEndLoc - Get the location of the last token of this operand.
550 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000551 /// getLocRange - Get the range between the first and last token of this
552 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000553 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
554
Daniel Dunbard8042b72010-08-11 06:36:53 +0000555 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000557 return CC.Val;
558 }
559
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000560 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000561 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000562 return Cop.Val;
563 }
564
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000565 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000566 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000567 return StringRef(Tok.Data, Tok.Length);
568 }
569
570 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000572 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000573 }
574
Bill Wendlingbed94652010-11-09 23:28:44 +0000575 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000576 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
577 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000578 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000579 }
580
Kevin Enderbyf5079942009-10-13 22:19:02 +0000581 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000582 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000583 return Imm.Val;
584 }
585
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000586 unsigned getVectorIndex() const {
587 assert(Kind == k_VectorIndex && "Invalid access!");
588 return VectorIndex.Val;
589 }
590
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000591 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000592 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000593 return MBOpt.Val;
594 }
595
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000596 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
597 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
598 return ISBOpt.Val;
599 }
600
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000601 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000602 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000603 return IFlags.Val;
604 }
605
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000606 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000608 return MMask.Val;
609 }
610
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000611 bool isCoprocNum() const { return Kind == k_CoprocNum; }
612 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000613 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000614 bool isCondCode() const { return Kind == k_CondCode; }
615 bool isCCOut() const { return Kind == k_CCOut; }
616 bool isITMask() const { return Kind == k_ITCondMask; }
617 bool isITCondCode() const { return Kind == k_CondCode; }
618 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000619 // checks whether this operand is an unsigned offset which fits is a field
620 // of specified width and scaled by a specific number of bits
621 template<unsigned width, unsigned scale>
622 bool isUnsignedOffset() const {
623 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000624 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000625 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
626 int64_t Val = CE->getValue();
627 int64_t Align = 1LL << scale;
628 int64_t Max = Align * ((1LL << width) - 1);
629 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
630 }
631 return false;
632 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000633 // checks whether this operand is an signed offset which fits is a field
634 // of specified width and scaled by a specific number of bits
635 template<unsigned width, unsigned scale>
636 bool isSignedOffset() const {
637 if (!isImm()) return false;
638 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
639 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
640 int64_t Val = CE->getValue();
641 int64_t Align = 1LL << scale;
642 int64_t Max = Align * ((1LL << (width-1)) - 1);
643 int64_t Min = -Align * (1LL << (width-1));
644 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
645 }
646 return false;
647 }
648
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000649 // checks whether this operand is a memory operand computed as an offset
650 // applied to PC. the offset may have 8 bits of magnitude and is represented
651 // with two bits of shift. textually it may be either [pc, #imm], #imm or
652 // relocable expression...
653 bool isThumbMemPC() const {
654 int64_t Val = 0;
655 if (isImm()) {
656 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
658 if (!CE) return false;
659 Val = CE->getValue();
660 }
661 else if (isMem()) {
662 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
663 if(Memory.BaseRegNum != ARM::PC) return false;
664 Val = Memory.OffsetImm->getValue();
665 }
666 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000667 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000668 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000669 bool isFPImm() const {
670 if (!isImm()) return false;
671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
674 return Val != -1;
675 }
Jim Grosbachea231912011-12-22 22:19:05 +0000676 bool isFBits16() const {
677 if (!isImm()) return false;
678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
679 if (!CE) return false;
680 int64_t Value = CE->getValue();
681 return Value >= 0 && Value <= 16;
682 }
683 bool isFBits32() const {
684 if (!isImm()) return false;
685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
686 if (!CE) return false;
687 int64_t Value = CE->getValue();
688 return Value >= 1 && Value <= 32;
689 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000690 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000691 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
696 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000697 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000698 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
703 }
704 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000705 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = CE->getValue();
709 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
710 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000711 bool isImm0_508s4Neg() const {
712 if (!isImm()) return false;
713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = -CE->getValue();
716 // explicitly exclude zero. we want that to use the normal 0_508 version.
717 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
718 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000719 bool isImm0_239() const {
720 if (!isImm()) return false;
721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
722 if (!CE) return false;
723 int64_t Value = CE->getValue();
724 return Value >= 0 && Value < 240;
725 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000726 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000727 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
729 if (!CE) return false;
730 int64_t Value = CE->getValue();
731 return Value >= 0 && Value < 256;
732 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000733 bool isImm0_4095() const {
734 if (!isImm()) return false;
735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
736 if (!CE) return false;
737 int64_t Value = CE->getValue();
738 return Value >= 0 && Value < 4096;
739 }
740 bool isImm0_4095Neg() const {
741 if (!isImm()) return false;
742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
743 if (!CE) return false;
744 int64_t Value = -CE->getValue();
745 return Value > 0 && Value < 4096;
746 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000747 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000748 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
750 if (!CE) return false;
751 int64_t Value = CE->getValue();
752 return Value >= 0 && Value < 2;
753 }
754 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000755 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
757 if (!CE) return false;
758 int64_t Value = CE->getValue();
759 return Value >= 0 && Value < 4;
760 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000761 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000762 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
764 if (!CE) return false;
765 int64_t Value = CE->getValue();
766 return Value >= 0 && Value < 8;
767 }
768 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000769 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int64_t Value = CE->getValue();
773 return Value >= 0 && Value < 16;
774 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000775 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000776 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value >= 0 && Value < 32;
781 }
Jim Grosbach00326402011-12-08 01:30:04 +0000782 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000783 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 0 && Value < 64;
788 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000789 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000790 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
794 return Value == 8;
795 }
796 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000797 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
801 return Value == 16;
802 }
803 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000804 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return Value == 32;
809 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000810 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000811 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = CE->getValue();
815 return Value > 0 && Value <= 8;
816 }
817 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000818 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
820 if (!CE) return false;
821 int64_t Value = CE->getValue();
822 return Value > 0 && Value <= 16;
823 }
824 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000825 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
827 if (!CE) return false;
828 int64_t Value = CE->getValue();
829 return Value > 0 && Value <= 32;
830 }
831 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000832 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
834 if (!CE) return false;
835 int64_t Value = CE->getValue();
836 return Value > 0 && Value <= 64;
837 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000838 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000839 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
841 if (!CE) return false;
842 int64_t Value = CE->getValue();
843 return Value > 0 && Value < 8;
844 }
845 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000846 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000847 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
848 if (!CE) return false;
849 int64_t Value = CE->getValue();
850 return Value > 0 && Value < 16;
851 }
852 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000853 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
855 if (!CE) return false;
856 int64_t Value = CE->getValue();
857 return Value > 0 && Value < 32;
858 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000859 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000860 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
862 if (!CE) return false;
863 int64_t Value = CE->getValue();
864 return Value > 0 && Value < 17;
865 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000866 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000867 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +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 Grosbachc14871c2011-11-10 19:18:01 +0000873 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000874 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value < 33;
879 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000880 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value >= 0 && Value < 65536;
886 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000887 bool isImm256_65535Expr() const {
888 if (!isImm()) return false;
889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 // If it's not a constant expression, it'll generate a fixup and be
891 // handled later.
892 if (!CE) return true;
893 int64_t Value = CE->getValue();
894 return Value >= 256 && Value < 65536;
895 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000896 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000897 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 // If it's not a constant expression, it'll generate a fixup and be
900 // handled later.
901 if (!CE) return true;
902 int64_t Value = CE->getValue();
903 return Value >= 0 && Value < 65536;
904 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000905 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000906 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Value = CE->getValue();
910 return Value >= 0 && Value <= 0xffffff;
911 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000912 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000913 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Value = CE->getValue();
917 return Value > 0 && Value < 33;
918 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000919 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000920 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
922 if (!CE) return false;
923 int64_t Value = CE->getValue();
924 return Value >= 0 && Value < 32;
925 }
926 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000927 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
929 if (!CE) return false;
930 int64_t Value = CE->getValue();
931 return Value > 0 && Value <= 32;
932 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000933 bool isAdrLabel() const {
934 // If we have an immediate that's not a constant, treat it as a label
935 // reference needing a fixup. If it is a constant, but it can't fit
936 // into shift immediate encoding, we reject it.
937 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
938 else return (isARMSOImm() || isARMSOImmNeg());
939 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000940 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000941 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return ARM_AM::getSOImmVal(Value) != -1;
946 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000947 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000948 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
950 if (!CE) return false;
951 int64_t Value = CE->getValue();
952 return ARM_AM::getSOImmVal(~Value) != -1;
953 }
Jim Grosbach30506252011-12-08 00:31:07 +0000954 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000955 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000959 // Only use this when not representable as a plain so_imm.
960 return ARM_AM::getSOImmVal(Value) == -1 &&
961 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000962 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000963 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000964 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
966 if (!CE) return false;
967 int64_t Value = CE->getValue();
968 return ARM_AM::getT2SOImmVal(Value) != -1;
969 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000970 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000971 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000972 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
973 if (!CE) return false;
974 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000975 return ARM_AM::getT2SOImmVal(Value) == -1 &&
976 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000977 }
Jim Grosbach30506252011-12-08 00:31:07 +0000978 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000979 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000980 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
981 if (!CE) return false;
982 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000983 // Only use this when not representable as a plain so_imm.
984 return ARM_AM::getT2SOImmVal(Value) == -1 &&
985 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000986 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000987 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000988 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000989 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
990 if (!CE) return false;
991 int64_t Value = CE->getValue();
992 return Value == 1 || Value == 0;
993 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000994 bool isReg() const { return Kind == k_Register; }
995 bool isRegList() const { return Kind == k_RegisterList; }
996 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
997 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
998 bool isToken() const { return Kind == k_Token; }
999 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001000 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +00001001 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001002 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1003 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1004 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1005 bool isRotImm() const { return Kind == k_RotateImmediate; }
1006 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1007 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001008 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001009 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001010 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001011 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +00001012 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001013 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001014 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001015 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1016 (alignOK || Memory.Alignment == 0);
1017 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001018 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001019 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001020 return false;
1021 // Base register must be PC.
1022 if (Memory.BaseRegNum != ARM::PC)
1023 return false;
1024 // Immediate offset in range [-4095, 4095].
1025 if (!Memory.OffsetImm) return true;
1026 int64_t Val = Memory.OffsetImm->getValue();
1027 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1028 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001029 bool isAlignedMemory() const {
1030 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001031 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001032 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001033 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001034 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001035 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001036 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001037 if (!Memory.OffsetImm) return true;
1038 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001039 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001040 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001041 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001042 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001043 // Immediate offset in range [-4095, 4095].
1044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1045 if (!CE) return false;
1046 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001047 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001048 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001049 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001050 // If we have an immediate that's not a constant, treat it as a label
1051 // reference needing a fixup. If it is a constant, it's something else
1052 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001053 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001054 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001055 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001056 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001057 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001058 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001059 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001060 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001061 if (!Memory.OffsetImm) return true;
1062 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001063 // The #-0 offset is encoded as INT32_MIN, and we have to check
1064 // for this too.
1065 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001066 }
1067 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001068 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001069 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001070 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001071 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1072 // Immediate offset in range [-255, 255].
1073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1074 if (!CE) return false;
1075 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001076 // Special case, #-0 is INT32_MIN.
1077 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001078 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001079 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001080 // If we have an immediate that's not a constant, treat it as a label
1081 // reference needing a fixup. If it is a constant, it's something else
1082 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001083 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001084 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001085 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001086 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001087 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001088 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001089 if (!Memory.OffsetImm) return true;
1090 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001091 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001092 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001093 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001094 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001095 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001096 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001097 return false;
1098 return true;
1099 }
1100 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001101 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001102 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1103 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001104 return false;
1105 return true;
1106 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001107 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001108 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001109 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001110 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001111 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001112 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001113 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001114 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001115 return false;
1116 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001117 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001118 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001119 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001120 return false;
1121 return true;
1122 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001123 bool isMemThumbRR() const {
1124 // Thumb reg+reg addressing is simple. Just two registers, a base and
1125 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001126 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001127 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001128 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001129 return isARMLowRegister(Memory.BaseRegNum) &&
1130 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001131 }
1132 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001133 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001134 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001135 return false;
1136 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001137 if (!Memory.OffsetImm) return true;
1138 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001139 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1140 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001141 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001142 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001143 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001144 return false;
1145 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001146 if (!Memory.OffsetImm) return true;
1147 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001148 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1149 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001150 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001151 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001152 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001153 return false;
1154 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001155 if (!Memory.OffsetImm) return true;
1156 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001157 return Val >= 0 && Val <= 31;
1158 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001159 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001160 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001161 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001162 return false;
1163 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001164 if (!Memory.OffsetImm) return true;
1165 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001166 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001167 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001168 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001169 // If we have an immediate that's not a constant, treat it as a label
1170 // reference needing a fixup. If it is a constant, it's something else
1171 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001172 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001173 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001174 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001175 return false;
1176 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001177 if (!Memory.OffsetImm) return true;
1178 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001179 // Special case, #-0 is INT32_MIN.
1180 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001181 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001182 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001183 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001184 return false;
1185 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001186 if (!Memory.OffsetImm) return true;
1187 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001188 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1189 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001190 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001191 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001192 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001193 // Base reg of PC isn't allowed for these encodings.
1194 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001195 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001196 if (!Memory.OffsetImm) return true;
1197 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001198 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001199 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001200 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001201 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001202 return false;
1203 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001204 if (!Memory.OffsetImm) return true;
1205 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001206 return Val >= 0 && Val < 256;
1207 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001208 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001209 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001210 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001211 // Base reg of PC isn't allowed for these encodings.
1212 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001213 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001214 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001215 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001216 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001217 }
1218 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001219 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001220 return false;
1221 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001222 if (!Memory.OffsetImm) return true;
1223 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001224 return (Val >= 0 && Val < 4096);
1225 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001226 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001227 // If we have an immediate that's not a constant, treat it as a label
1228 // reference needing a fixup. If it is a constant, it's something else
1229 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001230 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001231 return true;
1232
Chad Rosier41099832012-09-11 23:02:35 +00001233 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001234 return false;
1235 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001236 if (!Memory.OffsetImm) return true;
1237 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001238 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001239 }
1240 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001241 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001242 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1243 if (!CE) return false;
1244 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001245 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001246 }
Jim Grosbach93981412011-10-11 21:55:36 +00001247 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001248 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001249 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1250 if (!CE) return false;
1251 int64_t Val = CE->getValue();
1252 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1253 (Val == INT32_MIN);
1254 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001255
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001256 bool isMSRMask() const { return Kind == k_MSRMask; }
1257 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001258
Jim Grosbach741cd732011-10-17 22:26:03 +00001259 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001260 bool isSingleSpacedVectorList() const {
1261 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1262 }
1263 bool isDoubleSpacedVectorList() const {
1264 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1265 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001266 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001267 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001268 return VectorList.Count == 1;
1269 }
1270
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001271 bool isVecListDPair() const {
1272 if (!isSingleSpacedVectorList()) return false;
1273 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1274 .contains(VectorList.RegNum));
1275 }
1276
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001277 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001278 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001279 return VectorList.Count == 3;
1280 }
1281
Jim Grosbach846bcff2011-10-21 20:35:01 +00001282 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001283 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001284 return VectorList.Count == 4;
1285 }
1286
Jim Grosbache5307f92012-03-05 21:43:40 +00001287 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001288 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001289 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1290 .contains(VectorList.RegNum));
1291 }
1292
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001293 bool isVecListThreeQ() const {
1294 if (!isDoubleSpacedVectorList()) return false;
1295 return VectorList.Count == 3;
1296 }
1297
Jim Grosbach1e946a42012-01-24 00:43:12 +00001298 bool isVecListFourQ() const {
1299 if (!isDoubleSpacedVectorList()) return false;
1300 return VectorList.Count == 4;
1301 }
1302
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001303 bool isSingleSpacedVectorAllLanes() const {
1304 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1305 }
1306 bool isDoubleSpacedVectorAllLanes() const {
1307 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1308 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001309 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001310 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001311 return VectorList.Count == 1;
1312 }
1313
Jim Grosbach13a292c2012-03-06 22:01:44 +00001314 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001315 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001316 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1317 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001318 }
1319
Jim Grosbached428bc2012-03-06 23:10:38 +00001320 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001321 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001322 return VectorList.Count == 2;
1323 }
1324
Jim Grosbachb78403c2012-01-24 23:47:04 +00001325 bool isVecListThreeDAllLanes() const {
1326 if (!isSingleSpacedVectorAllLanes()) return false;
1327 return VectorList.Count == 3;
1328 }
1329
1330 bool isVecListThreeQAllLanes() const {
1331 if (!isDoubleSpacedVectorAllLanes()) return false;
1332 return VectorList.Count == 3;
1333 }
1334
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001335 bool isVecListFourDAllLanes() const {
1336 if (!isSingleSpacedVectorAllLanes()) return false;
1337 return VectorList.Count == 4;
1338 }
1339
1340 bool isVecListFourQAllLanes() const {
1341 if (!isDoubleSpacedVectorAllLanes()) return false;
1342 return VectorList.Count == 4;
1343 }
1344
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001345 bool isSingleSpacedVectorIndexed() const {
1346 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1347 }
1348 bool isDoubleSpacedVectorIndexed() const {
1349 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1350 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001351 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001352 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001353 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1354 }
1355
Jim Grosbachda511042011-12-14 23:35:06 +00001356 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001357 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001358 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1359 }
1360
1361 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001362 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001363 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1364 }
1365
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001366 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001367 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001368 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1369 }
1370
Jim Grosbachda511042011-12-14 23:35:06 +00001371 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1374 }
1375
1376 bool isVecListTwoQWordIndexed() const {
1377 if (!isDoubleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1379 }
1380
1381 bool isVecListTwoQHWordIndexed() const {
1382 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001383 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1384 }
1385
1386 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001387 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001388 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1389 }
1390
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001391 bool isVecListThreeDByteIndexed() const {
1392 if (!isSingleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1394 }
1395
1396 bool isVecListThreeDHWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1399 }
1400
1401 bool isVecListThreeQWordIndexed() const {
1402 if (!isDoubleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1404 }
1405
1406 bool isVecListThreeQHWordIndexed() const {
1407 if (!isDoubleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1409 }
1410
1411 bool isVecListThreeDWordIndexed() const {
1412 if (!isSingleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1414 }
1415
Jim Grosbach14952a02012-01-24 18:37:25 +00001416 bool isVecListFourDByteIndexed() const {
1417 if (!isSingleSpacedVectorIndexed()) return false;
1418 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1419 }
1420
1421 bool isVecListFourDHWordIndexed() const {
1422 if (!isSingleSpacedVectorIndexed()) return false;
1423 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1424 }
1425
1426 bool isVecListFourQWordIndexed() const {
1427 if (!isDoubleSpacedVectorIndexed()) return false;
1428 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1429 }
1430
1431 bool isVecListFourQHWordIndexed() const {
1432 if (!isDoubleSpacedVectorIndexed()) return false;
1433 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1434 }
1435
1436 bool isVecListFourDWordIndexed() const {
1437 if (!isSingleSpacedVectorIndexed()) return false;
1438 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1439 }
1440
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001441 bool isVectorIndex8() const {
1442 if (Kind != k_VectorIndex) return false;
1443 return VectorIndex.Val < 8;
1444 }
1445 bool isVectorIndex16() const {
1446 if (Kind != k_VectorIndex) return false;
1447 return VectorIndex.Val < 4;
1448 }
1449 bool isVectorIndex32() const {
1450 if (Kind != k_VectorIndex) return false;
1451 return VectorIndex.Val < 2;
1452 }
1453
Jim Grosbach741cd732011-10-17 22:26:03 +00001454 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001455 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001456 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1457 // Must be a constant.
1458 if (!CE) return false;
1459 int64_t Value = CE->getValue();
1460 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1461 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001462 return Value >= 0 && Value < 256;
1463 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001464
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001465 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001466 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001467 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1468 // Must be a constant.
1469 if (!CE) return false;
1470 int64_t Value = CE->getValue();
1471 // i16 value in the range [0,255] or [0x0100, 0xff00]
1472 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1473 }
1474
Jim Grosbach8211c052011-10-18 00:22:00 +00001475 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001476 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1478 // Must be a constant.
1479 if (!CE) return false;
1480 int64_t Value = CE->getValue();
1481 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1482 return (Value >= 0 && Value < 256) ||
1483 (Value >= 0x0100 && Value <= 0xff00) ||
1484 (Value >= 0x010000 && Value <= 0xff0000) ||
1485 (Value >= 0x01000000 && Value <= 0xff000000);
1486 }
1487
1488 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001489 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 // Must be a constant.
1492 if (!CE) return false;
1493 int64_t Value = CE->getValue();
1494 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1495 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1496 return (Value >= 0 && Value < 256) ||
1497 (Value >= 0x0100 && Value <= 0xff00) ||
1498 (Value >= 0x010000 && Value <= 0xff0000) ||
1499 (Value >= 0x01000000 && Value <= 0xff000000) ||
1500 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1501 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1502 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001503 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001504 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001505 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1506 // Must be a constant.
1507 if (!CE) return false;
1508 int64_t Value = ~CE->getValue();
1509 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1510 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1511 return (Value >= 0 && Value < 256) ||
1512 (Value >= 0x0100 && Value <= 0xff00) ||
1513 (Value >= 0x010000 && Value <= 0xff0000) ||
1514 (Value >= 0x01000000 && Value <= 0xff000000) ||
1515 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1516 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1517 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001518
Jim Grosbache4454e02011-10-18 16:18:11 +00001519 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001520 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001521 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1522 // Must be a constant.
1523 if (!CE) return false;
1524 uint64_t Value = CE->getValue();
1525 // i64 value with each byte being either 0 or 0xff.
1526 for (unsigned i = 0; i < 8; ++i)
1527 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1528 return true;
1529 }
1530
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001531 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001532 // Add as immediates when possible. Null MCExpr = 0.
1533 if (Expr == 0)
1534 Inst.addOperand(MCOperand::CreateImm(0));
1535 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001536 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1537 else
1538 Inst.addOperand(MCOperand::CreateExpr(Expr));
1539 }
1540
Daniel Dunbard8042b72010-08-11 06:36:53 +00001541 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001542 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001543 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001544 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1545 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001546 }
1547
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001548 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1551 }
1552
Jim Grosbach48399582011-10-12 17:34:41 +00001553 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1556 }
1557
1558 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1561 }
1562
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001563 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1564 assert(N == 1 && "Invalid number of operands!");
1565 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1566 }
1567
1568 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1569 assert(N == 1 && "Invalid number of operands!");
1570 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1571 }
1572
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001573 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1574 assert(N == 1 && "Invalid number of operands!");
1575 Inst.addOperand(MCOperand::CreateReg(getReg()));
1576 }
1577
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001578 void addRegOperands(MCInst &Inst, unsigned N) const {
1579 assert(N == 1 && "Invalid number of operands!");
1580 Inst.addOperand(MCOperand::CreateReg(getReg()));
1581 }
1582
Jim Grosbachac798e12011-07-25 20:49:51 +00001583 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001584 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001585 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001586 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001587 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1588 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001589 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001590 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001591 }
1592
Jim Grosbachac798e12011-07-25 20:49:51 +00001593 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001594 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001595 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001596 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001597 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001598 // Shift of #32 is encoded as 0 where permitted
1599 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001600 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001601 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001602 }
1603
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001604 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001605 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001606 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1607 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001608 }
1609
Bill Wendling8d2aa032010-11-08 23:49:57 +00001610 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001611 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001612 const SmallVectorImpl<unsigned> &RegList = getRegList();
1613 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001614 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1615 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001616 }
1617
Bill Wendling9898ac92010-11-17 04:32:08 +00001618 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1619 addRegListOperands(Inst, N);
1620 }
1621
1622 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1623 addRegListOperands(Inst, N);
1624 }
1625
Jim Grosbach833b9d32011-07-27 20:15:40 +00001626 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1629 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1630 }
1631
Jim Grosbach864b6092011-07-28 21:34:26 +00001632 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 // Munge the lsb/width into a bitfield mask.
1635 unsigned lsb = Bitfield.LSB;
1636 unsigned width = Bitfield.Width;
1637 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1638 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1639 (32 - (lsb + width)));
1640 Inst.addOperand(MCOperand::CreateImm(Mask));
1641 }
1642
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001643 void addImmOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 addExpr(Inst, getImm());
1646 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001647
Jim Grosbachea231912011-12-22 22:19:05 +00001648 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1651 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1652 }
1653
1654 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1655 assert(N == 1 && "Invalid number of operands!");
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1658 }
1659
Jim Grosbache7fbce72011-10-03 23:38:36 +00001660 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1664 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001665 }
1666
Jim Grosbach7db8d692011-09-08 22:07:06 +00001667 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1668 assert(N == 1 && "Invalid number of operands!");
1669 // FIXME: We really want to scale the value here, but the LDRD/STRD
1670 // instruction don't encode operands that way yet.
1671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1672 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1673 }
1674
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001675 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1676 assert(N == 1 && "Invalid number of operands!");
1677 // The immediate is scaled by four in the encoding and is stored
1678 // in the MCInst as such. Lop off the low two bits here.
1679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1680 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1681 }
1682
Jim Grosbach930f2f62012-04-05 20:57:13 +00001683 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1684 assert(N == 1 && "Invalid number of operands!");
1685 // The immediate is scaled by four in the encoding and is stored
1686 // in the MCInst as such. Lop off the low two bits here.
1687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1688 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1689 }
1690
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001691 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // The immediate is scaled by four in the encoding and is stored
1694 // in the MCInst as such. Lop off the low two bits here.
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1697 }
1698
Jim Grosbach475c6db2011-07-25 23:09:14 +00001699 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1700 assert(N == 1 && "Invalid number of operands!");
1701 // The constant encodes as the immediate-1, and we store in the instruction
1702 // the bits as encoded, so subtract off one here.
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1705 }
1706
Jim Grosbach801e0a32011-07-22 23:16:18 +00001707 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 // The constant encodes as the immediate-1, and we store in the instruction
1710 // the bits as encoded, so subtract off one here.
1711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1712 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1713 }
1714
Jim Grosbach46dd4132011-08-17 21:51:27 +00001715 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1716 assert(N == 1 && "Invalid number of operands!");
1717 // The constant encodes as the immediate, except for 32, which encodes as
1718 // zero.
1719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1720 unsigned Imm = CE->getValue();
1721 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1722 }
1723
Jim Grosbach27c1e252011-07-21 17:23:04 +00001724 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1725 assert(N == 1 && "Invalid number of operands!");
1726 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1727 // the instruction as well.
1728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 int Val = CE->getValue();
1730 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1731 }
1732
Jim Grosbachb009a872011-10-28 22:36:30 +00001733 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1734 assert(N == 1 && "Invalid number of operands!");
1735 // The operand is actually a t2_so_imm, but we have its bitwise
1736 // negation in the assembly source, so twiddle it here.
1737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1738 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1739 }
1740
Jim Grosbach30506252011-12-08 00:31:07 +00001741 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1742 assert(N == 1 && "Invalid number of operands!");
1743 // The operand is actually a t2_so_imm, but we have its
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 Grosbach930f2f62012-04-05 20:57:13 +00001749 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 // The operand is actually an imm0_4095, 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
Mihai Popad36cbaa2013-07-03 09:21:44 +00001757 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1758 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1759 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1760 return;
1761 }
1762
1763 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1764 assert(SR && "Unknown value type!");
1765 Inst.addOperand(MCOperand::CreateExpr(SR));
1766 }
1767
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001768 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1769 assert(N == 1 && "Invalid number of operands!");
1770 if (isImm()) {
1771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1772 if (CE) {
1773 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1774 return;
1775 }
1776
1777 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1778 assert(SR && "Unknown value type!");
1779 Inst.addOperand(MCOperand::CreateExpr(SR));
1780 return;
1781 }
1782
1783 assert(isMem() && "Unknown value type!");
1784 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1785 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1786 }
1787
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001788 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 1 && "Invalid number of operands!");
1790 // The operand is actually a so_imm, but we have its bitwise
1791 // negation in the assembly source, so twiddle it here.
1792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1793 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1794 }
1795
Jim Grosbach30506252011-12-08 00:31:07 +00001796 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 1 && "Invalid number of operands!");
1798 // The operand is actually a so_imm, but we have its
1799 // negation in the assembly source, so twiddle it here.
1800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1801 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1802 }
1803
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001804 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1805 assert(N == 1 && "Invalid number of operands!");
1806 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1807 }
1808
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001809 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1810 assert(N == 1 && "Invalid number of operands!");
1811 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1812 }
1813
Jim Grosbachd3595712011-08-03 23:50:40 +00001814 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1815 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001816 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001817 }
1818
Jim Grosbach94298a92012-01-18 22:46:46 +00001819 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1820 assert(N == 1 && "Invalid number of operands!");
1821 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001822 Inst.addOperand(MCOperand::CreateImm(Imm));
1823 }
1824
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001825 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 1 && "Invalid number of operands!");
1827 assert(isImm() && "Not an immediate!");
1828
1829 // If we have an immediate that's not a constant, treat it as a label
1830 // reference needing a fixup.
1831 if (!isa<MCConstantExpr>(getImm())) {
1832 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1833 return;
1834 }
1835
1836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1837 int Val = CE->getValue();
1838 Inst.addOperand(MCOperand::CreateImm(Val));
1839 }
1840
Jim Grosbacha95ec992011-10-11 17:29:55 +00001841 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1842 assert(N == 2 && "Invalid number of operands!");
1843 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1844 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1845 }
1846
Jim Grosbachd3595712011-08-03 23:50:40 +00001847 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1848 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001849 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1850 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001851 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1852 // Special case for #-0
1853 if (Val == INT32_MIN) Val = 0;
1854 if (Val < 0) Val = -Val;
1855 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1856 } else {
1857 // For register offset, we encode the shift type and negation flag
1858 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001859 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1860 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001861 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001862 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1863 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001864 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001865 }
1866
Jim Grosbachcd17c122011-08-04 23:01:30 +00001867 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1868 assert(N == 2 && "Invalid number of operands!");
1869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1870 assert(CE && "non-constant AM2OffsetImm operand!");
1871 int32_t Val = CE->getValue();
1872 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1873 // Special case for #-0
1874 if (Val == INT32_MIN) Val = 0;
1875 if (Val < 0) Val = -Val;
1876 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1877 Inst.addOperand(MCOperand::CreateReg(0));
1878 Inst.addOperand(MCOperand::CreateImm(Val));
1879 }
1880
Jim Grosbach5b96b802011-08-10 20:29:19 +00001881 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1882 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001883 // If we have an immediate that's not a constant, treat it as a label
1884 // reference needing a fixup. If it is a constant, it's something else
1885 // and we reject it.
1886 if (isImm()) {
1887 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1888 Inst.addOperand(MCOperand::CreateReg(0));
1889 Inst.addOperand(MCOperand::CreateImm(0));
1890 return;
1891 }
1892
Jim Grosbach871dff72011-10-11 15:59:20 +00001893 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1894 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001895 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1896 // Special case for #-0
1897 if (Val == INT32_MIN) Val = 0;
1898 if (Val < 0) Val = -Val;
1899 Val = ARM_AM::getAM3Opc(AddSub, Val);
1900 } else {
1901 // For register offset, we encode the shift type and negation flag
1902 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001903 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001904 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001905 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1906 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001907 Inst.addOperand(MCOperand::CreateImm(Val));
1908 }
1909
1910 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1911 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001912 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001913 int32_t Val =
1914 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1915 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1916 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001917 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001918 }
1919
1920 // Constant offset.
1921 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1922 int32_t Val = CE->getValue();
1923 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1924 // Special case for #-0
1925 if (Val == INT32_MIN) Val = 0;
1926 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001927 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001928 Inst.addOperand(MCOperand::CreateReg(0));
1929 Inst.addOperand(MCOperand::CreateImm(Val));
1930 }
1931
Jim Grosbachd3595712011-08-03 23:50:40 +00001932 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1933 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001934 // If we have an immediate that's not a constant, treat it as a label
1935 // reference needing a fixup. If it is a constant, it's something else
1936 // and we reject it.
1937 if (isImm()) {
1938 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1939 Inst.addOperand(MCOperand::CreateImm(0));
1940 return;
1941 }
1942
Jim Grosbachd3595712011-08-03 23:50:40 +00001943 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001944 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001945 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1946 // Special case for #-0
1947 if (Val == INT32_MIN) Val = 0;
1948 if (Val < 0) Val = -Val;
1949 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001950 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001951 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001952 }
1953
Jim Grosbach7db8d692011-09-08 22:07:06 +00001954 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1955 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001956 // If we have an immediate that's not a constant, treat it as a label
1957 // reference needing a fixup. If it is a constant, it's something else
1958 // and we reject it.
1959 if (isImm()) {
1960 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1961 Inst.addOperand(MCOperand::CreateImm(0));
1962 return;
1963 }
1964
Jim Grosbach871dff72011-10-11 15:59:20 +00001965 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1966 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001967 Inst.addOperand(MCOperand::CreateImm(Val));
1968 }
1969
Jim Grosbacha05627e2011-09-09 18:37:27 +00001970 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1971 assert(N == 2 && "Invalid number of operands!");
1972 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001973 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1974 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001975 Inst.addOperand(MCOperand::CreateImm(Val));
1976 }
1977
Jim Grosbachd3595712011-08-03 23:50:40 +00001978 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001980 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1981 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001982 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001983 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001984
Jim Grosbach2392c532011-09-07 23:39:14 +00001985 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1986 addMemImm8OffsetOperands(Inst, N);
1987 }
1988
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001989 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001990 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001991 }
1992
1993 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
1995 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001996 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001997 addExpr(Inst, getImm());
1998 Inst.addOperand(MCOperand::CreateImm(0));
1999 return;
2000 }
2001
2002 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2004 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002005 Inst.addOperand(MCOperand::CreateImm(Val));
2006 }
2007
Jim Grosbachd3595712011-08-03 23:50:40 +00002008 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002010 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002011 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002012 addExpr(Inst, getImm());
2013 Inst.addOperand(MCOperand::CreateImm(0));
2014 return;
2015 }
2016
2017 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002018 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2019 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002020 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002021 }
Bill Wendling811c9362010-11-30 07:44:32 +00002022
Jim Grosbach05541f42011-09-19 22:21:13 +00002023 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2024 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2026 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002027 }
2028
2029 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2032 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002033 }
2034
Jim Grosbachd3595712011-08-03 23:50:40 +00002035 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002037 unsigned Val =
2038 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2039 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002040 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2041 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002042 Inst.addOperand(MCOperand::CreateImm(Val));
2043 }
2044
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002045 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2046 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002047 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2048 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2049 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002050 }
2051
Jim Grosbachd3595712011-08-03 23:50:40 +00002052 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002054 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2055 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002056 }
2057
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002058 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2059 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002060 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2061 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002062 Inst.addOperand(MCOperand::CreateImm(Val));
2063 }
2064
Jim Grosbach26d35872011-08-19 18:55:51 +00002065 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2066 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002067 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2068 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002069 Inst.addOperand(MCOperand::CreateImm(Val));
2070 }
2071
Jim Grosbacha32c7532011-08-19 18:49:59 +00002072 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002074 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2075 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002076 Inst.addOperand(MCOperand::CreateImm(Val));
2077 }
2078
Jim Grosbach23983d62011-08-19 18:13:48 +00002079 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2080 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002081 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2082 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002083 Inst.addOperand(MCOperand::CreateImm(Val));
2084 }
2085
Jim Grosbachd3595712011-08-03 23:50:40 +00002086 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2087 assert(N == 1 && "Invalid number of operands!");
2088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2089 assert(CE && "non-constant post-idx-imm8 operand!");
2090 int Imm = CE->getValue();
2091 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002092 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002093 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2094 Inst.addOperand(MCOperand::CreateImm(Imm));
2095 }
2096
Jim Grosbach93981412011-10-11 21:55:36 +00002097 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2098 assert(N == 1 && "Invalid number of operands!");
2099 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2100 assert(CE && "non-constant post-idx-imm8s4 operand!");
2101 int Imm = CE->getValue();
2102 bool isAdd = Imm >= 0;
2103 if (Imm == INT32_MIN) Imm = 0;
2104 // Immediate is scaled by 4.
2105 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2106 Inst.addOperand(MCOperand::CreateImm(Imm));
2107 }
2108
Jim Grosbachd3595712011-08-03 23:50:40 +00002109 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2110 assert(N == 2 && "Invalid number of operands!");
2111 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002112 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2113 }
2114
2115 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2116 assert(N == 2 && "Invalid number of operands!");
2117 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2118 // The sign, shift type, and shift amount are encoded in a single operand
2119 // using the AM2 encoding helpers.
2120 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2121 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2122 PostIdxReg.ShiftTy);
2123 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002124 }
2125
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002126 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 1 && "Invalid number of operands!");
2128 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2129 }
2130
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002131 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2132 assert(N == 1 && "Invalid number of operands!");
2133 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2134 }
2135
Jim Grosbach182b6a02011-11-29 23:51:09 +00002136 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002137 assert(N == 1 && "Invalid number of operands!");
2138 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2139 }
2140
Jim Grosbach04945c42011-12-02 00:35:16 +00002141 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2142 assert(N == 2 && "Invalid number of operands!");
2143 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2144 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2145 }
2146
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002147 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 1 && "Invalid number of operands!");
2149 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2150 }
2151
2152 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2153 assert(N == 1 && "Invalid number of operands!");
2154 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2155 }
2156
2157 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2160 }
2161
Jim Grosbach741cd732011-10-17 22:26:03 +00002162 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2163 assert(N == 1 && "Invalid number of operands!");
2164 // The immediate encodes the type of constant as well as the value.
2165 // Mask in that this is an i8 splat.
2166 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2167 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2168 }
2169
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002170 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2171 assert(N == 1 && "Invalid number of operands!");
2172 // The immediate encodes the type of constant as well as the value.
2173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2174 unsigned Value = CE->getValue();
2175 if (Value >= 256)
2176 Value = (Value >> 8) | 0xa00;
2177 else
2178 Value |= 0x800;
2179 Inst.addOperand(MCOperand::CreateImm(Value));
2180 }
2181
Jim Grosbach8211c052011-10-18 00:22:00 +00002182 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2183 assert(N == 1 && "Invalid number of operands!");
2184 // The immediate encodes the type of constant as well as the value.
2185 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2186 unsigned Value = CE->getValue();
2187 if (Value >= 256 && Value <= 0xff00)
2188 Value = (Value >> 8) | 0x200;
2189 else if (Value > 0xffff && Value <= 0xff0000)
2190 Value = (Value >> 16) | 0x400;
2191 else if (Value > 0xffffff)
2192 Value = (Value >> 24) | 0x600;
2193 Inst.addOperand(MCOperand::CreateImm(Value));
2194 }
2195
2196 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2197 assert(N == 1 && "Invalid number of operands!");
2198 // The immediate encodes the type of constant as well as the value.
2199 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2200 unsigned Value = CE->getValue();
2201 if (Value >= 256 && Value <= 0xffff)
2202 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2203 else if (Value > 0xffff && Value <= 0xffffff)
2204 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2205 else if (Value > 0xffffff)
2206 Value = (Value >> 24) | 0x600;
2207 Inst.addOperand(MCOperand::CreateImm(Value));
2208 }
2209
Jim Grosbach045b6c72011-12-19 23:51:07 +00002210 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2211 assert(N == 1 && "Invalid number of operands!");
2212 // The immediate encodes the type of constant as well as the value.
2213 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2214 unsigned Value = ~CE->getValue();
2215 if (Value >= 256 && Value <= 0xffff)
2216 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2217 else if (Value > 0xffff && Value <= 0xffffff)
2218 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2219 else if (Value > 0xffffff)
2220 Value = (Value >> 24) | 0x600;
2221 Inst.addOperand(MCOperand::CreateImm(Value));
2222 }
2223
Jim Grosbache4454e02011-10-18 16:18:11 +00002224 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2225 assert(N == 1 && "Invalid number of operands!");
2226 // The immediate encodes the type of constant as well as the value.
2227 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2228 uint64_t Value = CE->getValue();
2229 unsigned Imm = 0;
2230 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2231 Imm |= (Value & 1) << i;
2232 }
2233 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2234 }
2235
Jim Grosbach602aa902011-07-13 15:34:57 +00002236 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002237
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002238 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002239 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002240 Op->ITMask.Mask = Mask;
2241 Op->StartLoc = S;
2242 Op->EndLoc = S;
2243 return Op;
2244 }
2245
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002246 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002247 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002248 Op->CC.Val = CC;
2249 Op->StartLoc = S;
2250 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002251 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002252 }
2253
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002254 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002255 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002256 Op->Cop.Val = CopVal;
2257 Op->StartLoc = S;
2258 Op->EndLoc = S;
2259 return Op;
2260 }
2261
2262 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002263 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002264 Op->Cop.Val = CopVal;
2265 Op->StartLoc = S;
2266 Op->EndLoc = S;
2267 return Op;
2268 }
2269
Jim Grosbach48399582011-10-12 17:34:41 +00002270 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2271 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2272 Op->Cop.Val = Val;
2273 Op->StartLoc = S;
2274 Op->EndLoc = E;
2275 return Op;
2276 }
2277
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002278 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002279 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002280 Op->Reg.RegNum = RegNum;
2281 Op->StartLoc = S;
2282 Op->EndLoc = S;
2283 return Op;
2284 }
2285
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002286 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002287 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002288 Op->Tok.Data = Str.data();
2289 Op->Tok.Length = Str.size();
2290 Op->StartLoc = S;
2291 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002292 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002293 }
2294
Bill Wendling2063b842010-11-18 23:43:05 +00002295 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002296 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002297 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002298 Op->StartLoc = S;
2299 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002300 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002301 }
2302
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002303 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2304 unsigned SrcReg,
2305 unsigned ShiftReg,
2306 unsigned ShiftImm,
2307 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002308 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002309 Op->RegShiftedReg.ShiftTy = ShTy;
2310 Op->RegShiftedReg.SrcReg = SrcReg;
2311 Op->RegShiftedReg.ShiftReg = ShiftReg;
2312 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002313 Op->StartLoc = S;
2314 Op->EndLoc = E;
2315 return Op;
2316 }
2317
Owen Andersonb595ed02011-07-21 18:54:16 +00002318 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2319 unsigned SrcReg,
2320 unsigned ShiftImm,
2321 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002322 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002323 Op->RegShiftedImm.ShiftTy = ShTy;
2324 Op->RegShiftedImm.SrcReg = SrcReg;
2325 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002326 Op->StartLoc = S;
2327 Op->EndLoc = E;
2328 return Op;
2329 }
2330
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002331 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002332 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002333 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002334 Op->ShifterImm.isASR = isASR;
2335 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002336 Op->StartLoc = S;
2337 Op->EndLoc = E;
2338 return Op;
2339 }
2340
Jim Grosbach833b9d32011-07-27 20:15:40 +00002341 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002342 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002343 Op->RotImm.Imm = Imm;
2344 Op->StartLoc = S;
2345 Op->EndLoc = E;
2346 return Op;
2347 }
2348
Jim Grosbach864b6092011-07-28 21:34:26 +00002349 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2350 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002351 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002352 Op->Bitfield.LSB = LSB;
2353 Op->Bitfield.Width = Width;
2354 Op->StartLoc = S;
2355 Op->EndLoc = E;
2356 return Op;
2357 }
2358
Bill Wendling2cae3272010-11-09 22:44:22 +00002359 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002360 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002361 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002362 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002363 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002364
Chad Rosierfa705ee2013-07-01 20:49:23 +00002365 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002366 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002367 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002368 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002369 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002370
Chad Rosierfa705ee2013-07-01 20:49:23 +00002371 // Sort based on the register encoding values.
2372 array_pod_sort(Regs.begin(), Regs.end());
2373
Bill Wendling9898ac92010-11-17 04:32:08 +00002374 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002375 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002376 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002377 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002378 Op->StartLoc = StartLoc;
2379 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002380 return Op;
2381 }
2382
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002383 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002384 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002385 ARMOperand *Op = new ARMOperand(k_VectorList);
2386 Op->VectorList.RegNum = RegNum;
2387 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002388 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002389 Op->StartLoc = S;
2390 Op->EndLoc = E;
2391 return Op;
2392 }
2393
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002394 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002395 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002396 SMLoc S, SMLoc E) {
2397 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2398 Op->VectorList.RegNum = RegNum;
2399 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002400 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002401 Op->StartLoc = S;
2402 Op->EndLoc = E;
2403 return Op;
2404 }
2405
Jim Grosbach04945c42011-12-02 00:35:16 +00002406 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002407 unsigned Index,
2408 bool isDoubleSpaced,
2409 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002410 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2411 Op->VectorList.RegNum = RegNum;
2412 Op->VectorList.Count = Count;
2413 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002414 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002415 Op->StartLoc = S;
2416 Op->EndLoc = E;
2417 return Op;
2418 }
2419
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002420 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2421 MCContext &Ctx) {
2422 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2423 Op->VectorIndex.Val = Idx;
2424 Op->StartLoc = S;
2425 Op->EndLoc = E;
2426 return Op;
2427 }
2428
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002429 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002430 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002431 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002432 Op->StartLoc = S;
2433 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002434 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002435 }
2436
Jim Grosbachd3595712011-08-03 23:50:40 +00002437 static ARMOperand *CreateMem(unsigned BaseRegNum,
2438 const MCConstantExpr *OffsetImm,
2439 unsigned OffsetRegNum,
2440 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002441 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002442 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002443 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002444 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002445 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002446 Op->Memory.BaseRegNum = BaseRegNum;
2447 Op->Memory.OffsetImm = OffsetImm;
2448 Op->Memory.OffsetRegNum = OffsetRegNum;
2449 Op->Memory.ShiftType = ShiftType;
2450 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002451 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002452 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002453 Op->StartLoc = S;
2454 Op->EndLoc = E;
2455 return Op;
2456 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002457
Jim Grosbachc320c852011-08-05 21:28:30 +00002458 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2459 ARM_AM::ShiftOpc ShiftTy,
2460 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002461 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002462 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002463 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002464 Op->PostIdxReg.isAdd = isAdd;
2465 Op->PostIdxReg.ShiftTy = ShiftTy;
2466 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002467 Op->StartLoc = S;
2468 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002469 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002470 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002471
2472 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002473 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002474 Op->MBOpt.Val = Opt;
2475 Op->StartLoc = S;
2476 Op->EndLoc = S;
2477 return Op;
2478 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002479
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002480 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2481 SMLoc S) {
2482 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2483 Op->ISBOpt.Val = Opt;
2484 Op->StartLoc = S;
2485 Op->EndLoc = S;
2486 return Op;
2487 }
2488
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002489 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002490 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002491 Op->IFlags.Val = IFlags;
2492 Op->StartLoc = S;
2493 Op->EndLoc = S;
2494 return Op;
2495 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002496
2497 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002498 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002499 Op->MMask.Val = MMask;
2500 Op->StartLoc = S;
2501 Op->EndLoc = S;
2502 return Op;
2503 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002504};
2505
2506} // end anonymous namespace.
2507
Jim Grosbach602aa902011-07-13 15:34:57 +00002508void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002509 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002510 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002511 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002512 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002513 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002514 OS << "<ccout " << getReg() << ">";
2515 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002516 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002517 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002518 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2519 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2520 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002521 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2522 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2523 break;
2524 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002525 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002526 OS << "<coprocessor number: " << getCoproc() << ">";
2527 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002528 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002529 OS << "<coprocessor register: " << getCoproc() << ">";
2530 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002531 case k_CoprocOption:
2532 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2533 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002534 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002535 OS << "<mask: " << getMSRMask() << ">";
2536 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002537 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002538 getImm()->print(OS);
2539 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002540 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002541 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002542 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002543 case k_InstSyncBarrierOpt:
2544 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2545 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002546 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002547 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002548 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002549 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002550 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002551 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002552 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2553 << PostIdxReg.RegNum;
2554 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2555 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2556 << PostIdxReg.ShiftImm;
2557 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002558 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002559 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002560 OS << "<ARM_PROC::";
2561 unsigned IFlags = getProcIFlags();
2562 for (int i=2; i >= 0; --i)
2563 if (IFlags & (1 << i))
2564 OS << ARM_PROC::IFlagsToString(1 << i);
2565 OS << ">";
2566 break;
2567 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002568 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002569 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002570 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002571 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002572 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2573 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002574 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002575 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002576 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002577 << RegShiftedReg.SrcReg << " "
2578 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2579 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002581 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002582 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002583 << RegShiftedImm.SrcReg << " "
2584 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2585 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002586 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002587 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002588 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2589 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002590 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002591 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2592 << ", width: " << Bitfield.Width << ">";
2593 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002594 case k_RegisterList:
2595 case k_DPRRegisterList:
2596 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002597 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002598
Bill Wendlingbed94652010-11-09 23:28:44 +00002599 const SmallVectorImpl<unsigned> &RegList = getRegList();
2600 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002601 I = RegList.begin(), E = RegList.end(); I != E; ) {
2602 OS << *I;
2603 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002604 }
2605
2606 OS << ">";
2607 break;
2608 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002609 case k_VectorList:
2610 OS << "<vector_list " << VectorList.Count << " * "
2611 << VectorList.RegNum << ">";
2612 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002613 case k_VectorListAllLanes:
2614 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2615 << VectorList.RegNum << ">";
2616 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002617 case k_VectorListIndexed:
2618 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2619 << VectorList.Count << " * " << VectorList.RegNum << ">";
2620 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002621 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002622 OS << "'" << getToken() << "'";
2623 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002624 case k_VectorIndex:
2625 OS << "<vectorindex " << getVectorIndex() << ">";
2626 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002627 }
2628}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002629
2630/// @name Auto-generated Match Functions
2631/// {
2632
2633static unsigned MatchRegisterName(StringRef Name);
2634
2635/// }
2636
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002637bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2638 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002639 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002640 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002641 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002642
2643 return (RegNo == (unsigned)-1);
2644}
2645
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002646/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002647/// and if it is a register name the token is eaten and the register number is
2648/// returned. Otherwise return -1.
2649///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002650int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002651 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002652 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002653
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002654 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002655 unsigned RegNum = MatchRegisterName(lowerCase);
2656 if (!RegNum) {
2657 RegNum = StringSwitch<unsigned>(lowerCase)
2658 .Case("r13", ARM::SP)
2659 .Case("r14", ARM::LR)
2660 .Case("r15", ARM::PC)
2661 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002662 // Additional register name aliases for 'gas' compatibility.
2663 .Case("a1", ARM::R0)
2664 .Case("a2", ARM::R1)
2665 .Case("a3", ARM::R2)
2666 .Case("a4", ARM::R3)
2667 .Case("v1", ARM::R4)
2668 .Case("v2", ARM::R5)
2669 .Case("v3", ARM::R6)
2670 .Case("v4", ARM::R7)
2671 .Case("v5", ARM::R8)
2672 .Case("v6", ARM::R9)
2673 .Case("v7", ARM::R10)
2674 .Case("v8", ARM::R11)
2675 .Case("sb", ARM::R9)
2676 .Case("sl", ARM::R10)
2677 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002678 .Default(0);
2679 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002680 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002681 // Check for aliases registered via .req. Canonicalize to lower case.
2682 // That's more consistent since register names are case insensitive, and
2683 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2684 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002685 // If no match, return failure.
2686 if (Entry == RegisterReqs.end())
2687 return -1;
2688 Parser.Lex(); // Eat identifier token.
2689 return Entry->getValue();
2690 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002691
Chris Lattner44e5981c2010-10-30 04:09:10 +00002692 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002693
Chris Lattner44e5981c2010-10-30 04:09:10 +00002694 return RegNum;
2695}
Jim Grosbach99710a82010-11-01 16:44:21 +00002696
Jim Grosbachbb24c592011-07-13 18:49:30 +00002697// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2698// If a recoverable error occurs, return 1. If an irrecoverable error
2699// occurs, return -1. An irrecoverable error is one where tokens have been
2700// consumed in the process of trying to parse the shifter (i.e., when it is
2701// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002702int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002703 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2704 SMLoc S = Parser.getTok().getLoc();
2705 const AsmToken &Tok = Parser.getTok();
2706 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2707
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002708 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002709 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002710 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002711 .Case("lsl", ARM_AM::lsl)
2712 .Case("lsr", ARM_AM::lsr)
2713 .Case("asr", ARM_AM::asr)
2714 .Case("ror", ARM_AM::ror)
2715 .Case("rrx", ARM_AM::rrx)
2716 .Default(ARM_AM::no_shift);
2717
2718 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002719 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002720
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002721 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002722
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002723 // The source register for the shift has already been added to the
2724 // operand list, so we need to pop it off and combine it into the shifted
2725 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002726 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002727 if (!PrevOp->isReg())
2728 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2729 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002730
2731 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002732 int64_t Imm = 0;
2733 int ShiftReg = 0;
2734 if (ShiftTy == ARM_AM::rrx) {
2735 // RRX Doesn't have an explicit shift amount. The encoder expects
2736 // the shift register to be the same as the source register. Seems odd,
2737 // but OK.
2738 ShiftReg = SrcReg;
2739 } else {
2740 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002741 if (Parser.getTok().is(AsmToken::Hash) ||
2742 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002743 Parser.Lex(); // Eat hash.
2744 SMLoc ImmLoc = Parser.getTok().getLoc();
2745 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002746 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002747 Error(ImmLoc, "invalid immediate shift value");
2748 return -1;
2749 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002750 // The expression must be evaluatable as an immediate.
2751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002752 if (!CE) {
2753 Error(ImmLoc, "invalid immediate shift value");
2754 return -1;
2755 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002756 // Range check the immediate.
2757 // lsl, ror: 0 <= imm <= 31
2758 // lsr, asr: 0 <= imm <= 32
2759 Imm = CE->getValue();
2760 if (Imm < 0 ||
2761 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2762 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002763 Error(ImmLoc, "immediate shift value out of range");
2764 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002765 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002766 // shift by zero is a nop. Always send it through as lsl.
2767 // ('as' compatibility)
2768 if (Imm == 0)
2769 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002770 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002771 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002772 EndLoc = Parser.getTok().getEndLoc();
2773 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002774 if (ShiftReg == -1) {
2775 Error (L, "expected immediate or register in shift operand");
2776 return -1;
2777 }
2778 } else {
2779 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002780 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002781 return -1;
2782 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002783 }
2784
Owen Andersonb595ed02011-07-21 18:54:16 +00002785 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2786 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002787 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002788 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002789 else
2790 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002791 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002792
Jim Grosbachbb24c592011-07-13 18:49:30 +00002793 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002794}
2795
2796
Bill Wendling2063b842010-11-18 23:43:05 +00002797/// Try to parse a register name. The token must be an Identifier when called.
2798/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2799/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002800///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002801/// TODO this is likely to change to allow different register types and or to
2802/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002803bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002804tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002805 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002806 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002807 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002808 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002809
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002810 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2811 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002812
Chris Lattner44e5981c2010-10-30 04:09:10 +00002813 const AsmToken &ExclaimTok = Parser.getTok();
2814 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002815 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2816 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002817 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002818 return false;
2819 }
2820
2821 // Also check for an index operand. This is only legal for vector registers,
2822 // but that'll get caught OK in operand matching, so we don't need to
2823 // explicitly filter everything else out here.
2824 if (Parser.getTok().is(AsmToken::LBrac)) {
2825 SMLoc SIdx = Parser.getTok().getLoc();
2826 Parser.Lex(); // Eat left bracket token.
2827
2828 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002829 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002830 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002831 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002832 if (!MCE)
2833 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002834
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002835 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002836 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002837
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002838 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002839 Parser.Lex(); // Eat right bracket token.
2840
2841 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2842 SIdx, E,
2843 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002844 }
2845
Bill Wendling2063b842010-11-18 23:43:05 +00002846 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002847}
2848
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002849/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2850/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2851/// "c5", ...
2852static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002853 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2854 // but efficient.
2855 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002856 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002857 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002858 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002859 return -1;
2860 switch (Name[1]) {
2861 default: return -1;
2862 case '0': return 0;
2863 case '1': return 1;
2864 case '2': return 2;
2865 case '3': return 3;
2866 case '4': return 4;
2867 case '5': return 5;
2868 case '6': return 6;
2869 case '7': return 7;
2870 case '8': return 8;
2871 case '9': return 9;
2872 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002873 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002874 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002875 return -1;
2876 switch (Name[2]) {
2877 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00002878 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2879 case '0': return CoprocOp == 'p'? -1: 10;
2880 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002881 case '2': return 12;
2882 case '3': return 13;
2883 case '4': return 14;
2884 case '5': return 15;
2885 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002886 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002887}
2888
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002889/// parseITCondCode - Try to parse a condition code for an IT instruction.
2890ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2891parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2892 SMLoc S = Parser.getTok().getLoc();
2893 const AsmToken &Tok = Parser.getTok();
2894 if (!Tok.is(AsmToken::Identifier))
2895 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002896 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002897 .Case("eq", ARMCC::EQ)
2898 .Case("ne", ARMCC::NE)
2899 .Case("hs", ARMCC::HS)
2900 .Case("cs", ARMCC::HS)
2901 .Case("lo", ARMCC::LO)
2902 .Case("cc", ARMCC::LO)
2903 .Case("mi", ARMCC::MI)
2904 .Case("pl", ARMCC::PL)
2905 .Case("vs", ARMCC::VS)
2906 .Case("vc", ARMCC::VC)
2907 .Case("hi", ARMCC::HI)
2908 .Case("ls", ARMCC::LS)
2909 .Case("ge", ARMCC::GE)
2910 .Case("lt", ARMCC::LT)
2911 .Case("gt", ARMCC::GT)
2912 .Case("le", ARMCC::LE)
2913 .Case("al", ARMCC::AL)
2914 .Default(~0U);
2915 if (CC == ~0U)
2916 return MatchOperand_NoMatch;
2917 Parser.Lex(); // Eat the token.
2918
2919 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2920
2921 return MatchOperand_Success;
2922}
2923
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002924/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002925/// token must be an Identifier when called, and if it is a coprocessor
2926/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002927ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002928parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002929 SMLoc S = Parser.getTok().getLoc();
2930 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002931 if (Tok.isNot(AsmToken::Identifier))
2932 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002933
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002934 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002935 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002936 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002937
2938 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002939 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002940 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002941}
2942
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002943/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002944/// token must be an Identifier when called, and if it is a coprocessor
2945/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002946ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002947parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002948 SMLoc S = Parser.getTok().getLoc();
2949 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002950 if (Tok.isNot(AsmToken::Identifier))
2951 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002952
2953 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2954 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002955 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002956
2957 Parser.Lex(); // Eat identifier token.
2958 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002959 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002960}
2961
Jim Grosbach48399582011-10-12 17:34:41 +00002962/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2963/// coproc_option : '{' imm0_255 '}'
2964ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2965parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2966 SMLoc S = Parser.getTok().getLoc();
2967
2968 // If this isn't a '{', this isn't a coprocessor immediate operand.
2969 if (Parser.getTok().isNot(AsmToken::LCurly))
2970 return MatchOperand_NoMatch;
2971 Parser.Lex(); // Eat the '{'
2972
2973 const MCExpr *Expr;
2974 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002975 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002976 Error(Loc, "illegal expression");
2977 return MatchOperand_ParseFail;
2978 }
2979 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2980 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2981 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2982 return MatchOperand_ParseFail;
2983 }
2984 int Val = CE->getValue();
2985
2986 // Check for and consume the closing '}'
2987 if (Parser.getTok().isNot(AsmToken::RCurly))
2988 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002989 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002990 Parser.Lex(); // Eat the '}'
2991
2992 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2993 return MatchOperand_Success;
2994}
2995
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002996// For register list parsing, we need to map from raw GPR register numbering
2997// to the enumeration values. The enumeration values aren't sorted by
2998// register number due to our using "sp", "lr" and "pc" as canonical names.
2999static unsigned getNextRegister(unsigned Reg) {
3000 // If this is a GPR, we need to do it manually, otherwise we can rely
3001 // on the sort ordering of the enumeration since the other reg-classes
3002 // are sane.
3003 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3004 return Reg + 1;
3005 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003006 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003007 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3008 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3009 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3010 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3011 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3012 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3013 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3014 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3015 }
3016}
3017
Jim Grosbach85a23432011-11-11 21:27:40 +00003018// Return the low-subreg of a given Q register.
3019static unsigned getDRegFromQReg(unsigned QReg) {
3020 switch (QReg) {
3021 default: llvm_unreachable("expected a Q register!");
3022 case ARM::Q0: return ARM::D0;
3023 case ARM::Q1: return ARM::D2;
3024 case ARM::Q2: return ARM::D4;
3025 case ARM::Q3: return ARM::D6;
3026 case ARM::Q4: return ARM::D8;
3027 case ARM::Q5: return ARM::D10;
3028 case ARM::Q6: return ARM::D12;
3029 case ARM::Q7: return ARM::D14;
3030 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003031 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003032 case ARM::Q10: return ARM::D20;
3033 case ARM::Q11: return ARM::D22;
3034 case ARM::Q12: return ARM::D24;
3035 case ARM::Q13: return ARM::D26;
3036 case ARM::Q14: return ARM::D28;
3037 case ARM::Q15: return ARM::D30;
3038 }
3039}
3040
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003041/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003042bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003043parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003044 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003045 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003046 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003047 Parser.Lex(); // Eat '{' token.
3048 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003049
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003050 // Check the first register in the list to see what register class
3051 // this is a list of.
3052 int Reg = tryParseRegister();
3053 if (Reg == -1)
3054 return Error(RegLoc, "register expected");
3055
Jim Grosbach85a23432011-11-11 21:27:40 +00003056 // The reglist instructions have at most 16 registers, so reserve
3057 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003058 int EReg = 0;
3059 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003060
3061 // Allow Q regs and just interpret them as the two D sub-registers.
3062 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3063 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003064 EReg = MRI->getEncodingValue(Reg);
3065 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003066 ++Reg;
3067 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003068 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003069 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3070 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3071 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3072 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3073 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3074 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3075 else
3076 return Error(RegLoc, "invalid register in register list");
3077
Jim Grosbach85a23432011-11-11 21:27:40 +00003078 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003079 EReg = MRI->getEncodingValue(Reg);
3080 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003081
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003082 // This starts immediately after the first register token in the list,
3083 // so we can see either a comma or a minus (range separator) as a legal
3084 // next token.
3085 while (Parser.getTok().is(AsmToken::Comma) ||
3086 Parser.getTok().is(AsmToken::Minus)) {
3087 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003088 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003089 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003090 int EndReg = tryParseRegister();
3091 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003092 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003093 // Allow Q regs and just interpret them as the two D sub-registers.
3094 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3095 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003096 // If the register is the same as the start reg, there's nothing
3097 // more to do.
3098 if (Reg == EndReg)
3099 continue;
3100 // The register must be in the same register class as the first.
3101 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003102 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003103 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003104 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003105 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003106
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003107 // Add all the registers in the range to the register list.
3108 while (Reg != EndReg) {
3109 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003110 EReg = MRI->getEncodingValue(Reg);
3111 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003112 }
3113 continue;
3114 }
3115 Parser.Lex(); // Eat the comma.
3116 RegLoc = Parser.getTok().getLoc();
3117 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003118 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003119 Reg = tryParseRegister();
3120 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003121 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003122 // Allow Q regs and just interpret them as the two D sub-registers.
3123 bool isQReg = false;
3124 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3125 Reg = getDRegFromQReg(Reg);
3126 isQReg = true;
3127 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003128 // The register must be in the same register class as the first.
3129 if (!RC->contains(Reg))
3130 return Error(RegLoc, "invalid register in register list");
3131 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003132 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003133 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3134 Warning(RegLoc, "register list not in ascending order");
3135 else
3136 return Error(RegLoc, "register list not in ascending order");
3137 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003138 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003139 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3140 ") in register list");
3141 continue;
3142 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003143 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003144 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3145 Reg != OldReg + 1)
3146 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003147 EReg = MRI->getEncodingValue(Reg);
3148 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3149 if (isQReg) {
3150 EReg = MRI->getEncodingValue(++Reg);
3151 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3152 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003153 }
3154
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003155 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003156 return Error(Parser.getTok().getLoc(), "'}' expected");
3157 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003158 Parser.Lex(); // Eat '}' token.
3159
Jim Grosbach18bf3632011-12-13 21:48:29 +00003160 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003161 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003162
3163 // The ARM system instruction variants for LDM/STM have a '^' token here.
3164 if (Parser.getTok().is(AsmToken::Caret)) {
3165 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3166 Parser.Lex(); // Eat '^' token.
3167 }
3168
Bill Wendling2063b842010-11-18 23:43:05 +00003169 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003170}
3171
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003172// Helper function to parse the lane index for vector lists.
3173ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003174parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003175 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003176 if (Parser.getTok().is(AsmToken::LBrac)) {
3177 Parser.Lex(); // Eat the '['.
3178 if (Parser.getTok().is(AsmToken::RBrac)) {
3179 // "Dn[]" is the 'all lanes' syntax.
3180 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003181 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003182 Parser.Lex(); // Eat the ']'.
3183 return MatchOperand_Success;
3184 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003185
3186 // There's an optional '#' token here. Normally there wouldn't be, but
3187 // inline assemble puts one in, and it's friendly to accept that.
3188 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003189 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003190
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003191 const MCExpr *LaneIndex;
3192 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003193 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003194 Error(Loc, "illegal expression");
3195 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003196 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003197 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3198 if (!CE) {
3199 Error(Loc, "lane index must be empty or an integer");
3200 return MatchOperand_ParseFail;
3201 }
3202 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3203 Error(Parser.getTok().getLoc(), "']' expected");
3204 return MatchOperand_ParseFail;
3205 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003206 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003207 Parser.Lex(); // Eat the ']'.
3208 int64_t Val = CE->getValue();
3209
3210 // FIXME: Make this range check context sensitive for .8, .16, .32.
3211 if (Val < 0 || Val > 7) {
3212 Error(Parser.getTok().getLoc(), "lane index out of range");
3213 return MatchOperand_ParseFail;
3214 }
3215 Index = Val;
3216 LaneKind = IndexedLane;
3217 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 }
3219 LaneKind = NoLanes;
3220 return MatchOperand_Success;
3221}
3222
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003223// parse a vector register list
3224ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3225parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003227 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003228 SMLoc S = Parser.getTok().getLoc();
3229 // As an extension (to match gas), support a plain D register or Q register
3230 // (without encosing curly braces) as a single or double entry list,
3231 // respectively.
3232 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003233 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003234 int Reg = tryParseRegister();
3235 if (Reg == -1)
3236 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003237 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003238 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003239 if (Res != MatchOperand_Success)
3240 return Res;
3241 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003242 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003243 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003244 break;
3245 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003246 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3247 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003248 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003249 case IndexedLane:
3250 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003251 LaneIndex,
3252 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003253 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003254 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003255 return MatchOperand_Success;
3256 }
3257 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3258 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003259 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003260 if (Res != MatchOperand_Success)
3261 return Res;
3262 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003263 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003264 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003265 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003266 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003267 break;
3268 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003269 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3270 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003271 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3272 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003273 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003274 case IndexedLane:
3275 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003276 LaneIndex,
3277 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003278 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003279 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003280 return MatchOperand_Success;
3281 }
3282 Error(S, "vector register expected");
3283 return MatchOperand_ParseFail;
3284 }
3285
3286 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003287 return MatchOperand_NoMatch;
3288
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003289 Parser.Lex(); // Eat '{' token.
3290 SMLoc RegLoc = Parser.getTok().getLoc();
3291
3292 int Reg = tryParseRegister();
3293 if (Reg == -1) {
3294 Error(RegLoc, "register expected");
3295 return MatchOperand_ParseFail;
3296 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003297 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003298 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003299 unsigned FirstReg = Reg;
3300 // The list is of D registers, but we also allow Q regs and just interpret
3301 // them as the two D sub-registers.
3302 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3303 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003304 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3305 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003306 ++Reg;
3307 ++Count;
3308 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003309
3310 SMLoc E;
3311 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003312 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003313
Jim Grosbache891fe82011-11-15 23:19:15 +00003314 while (Parser.getTok().is(AsmToken::Comma) ||
3315 Parser.getTok().is(AsmToken::Minus)) {
3316 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003317 if (!Spacing)
3318 Spacing = 1; // Register range implies a single spaced list.
3319 else if (Spacing == 2) {
3320 Error(Parser.getTok().getLoc(),
3321 "sequential registers in double spaced list");
3322 return MatchOperand_ParseFail;
3323 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003324 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003325 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003326 int EndReg = tryParseRegister();
3327 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003328 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003329 return MatchOperand_ParseFail;
3330 }
3331 // Allow Q regs and just interpret them as the two D sub-registers.
3332 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3333 EndReg = getDRegFromQReg(EndReg) + 1;
3334 // If the register is the same as the start reg, there's nothing
3335 // more to do.
3336 if (Reg == EndReg)
3337 continue;
3338 // The register must be in the same register class as the first.
3339 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003340 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003341 return MatchOperand_ParseFail;
3342 }
3343 // Ranges must go from low to high.
3344 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003345 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003346 return MatchOperand_ParseFail;
3347 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003348 // Parse the lane specifier if present.
3349 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003350 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003351 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(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003356 return MatchOperand_ParseFail;
3357 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003358
3359 // Add all the registers in the range to the register list.
3360 Count += EndReg - Reg;
3361 Reg = EndReg;
3362 continue;
3363 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003364 Parser.Lex(); // Eat the comma.
3365 RegLoc = Parser.getTok().getLoc();
3366 int OldReg = Reg;
3367 Reg = tryParseRegister();
3368 if (Reg == -1) {
3369 Error(RegLoc, "register expected");
3370 return MatchOperand_ParseFail;
3371 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003372 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003373 // It's OK to use the enumeration values directly here rather, as the
3374 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003375 //
3376 // The list is of D registers, but we also allow Q regs and just interpret
3377 // them as the two D sub-registers.
3378 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003379 if (!Spacing)
3380 Spacing = 1; // Register range implies a single spaced list.
3381 else if (Spacing == 2) {
3382 Error(RegLoc,
3383 "invalid register in double-spaced list (must be 'D' register')");
3384 return MatchOperand_ParseFail;
3385 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003386 Reg = getDRegFromQReg(Reg);
3387 if (Reg != OldReg + 1) {
3388 Error(RegLoc, "non-contiguous register range");
3389 return MatchOperand_ParseFail;
3390 }
3391 ++Reg;
3392 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003393 // Parse the lane specifier if present.
3394 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003395 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003396 SMLoc LaneLoc = Parser.getTok().getLoc();
3397 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3398 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003399 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003400 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003401 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003402 return MatchOperand_ParseFail;
3403 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003404 continue;
3405 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003406 // Normal D register.
3407 // Figure out the register spacing (single or double) of the list if
3408 // we don't know it already.
3409 if (!Spacing)
3410 Spacing = 1 + (Reg == OldReg + 2);
3411
3412 // Just check that it's contiguous and keep going.
3413 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003414 Error(RegLoc, "non-contiguous register range");
3415 return MatchOperand_ParseFail;
3416 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003417 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003418 // Parse the lane specifier if present.
3419 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003420 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003421 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003422 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003423 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003424 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003425 Error(EndLoc, "mismatched lane index in register list");
3426 return MatchOperand_ParseFail;
3427 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003428 }
3429
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003430 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003431 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003432 return MatchOperand_ParseFail;
3433 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003434 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003435 Parser.Lex(); // Eat '}' token.
3436
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003437 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003438 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003439 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003440 // composite register classes.
3441 if (Count == 2) {
3442 const MCRegisterClass *RC = (Spacing == 1) ?
3443 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3444 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3445 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3446 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003447
Jim Grosbach2f50e922011-12-15 21:44:33 +00003448 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3449 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003450 break;
3451 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003452 // Two-register operands have been converted to the
3453 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003454 if (Count == 2) {
3455 const MCRegisterClass *RC = (Spacing == 1) ?
3456 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3457 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003458 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3459 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003460 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003461 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003462 S, E));
3463 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003464 case IndexedLane:
3465 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003466 LaneIndex,
3467 (Spacing == 2),
3468 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003469 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003470 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003471 return MatchOperand_Success;
3472}
3473
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003474/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003475ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003476parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003477 SMLoc S = Parser.getTok().getLoc();
3478 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003479 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003480
Jiangning Liu288e1af2012-08-02 08:21:27 +00003481 if (Tok.is(AsmToken::Identifier)) {
3482 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003483
Jiangning Liu288e1af2012-08-02 08:21:27 +00003484 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3485 .Case("sy", ARM_MB::SY)
3486 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003487 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003488 .Case("sh", ARM_MB::ISH)
3489 .Case("ish", ARM_MB::ISH)
3490 .Case("shst", ARM_MB::ISHST)
3491 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003492 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003493 .Case("nsh", ARM_MB::NSH)
3494 .Case("un", ARM_MB::NSH)
3495 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003496 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003497 .Case("unst", ARM_MB::NSHST)
3498 .Case("osh", ARM_MB::OSH)
3499 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003500 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003501 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003502
Joey Gouly926d3f52013-09-05 15:35:24 +00003503 // ishld, oshld, nshld and ld are only available from ARMv8.
3504 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3505 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3506 Opt = ~0U;
3507
Jiangning Liu288e1af2012-08-02 08:21:27 +00003508 if (Opt == ~0U)
3509 return MatchOperand_NoMatch;
3510
3511 Parser.Lex(); // Eat identifier token.
3512 } else if (Tok.is(AsmToken::Hash) ||
3513 Tok.is(AsmToken::Dollar) ||
3514 Tok.is(AsmToken::Integer)) {
3515 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003516 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003517 SMLoc Loc = Parser.getTok().getLoc();
3518
3519 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003520 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003521 Error(Loc, "illegal expression");
3522 return MatchOperand_ParseFail;
3523 }
3524
3525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3526 if (!CE) {
3527 Error(Loc, "constant expression expected");
3528 return MatchOperand_ParseFail;
3529 }
3530
3531 int Val = CE->getValue();
3532 if (Val & ~0xf) {
3533 Error(Loc, "immediate value out of range");
3534 return MatchOperand_ParseFail;
3535 }
3536
3537 Opt = ARM_MB::RESERVED_0 + Val;
3538 } else
3539 return MatchOperand_ParseFail;
3540
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003541 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003542 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003543}
3544
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003545/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3546ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3547parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3548 SMLoc S = Parser.getTok().getLoc();
3549 const AsmToken &Tok = Parser.getTok();
3550 unsigned Opt;
3551
3552 if (Tok.is(AsmToken::Identifier)) {
3553 StringRef OptStr = Tok.getString();
3554
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003555 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003556 Opt = ARM_ISB::SY;
3557 else
3558 return MatchOperand_NoMatch;
3559
3560 Parser.Lex(); // Eat identifier token.
3561 } else if (Tok.is(AsmToken::Hash) ||
3562 Tok.is(AsmToken::Dollar) ||
3563 Tok.is(AsmToken::Integer)) {
3564 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003565 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003566 SMLoc Loc = Parser.getTok().getLoc();
3567
3568 const MCExpr *ISBarrierID;
3569 if (getParser().parseExpression(ISBarrierID)) {
3570 Error(Loc, "illegal expression");
3571 return MatchOperand_ParseFail;
3572 }
3573
3574 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3575 if (!CE) {
3576 Error(Loc, "constant expression expected");
3577 return MatchOperand_ParseFail;
3578 }
3579
3580 int Val = CE->getValue();
3581 if (Val & ~0xf) {
3582 Error(Loc, "immediate value out of range");
3583 return MatchOperand_ParseFail;
3584 }
3585
3586 Opt = ARM_ISB::RESERVED_0 + Val;
3587 } else
3588 return MatchOperand_ParseFail;
3589
3590 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3591 (ARM_ISB::InstSyncBOpt)Opt, S));
3592 return MatchOperand_Success;
3593}
3594
3595
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003596/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003597ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003598parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003599 SMLoc S = Parser.getTok().getLoc();
3600 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003601 if (!Tok.is(AsmToken::Identifier))
3602 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003603 StringRef IFlagsStr = Tok.getString();
3604
Owen Anderson10c5b122011-10-05 17:16:40 +00003605 // An iflags string of "none" is interpreted to mean that none of the AIF
3606 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003607 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003608 if (IFlagsStr != "none") {
3609 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3610 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3611 .Case("a", ARM_PROC::A)
3612 .Case("i", ARM_PROC::I)
3613 .Case("f", ARM_PROC::F)
3614 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003615
Owen Anderson10c5b122011-10-05 17:16:40 +00003616 // If some specific iflag is already set, it means that some letter is
3617 // present more than once, this is not acceptable.
3618 if (Flag == ~0U || (IFlags & Flag))
3619 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003620
Owen Anderson10c5b122011-10-05 17:16:40 +00003621 IFlags |= Flag;
3622 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003623 }
3624
3625 Parser.Lex(); // Eat identifier token.
3626 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3627 return MatchOperand_Success;
3628}
3629
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003630/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003631ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003632parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003633 SMLoc S = Parser.getTok().getLoc();
3634 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003635 if (!Tok.is(AsmToken::Identifier))
3636 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003637 StringRef Mask = Tok.getString();
3638
James Molloy21efa7d2011-09-28 14:21:38 +00003639 if (isMClass()) {
3640 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003641 std::string Name = Mask.lower();
3642 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003643 // Note: in the documentation:
3644 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3645 // for MSR APSR_nzcvq.
3646 // but we do make it an alias here. This is so to get the "mask encoding"
3647 // bits correct on MSR APSR writes.
3648 //
3649 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3650 // should really only be allowed when writing a special register. Note
3651 // they get dropped in the MRS instruction reading a special register as
3652 // the SYSm field is only 8 bits.
3653 //
3654 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3655 // includes the DSP extension but that is not checked.
3656 .Case("apsr", 0x800)
3657 .Case("apsr_nzcvq", 0x800)
3658 .Case("apsr_g", 0x400)
3659 .Case("apsr_nzcvqg", 0xc00)
3660 .Case("iapsr", 0x801)
3661 .Case("iapsr_nzcvq", 0x801)
3662 .Case("iapsr_g", 0x401)
3663 .Case("iapsr_nzcvqg", 0xc01)
3664 .Case("eapsr", 0x802)
3665 .Case("eapsr_nzcvq", 0x802)
3666 .Case("eapsr_g", 0x402)
3667 .Case("eapsr_nzcvqg", 0xc02)
3668 .Case("xpsr", 0x803)
3669 .Case("xpsr_nzcvq", 0x803)
3670 .Case("xpsr_g", 0x403)
3671 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003672 .Case("ipsr", 0x805)
3673 .Case("epsr", 0x806)
3674 .Case("iepsr", 0x807)
3675 .Case("msp", 0x808)
3676 .Case("psp", 0x809)
3677 .Case("primask", 0x810)
3678 .Case("basepri", 0x811)
3679 .Case("basepri_max", 0x812)
3680 .Case("faultmask", 0x813)
3681 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003682 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003683
James Molloy21efa7d2011-09-28 14:21:38 +00003684 if (FlagsVal == ~0U)
3685 return MatchOperand_NoMatch;
3686
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003687 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003688 // basepri, basepri_max and faultmask only valid for V7m.
3689 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003690
James Molloy21efa7d2011-09-28 14:21:38 +00003691 Parser.Lex(); // Eat identifier token.
3692 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3693 return MatchOperand_Success;
3694 }
3695
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003696 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3697 size_t Start = 0, Next = Mask.find('_');
3698 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003699 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003700 if (Next != StringRef::npos)
3701 Flags = Mask.slice(Next+1, Mask.size());
3702
3703 // FlagsVal contains the complete mask:
3704 // 3-0: Mask
3705 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3706 unsigned FlagsVal = 0;
3707
3708 if (SpecReg == "apsr") {
3709 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003710 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003711 .Case("g", 0x4) // same as CPSR_s
3712 .Case("nzcvqg", 0xc) // same as CPSR_fs
3713 .Default(~0U);
3714
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003715 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003716 if (!Flags.empty())
3717 return MatchOperand_NoMatch;
3718 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003719 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003720 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003721 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003722 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3723 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003724 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003725 for (int i = 0, e = Flags.size(); i != e; ++i) {
3726 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3727 .Case("c", 1)
3728 .Case("x", 2)
3729 .Case("s", 4)
3730 .Case("f", 8)
3731 .Default(~0U);
3732
3733 // If some specific flag is already set, it means that some letter is
3734 // present more than once, this is not acceptable.
3735 if (FlagsVal == ~0U || (FlagsVal & Flag))
3736 return MatchOperand_NoMatch;
3737 FlagsVal |= Flag;
3738 }
3739 } else // No match for special register.
3740 return MatchOperand_NoMatch;
3741
Owen Anderson03a173e2011-10-21 18:43:28 +00003742 // Special register without flags is NOT equivalent to "fc" flags.
3743 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3744 // two lines would enable gas compatibility at the expense of breaking
3745 // round-tripping.
3746 //
3747 // if (!FlagsVal)
3748 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003749
3750 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3751 if (SpecReg == "spsr")
3752 FlagsVal |= 16;
3753
3754 Parser.Lex(); // Eat identifier token.
3755 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3756 return MatchOperand_Success;
3757}
3758
Jim Grosbach27c1e252011-07-21 17:23:04 +00003759ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3760parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3761 int Low, int High) {
3762 const AsmToken &Tok = Parser.getTok();
3763 if (Tok.isNot(AsmToken::Identifier)) {
3764 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3765 return MatchOperand_ParseFail;
3766 }
3767 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003768 std::string LowerOp = Op.lower();
3769 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003770 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3771 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3772 return MatchOperand_ParseFail;
3773 }
3774 Parser.Lex(); // Eat shift type token.
3775
3776 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003777 if (Parser.getTok().isNot(AsmToken::Hash) &&
3778 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003779 Error(Parser.getTok().getLoc(), "'#' expected");
3780 return MatchOperand_ParseFail;
3781 }
3782 Parser.Lex(); // Eat hash token.
3783
3784 const MCExpr *ShiftAmount;
3785 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003786 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003787 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003788 Error(Loc, "illegal expression");
3789 return MatchOperand_ParseFail;
3790 }
3791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3792 if (!CE) {
3793 Error(Loc, "constant expression expected");
3794 return MatchOperand_ParseFail;
3795 }
3796 int Val = CE->getValue();
3797 if (Val < Low || Val > High) {
3798 Error(Loc, "immediate value out of range");
3799 return MatchOperand_ParseFail;
3800 }
3801
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003802 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003803
3804 return MatchOperand_Success;
3805}
3806
Jim Grosbach0a547702011-07-22 17:44:50 +00003807ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3808parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3809 const AsmToken &Tok = Parser.getTok();
3810 SMLoc S = Tok.getLoc();
3811 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003812 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003813 return MatchOperand_ParseFail;
3814 }
Tim Northover4d141442013-05-31 15:58:45 +00003815 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003816 .Case("be", 1)
3817 .Case("le", 0)
3818 .Default(-1);
3819 Parser.Lex(); // Eat the token.
3820
3821 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003822 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003823 return MatchOperand_ParseFail;
3824 }
3825 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3826 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003827 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003828 return MatchOperand_Success;
3829}
3830
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003831/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3832/// instructions. Legal values are:
3833/// lsl #n 'n' in [0,31]
3834/// asr #n 'n' in [1,32]
3835/// n == 32 encoded as n == 0.
3836ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3837parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3838 const AsmToken &Tok = Parser.getTok();
3839 SMLoc S = Tok.getLoc();
3840 if (Tok.isNot(AsmToken::Identifier)) {
3841 Error(S, "shift operator 'asr' or 'lsl' expected");
3842 return MatchOperand_ParseFail;
3843 }
3844 StringRef ShiftName = Tok.getString();
3845 bool isASR;
3846 if (ShiftName == "lsl" || ShiftName == "LSL")
3847 isASR = false;
3848 else if (ShiftName == "asr" || ShiftName == "ASR")
3849 isASR = true;
3850 else {
3851 Error(S, "shift operator 'asr' or 'lsl' expected");
3852 return MatchOperand_ParseFail;
3853 }
3854 Parser.Lex(); // Eat the operator.
3855
3856 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003857 if (Parser.getTok().isNot(AsmToken::Hash) &&
3858 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003859 Error(Parser.getTok().getLoc(), "'#' expected");
3860 return MatchOperand_ParseFail;
3861 }
3862 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003863 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003864
3865 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003866 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003867 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003868 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003869 return MatchOperand_ParseFail;
3870 }
3871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3872 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003873 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003874 return MatchOperand_ParseFail;
3875 }
3876
3877 int64_t Val = CE->getValue();
3878 if (isASR) {
3879 // Shift amount must be in [1,32]
3880 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003881 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003882 return MatchOperand_ParseFail;
3883 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003884 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3885 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003886 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003887 return MatchOperand_ParseFail;
3888 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003889 if (Val == 32) Val = 0;
3890 } else {
3891 // Shift amount must be in [1,32]
3892 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003893 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003894 return MatchOperand_ParseFail;
3895 }
3896 }
3897
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003898 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003899
3900 return MatchOperand_Success;
3901}
3902
Jim Grosbach833b9d32011-07-27 20:15:40 +00003903/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3904/// of instructions. Legal values are:
3905/// ror #n 'n' in {0, 8, 16, 24}
3906ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3907parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3908 const AsmToken &Tok = Parser.getTok();
3909 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003910 if (Tok.isNot(AsmToken::Identifier))
3911 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003912 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003913 if (ShiftName != "ror" && ShiftName != "ROR")
3914 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003915 Parser.Lex(); // Eat the operator.
3916
3917 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003918 if (Parser.getTok().isNot(AsmToken::Hash) &&
3919 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003920 Error(Parser.getTok().getLoc(), "'#' expected");
3921 return MatchOperand_ParseFail;
3922 }
3923 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003924 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003925
3926 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003927 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003928 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003929 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003930 return MatchOperand_ParseFail;
3931 }
3932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3933 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003934 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003935 return MatchOperand_ParseFail;
3936 }
3937
3938 int64_t Val = CE->getValue();
3939 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3940 // normally, zero is represented in asm by omitting the rotate operand
3941 // entirely.
3942 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003943 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003944 return MatchOperand_ParseFail;
3945 }
3946
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003947 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003948
3949 return MatchOperand_Success;
3950}
3951
Jim Grosbach864b6092011-07-28 21:34:26 +00003952ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3953parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 SMLoc S = Parser.getTok().getLoc();
3955 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003956 if (Parser.getTok().isNot(AsmToken::Hash) &&
3957 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003958 Error(Parser.getTok().getLoc(), "'#' expected");
3959 return MatchOperand_ParseFail;
3960 }
3961 Parser.Lex(); // Eat hash token.
3962
3963 const MCExpr *LSBExpr;
3964 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003965 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003966 Error(E, "malformed immediate expression");
3967 return MatchOperand_ParseFail;
3968 }
3969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3970 if (!CE) {
3971 Error(E, "'lsb' operand must be an immediate");
3972 return MatchOperand_ParseFail;
3973 }
3974
3975 int64_t LSB = CE->getValue();
3976 // The LSB must be in the range [0,31]
3977 if (LSB < 0 || LSB > 31) {
3978 Error(E, "'lsb' operand must be in the range [0,31]");
3979 return MatchOperand_ParseFail;
3980 }
3981 E = Parser.getTok().getLoc();
3982
3983 // Expect another immediate operand.
3984 if (Parser.getTok().isNot(AsmToken::Comma)) {
3985 Error(Parser.getTok().getLoc(), "too few operands");
3986 return MatchOperand_ParseFail;
3987 }
3988 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003989 if (Parser.getTok().isNot(AsmToken::Hash) &&
3990 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003991 Error(Parser.getTok().getLoc(), "'#' expected");
3992 return MatchOperand_ParseFail;
3993 }
3994 Parser.Lex(); // Eat hash token.
3995
3996 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003997 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003998 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003999 Error(E, "malformed immediate expression");
4000 return MatchOperand_ParseFail;
4001 }
4002 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4003 if (!CE) {
4004 Error(E, "'width' operand must be an immediate");
4005 return MatchOperand_ParseFail;
4006 }
4007
4008 int64_t Width = CE->getValue();
4009 // The LSB must be in the range [1,32-lsb]
4010 if (Width < 1 || Width > 32 - LSB) {
4011 Error(E, "'width' operand must be in the range [1,32-lsb]");
4012 return MatchOperand_ParseFail;
4013 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004014
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004015 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004016
4017 return MatchOperand_Success;
4018}
4019
Jim Grosbachd3595712011-08-03 23:50:40 +00004020ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4021parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4022 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004023 // postidx_reg := '+' register {, shift}
4024 // | '-' register {, shift}
4025 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004026
4027 // This method must return MatchOperand_NoMatch without consuming any tokens
4028 // in the case where there is no match, as other alternatives take other
4029 // parse methods.
4030 AsmToken Tok = Parser.getTok();
4031 SMLoc S = Tok.getLoc();
4032 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004033 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004034 if (Tok.is(AsmToken::Plus)) {
4035 Parser.Lex(); // Eat the '+' token.
4036 haveEaten = true;
4037 } else if (Tok.is(AsmToken::Minus)) {
4038 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004039 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004040 haveEaten = true;
4041 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004042
4043 SMLoc E = Parser.getTok().getEndLoc();
4044 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004045 if (Reg == -1) {
4046 if (!haveEaten)
4047 return MatchOperand_NoMatch;
4048 Error(Parser.getTok().getLoc(), "register expected");
4049 return MatchOperand_ParseFail;
4050 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004051
Jim Grosbachc320c852011-08-05 21:28:30 +00004052 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4053 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004054 if (Parser.getTok().is(AsmToken::Comma)) {
4055 Parser.Lex(); // Eat the ','.
4056 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4057 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004058
4059 // FIXME: Only approximates end...may include intervening whitespace.
4060 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004061 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004062
4063 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4064 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004065
4066 return MatchOperand_Success;
4067}
4068
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004069ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4070parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4071 // Check for a post-index addressing register operand. Specifically:
4072 // am3offset := '+' register
4073 // | '-' register
4074 // | register
4075 // | # imm
4076 // | # + imm
4077 // | # - imm
4078
4079 // This method must return MatchOperand_NoMatch without consuming any tokens
4080 // in the case where there is no match, as other alternatives take other
4081 // parse methods.
4082 AsmToken Tok = Parser.getTok();
4083 SMLoc S = Tok.getLoc();
4084
4085 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004086 if (Parser.getTok().is(AsmToken::Hash) ||
4087 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004088 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004089 // Explicitly look for a '-', as we need to encode negative zero
4090 // differently.
4091 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4092 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004093 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004094 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004095 return MatchOperand_ParseFail;
4096 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4097 if (!CE) {
4098 Error(S, "constant expression expected");
4099 return MatchOperand_ParseFail;
4100 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004101 // Negative zero is encoded as the flag value INT32_MIN.
4102 int32_t Val = CE->getValue();
4103 if (isNegative && Val == 0)
4104 Val = INT32_MIN;
4105
4106 Operands.push_back(
4107 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4108
4109 return MatchOperand_Success;
4110 }
4111
4112
4113 bool haveEaten = false;
4114 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004115 if (Tok.is(AsmToken::Plus)) {
4116 Parser.Lex(); // Eat the '+' token.
4117 haveEaten = true;
4118 } else if (Tok.is(AsmToken::Minus)) {
4119 Parser.Lex(); // Eat the '-' token.
4120 isAdd = false;
4121 haveEaten = true;
4122 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004123
4124 Tok = Parser.getTok();
4125 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004126 if (Reg == -1) {
4127 if (!haveEaten)
4128 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004129 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004130 return MatchOperand_ParseFail;
4131 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004132
4133 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004134 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004135
4136 return MatchOperand_Success;
4137}
4138
Tim Northovereb5e4d52013-07-22 09:06:12 +00004139/// Convert parsed operands to MCInst. Needed here because this instruction
4140/// only has two register operands, but multiplication is commutative so
4141/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004142void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004143cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004144 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004145 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4146 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004147 // If we have a three-operand form, make sure to set Rn to be the operand
4148 // that isn't the same as Rd.
4149 unsigned RegOp = 4;
4150 if (Operands.size() == 6 &&
4151 ((ARMOperand*)Operands[4])->getReg() ==
4152 ((ARMOperand*)Operands[3])->getReg())
4153 RegOp = 5;
4154 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4155 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004156 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004157}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004158
Mihai Popaad18d3c2013-08-09 10:38:32 +00004159void ARMAsmParser::
4160cvtThumbBranches(MCInst &Inst,
4161 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4162 int CondOp = -1, ImmOp = -1;
4163 switch(Inst.getOpcode()) {
4164 case ARM::tB:
4165 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4166
4167 case ARM::t2B:
4168 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4169
4170 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4171 }
4172 // first decide whether or not the branch should be conditional
4173 // by looking at it's location relative to an IT block
4174 if(inITBlock()) {
4175 // inside an IT block we cannot have any conditional branches. any
4176 // such instructions needs to be converted to unconditional form
4177 switch(Inst.getOpcode()) {
4178 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4179 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4180 }
4181 } else {
4182 // outside IT blocks we can only have unconditional branches with AL
4183 // condition code or conditional branches with non-AL condition code
4184 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4185 switch(Inst.getOpcode()) {
4186 case ARM::tB:
4187 case ARM::tBcc:
4188 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4189 break;
4190 case ARM::t2B:
4191 case ARM::t2Bcc:
4192 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4193 break;
4194 }
4195 }
4196
4197 // now decide on encoding size based on branch target range
4198 switch(Inst.getOpcode()) {
4199 // classify tB as either t2B or t1B based on range of immediate operand
4200 case ARM::tB: {
4201 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4202 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4203 Inst.setOpcode(ARM::t2B);
4204 break;
4205 }
4206 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4207 case ARM::tBcc: {
4208 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4209 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4210 Inst.setOpcode(ARM::t2Bcc);
4211 break;
4212 }
4213 }
4214 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4215 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4216}
4217
Bill Wendlinge18980a2010-11-06 22:36:58 +00004218/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004219/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004220bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004221parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004222 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004223 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004224 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004225 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004226 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004227
Sean Callanan936b0d32010-01-19 21:44:56 +00004228 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004229 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004230 if (BaseRegNum == -1)
4231 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004232
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004233 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004234 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004235 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4236 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004237 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004238
Jim Grosbachd3595712011-08-03 23:50:40 +00004239 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004240 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004241 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004242
Jim Grosbachd3595712011-08-03 23:50:40 +00004243 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004244 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004245
Jim Grosbach40700e02011-09-19 18:42:21 +00004246 // If there's a pre-indexing writeback marker, '!', just add it as a token
4247 // operand. It's rather odd, but syntactically valid.
4248 if (Parser.getTok().is(AsmToken::Exclaim)) {
4249 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4250 Parser.Lex(); // Eat the '!'.
4251 }
4252
Jim Grosbachd3595712011-08-03 23:50:40 +00004253 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004254 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004255
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004256 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4257 "Lost colon or comma in memory operand?!");
4258 if (Tok.is(AsmToken::Comma)) {
4259 Parser.Lex(); // Eat the comma.
4260 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004261
Jim Grosbacha95ec992011-10-11 17:29:55 +00004262 // If we have a ':', it's an alignment specifier.
4263 if (Parser.getTok().is(AsmToken::Colon)) {
4264 Parser.Lex(); // Eat the ':'.
4265 E = Parser.getTok().getLoc();
4266
4267 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004268 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004269 return true;
4270
4271 // The expression has to be a constant. Memory references with relocations
4272 // don't come through here, as they use the <label> forms of the relevant
4273 // instructions.
4274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4275 if (!CE)
4276 return Error (E, "constant expression expected");
4277
4278 unsigned Align = 0;
4279 switch (CE->getValue()) {
4280 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004281 return Error(E,
4282 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4283 case 16: Align = 2; break;
4284 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004285 case 64: Align = 8; break;
4286 case 128: Align = 16; break;
4287 case 256: Align = 32; break;
4288 }
4289
4290 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004291 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004292 return Error(Parser.getTok().getLoc(), "']' expected");
4293 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004294 Parser.Lex(); // Eat right bracket token.
4295
4296 // Don't worry about range checking the value here. That's handled by
4297 // the is*() predicates.
4298 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4299 ARM_AM::no_shift, 0, Align,
4300 false, S, E));
4301
4302 // If there's a pre-indexing writeback marker, '!', just add it as a token
4303 // operand.
4304 if (Parser.getTok().is(AsmToken::Exclaim)) {
4305 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4306 Parser.Lex(); // Eat the '!'.
4307 }
4308
4309 return false;
4310 }
4311
4312 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004313 // offset. Be friendly and also accept a plain integer (without a leading
4314 // hash) for gas compatibility.
4315 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004316 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004317 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004318 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004319 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004320 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004321
Owen Anderson967674d2011-08-29 19:36:44 +00004322 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004323 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004324 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004325 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004326
4327 // The expression has to be a constant. Memory references with relocations
4328 // don't come through here, as they use the <label> forms of the relevant
4329 // instructions.
4330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4331 if (!CE)
4332 return Error (E, "constant expression expected");
4333
Owen Anderson967674d2011-08-29 19:36:44 +00004334 // If the constant was #-0, represent it as INT32_MIN.
4335 int32_t Val = CE->getValue();
4336 if (isNegative && Val == 0)
4337 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4338
Jim Grosbachd3595712011-08-03 23:50:40 +00004339 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004340 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004341 return Error(Parser.getTok().getLoc(), "']' expected");
4342 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004343 Parser.Lex(); // Eat right bracket token.
4344
4345 // Don't worry about range checking the value here. That's handled by
4346 // the is*() predicates.
4347 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004348 ARM_AM::no_shift, 0, 0,
4349 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004350
4351 // If there's a pre-indexing writeback marker, '!', just add it as a token
4352 // operand.
4353 if (Parser.getTok().is(AsmToken::Exclaim)) {
4354 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4355 Parser.Lex(); // Eat the '!'.
4356 }
4357
4358 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004359 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004360
4361 // The register offset is optionally preceded by a '+' or '-'
4362 bool isNegative = false;
4363 if (Parser.getTok().is(AsmToken::Minus)) {
4364 isNegative = true;
4365 Parser.Lex(); // Eat the '-'.
4366 } else if (Parser.getTok().is(AsmToken::Plus)) {
4367 // Nothing to do.
4368 Parser.Lex(); // Eat the '+'.
4369 }
4370
4371 E = Parser.getTok().getLoc();
4372 int OffsetRegNum = tryParseRegister();
4373 if (OffsetRegNum == -1)
4374 return Error(E, "register expected");
4375
4376 // If there's a shift operator, handle it.
4377 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004378 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004379 if (Parser.getTok().is(AsmToken::Comma)) {
4380 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004381 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004382 return true;
4383 }
4384
4385 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004386 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004387 return Error(Parser.getTok().getLoc(), "']' expected");
4388 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004389 Parser.Lex(); // Eat right bracket token.
4390
4391 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004392 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004393 S, E));
4394
Jim Grosbachc320c852011-08-05 21:28:30 +00004395 // If there's a pre-indexing writeback marker, '!', just add it as a token
4396 // operand.
4397 if (Parser.getTok().is(AsmToken::Exclaim)) {
4398 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4399 Parser.Lex(); // Eat the '!'.
4400 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004401
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004402 return false;
4403}
4404
Jim Grosbachd3595712011-08-03 23:50:40 +00004405/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406/// ( lsl | lsr | asr | ror ) , # shift_amount
4407/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004408/// return true if it parses a shift otherwise it returns false.
4409bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4410 unsigned &Amount) {
4411 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004412 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004413 if (Tok.isNot(AsmToken::Identifier))
4414 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004415 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004416 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4417 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004418 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004419 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004420 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004421 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004422 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004423 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004424 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004425 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004426 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004427 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004428 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004429 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004430
Jim Grosbachd3595712011-08-03 23:50:40 +00004431 // rrx stands alone.
4432 Amount = 0;
4433 if (St != ARM_AM::rrx) {
4434 Loc = Parser.getTok().getLoc();
4435 // A '#' and a shift amount.
4436 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004437 if (HashTok.isNot(AsmToken::Hash) &&
4438 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004439 return Error(HashTok.getLoc(), "'#' expected");
4440 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004441
Jim Grosbachd3595712011-08-03 23:50:40 +00004442 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004443 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004444 return true;
4445 // Range check the immediate.
4446 // lsl, ror: 0 <= imm <= 31
4447 // lsr, asr: 0 <= imm <= 32
4448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4449 if (!CE)
4450 return Error(Loc, "shift amount must be an immediate");
4451 int64_t Imm = CE->getValue();
4452 if (Imm < 0 ||
4453 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4454 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4455 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004456 // If <ShiftTy> #0, turn it into a no_shift.
4457 if (Imm == 0)
4458 St = ARM_AM::lsl;
4459 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4460 if (Imm == 32)
4461 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004462 Amount = Imm;
4463 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004464
4465 return false;
4466}
4467
Jim Grosbache7fbce72011-10-03 23:38:36 +00004468/// parseFPImm - A floating point immediate expression operand.
4469ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4470parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004471 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004472 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004473 // integer only.
4474 //
4475 // This routine still creates a generic Immediate operand, containing
4476 // a bitcast of the 64-bit floating point value. The various operands
4477 // that accept floats can check whether the value is valid for them
4478 // via the standard is*() predicates.
4479
Jim Grosbache7fbce72011-10-03 23:38:36 +00004480 SMLoc S = Parser.getTok().getLoc();
4481
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004482 if (Parser.getTok().isNot(AsmToken::Hash) &&
4483 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004484 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004485
4486 // Disambiguate the VMOV forms that can accept an FP immediate.
4487 // vmov.f32 <sreg>, #imm
4488 // vmov.f64 <dreg>, #imm
4489 // vmov.f32 <dreg>, #imm @ vector f32x2
4490 // vmov.f32 <qreg>, #imm @ vector f32x4
4491 //
4492 // There are also the NEON VMOV instructions which expect an
4493 // integer constant. Make sure we don't try to parse an FPImm
4494 // for these:
4495 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4496 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4497 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4498 TyOp->getToken() != ".f64"))
4499 return MatchOperand_NoMatch;
4500
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004501 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004502
4503 // Handle negation, as that still comes through as a separate token.
4504 bool isNegative = false;
4505 if (Parser.getTok().is(AsmToken::Minus)) {
4506 isNegative = true;
4507 Parser.Lex();
4508 }
4509 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004510 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004511 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004512 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004513 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4514 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004515 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004516 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004517 Operands.push_back(ARMOperand::CreateImm(
4518 MCConstantExpr::Create(IntVal, getContext()),
4519 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004520 return MatchOperand_Success;
4521 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004522 // Also handle plain integers. Instructions which allow floating point
4523 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004524 if (Tok.is(AsmToken::Integer)) {
4525 int64_t Val = Tok.getIntVal();
4526 Parser.Lex(); // Eat the token.
4527 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004528 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004529 return MatchOperand_ParseFail;
4530 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004531 double RealVal = ARM_AM::getFPImmFloat(Val);
4532 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4533 Operands.push_back(ARMOperand::CreateImm(
4534 MCConstantExpr::Create(Val, getContext()), S,
4535 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004536 return MatchOperand_Success;
4537 }
4538
Jim Grosbach235c8d22012-01-19 02:47:30 +00004539 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004540 return MatchOperand_ParseFail;
4541}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004542
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004543/// Parse a arm instruction operand. For now this parses the operand regardless
4544/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004545bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004546 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004547 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004548
4549 // Check if the current operand has a custom associated parser, if so, try to
4550 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004551 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4552 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004553 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004554 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4555 // there was a match, but an error occurred, in which case, just return that
4556 // the operand parsing failed.
4557 if (ResTy == MatchOperand_ParseFail)
4558 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004559
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004560 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004561 default:
4562 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004563 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004564 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004565 // If we've seen a branch mnemonic, the next operand must be a label. This
4566 // is true even if the label is a register name. So "br r1" means branch to
4567 // label "r1".
4568 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4569 if (!ExpectLabel) {
4570 if (!tryParseRegisterWithWriteBack(Operands))
4571 return false;
4572 int Res = tryParseShiftRegister(Operands);
4573 if (Res == 0) // success
4574 return false;
4575 else if (Res == -1) // irrecoverable error
4576 return true;
4577 // If this is VMRS, check for the apsr_nzcv operand.
4578 if (Mnemonic == "vmrs" &&
4579 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4580 S = Parser.getTok().getLoc();
4581 Parser.Lex();
4582 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4583 return false;
4584 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004585 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004586
4587 // Fall though for the Identifier case that is not a register or a
4588 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004589 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004590 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004591 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004592 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004593 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004594 // This was not a register so parse other operands that start with an
4595 // identifier (like labels) as expressions and create them as immediates.
4596 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004597 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004598 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004599 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004600 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004601 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4602 return false;
4603 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004604 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004605 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004606 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004607 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004608 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004609 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004610 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004611 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004612 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004613
4614 if (Parser.getTok().isNot(AsmToken::Colon)) {
4615 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4616 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004617 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004618 return true;
4619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4620 if (CE) {
4621 int32_t Val = CE->getValue();
4622 if (isNegative && Val == 0)
4623 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4624 }
4625 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4626 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004627
4628 // There can be a trailing '!' on operands that we want as a separate
4629 // '!' Token operand. Handle that here. For example, the compatibilty
4630 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4631 if (Parser.getTok().is(AsmToken::Exclaim)) {
4632 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4633 Parser.getTok().getLoc()));
4634 Parser.Lex(); // Eat exclaim token
4635 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004636 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004637 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004638 // w/ a ':' after the '#', it's just like a plain ':'.
4639 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004640 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004641 case AsmToken::Colon: {
4642 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004643 // FIXME: Check it's an expression prefix,
4644 // e.g. (FOO - :lower16:BAR) isn't legal.
4645 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004646 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004647 return true;
4648
Evan Cheng965b3c72011-01-13 07:58:56 +00004649 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004650 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004651 return true;
4652
Evan Cheng965b3c72011-01-13 07:58:56 +00004653 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004654 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004655 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004656 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004657 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004658 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004659 }
4660}
4661
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004662// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004663// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004664bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004665 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004666
4667 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004668 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004669 Parser.Lex(); // Eat ':'
4670
4671 if (getLexer().isNot(AsmToken::Identifier)) {
4672 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4673 return true;
4674 }
4675
4676 StringRef IDVal = Parser.getTok().getIdentifier();
4677 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004678 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004679 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004680 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004681 } else {
4682 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4683 return true;
4684 }
4685 Parser.Lex();
4686
4687 if (getLexer().isNot(AsmToken::Colon)) {
4688 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4689 return true;
4690 }
4691 Parser.Lex(); // Eat the last ':'
4692 return false;
4693}
4694
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004695/// \brief Given a mnemonic, split out possible predication code and carry
4696/// setting letters to form a canonical mnemonic and flags.
4697//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004698// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004699// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004700StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004701 unsigned &PredicationCode,
4702 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004703 unsigned &ProcessorIMod,
4704 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004705 PredicationCode = ARMCC::AL;
4706 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004707 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004708
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004709 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004710 //
4711 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004712 if ((Mnemonic == "movs" && isThumb()) ||
4713 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4714 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4715 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4716 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004717 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004718 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4719 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004720 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004721 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004722 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4723 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4724 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004725 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004726
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004727 // First, split out any predication code. Ignore mnemonics we know aren't
4728 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004729 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004730 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004731 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004732 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004733 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4734 .Case("eq", ARMCC::EQ)
4735 .Case("ne", ARMCC::NE)
4736 .Case("hs", ARMCC::HS)
4737 .Case("cs", ARMCC::HS)
4738 .Case("lo", ARMCC::LO)
4739 .Case("cc", ARMCC::LO)
4740 .Case("mi", ARMCC::MI)
4741 .Case("pl", ARMCC::PL)
4742 .Case("vs", ARMCC::VS)
4743 .Case("vc", ARMCC::VC)
4744 .Case("hi", ARMCC::HI)
4745 .Case("ls", ARMCC::LS)
4746 .Case("ge", ARMCC::GE)
4747 .Case("lt", ARMCC::LT)
4748 .Case("gt", ARMCC::GT)
4749 .Case("le", ARMCC::LE)
4750 .Case("al", ARMCC::AL)
4751 .Default(~0U);
4752 if (CC != ~0U) {
4753 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4754 PredicationCode = CC;
4755 }
Bill Wendling193961b2010-10-29 23:50:21 +00004756 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004757
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004758 // Next, determine if we have a carry setting bit. We explicitly ignore all
4759 // the instructions we know end in 's'.
4760 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004761 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004762 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4763 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4764 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004765 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004766 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004767 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004768 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004769 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004770 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004771 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4772 CarrySetting = true;
4773 }
4774
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004775 // The "cps" instruction can have a interrupt mode operand which is glued into
4776 // the mnemonic. Check if this is the case, split it and parse the imod op
4777 if (Mnemonic.startswith("cps")) {
4778 // Split out any imod code.
4779 unsigned IMod =
4780 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4781 .Case("ie", ARM_PROC::IE)
4782 .Case("id", ARM_PROC::ID)
4783 .Default(~0U);
4784 if (IMod != ~0U) {
4785 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4786 ProcessorIMod = IMod;
4787 }
4788 }
4789
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004790 // The "it" instruction has the condition mask on the end of the mnemonic.
4791 if (Mnemonic.startswith("it")) {
4792 ITMask = Mnemonic.slice(2, Mnemonic.size());
4793 Mnemonic = Mnemonic.slice(0, 2);
4794 }
4795
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004796 return Mnemonic;
4797}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004798
4799/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4800/// inclusion of carry set or predication code operands.
4801//
4802// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004803void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004804getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4805 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004806 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4807 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004808 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004809 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004810 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004811 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004812 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004813 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004814 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004815 Mnemonic == "mla" || Mnemonic == "smlal" ||
4816 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004817 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004818 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004819 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004820
Tim Northover2c45a382013-06-26 16:52:40 +00004821 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4822 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004823 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004824 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4825 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004826 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4827 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004828 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4829 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4830 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004831 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004832 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004833 } else if (!isThumb()) {
4834 // Some instructions are only predicable in Thumb mode
4835 CanAcceptPredicationCode
4836 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4837 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4838 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4839 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4840 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4841 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4842 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4843 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004844 if (hasV6MOps())
4845 CanAcceptPredicationCode = Mnemonic != "movs";
4846 else
4847 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004848 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004849 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004850}
4851
Jim Grosbach7283da92011-08-16 21:12:37 +00004852bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4853 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004854 // FIXME: This is all horribly hacky. We really need a better way to deal
4855 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004856
4857 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4858 // another does not. Specifically, the MOVW instruction does not. So we
4859 // special case it here and remove the defaulted (non-setting) cc_out
4860 // operand if that's the instruction we're trying to match.
4861 //
4862 // We do this as post-processing of the explicit operands rather than just
4863 // conditionally adding the cc_out in the first place because we need
4864 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004865 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004866 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4867 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4868 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4869 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004870
4871 // Register-register 'add' for thumb does not have a cc_out operand
4872 // when there are only two register operands.
4873 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4874 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4875 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4876 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4877 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004878 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004879 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4880 // have to check the immediate range here since Thumb2 has a variant
4881 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004882 if (((isThumb() && Mnemonic == "add") ||
4883 (isThumbTwo() && Mnemonic == "sub")) &&
4884 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004885 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4886 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4887 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004888 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004889 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004890 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004891 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004892 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4893 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004894 // selecting via the generic "add" mnemonic, so to know that we
4895 // should remove the cc_out operand, we have to explicitly check that
4896 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004897 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4898 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004899 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4900 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4901 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4902 // Nest conditions rather than one big 'if' statement for readability.
4903 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004904 // If both registers are low, we're in an IT block, and the immediate is
4905 // in range, we should use encoding T1 instead, which has a cc_out.
4906 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004907 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004908 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4909 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4910 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004911 // Check against T3. If the second register is the PC, this is an
4912 // alternate form of ADR, which uses encoding T4, so check for that too.
4913 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4914 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4915 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004916
4917 // Otherwise, we use encoding T4, which does not have a cc_out
4918 // operand.
4919 return true;
4920 }
4921
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004922 // The thumb2 multiply instruction doesn't have a CCOut register, so
4923 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4924 // use the 16-bit encoding or not.
4925 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4926 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4927 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4928 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4929 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4930 // If the registers aren't low regs, the destination reg isn't the
4931 // same as one of the source regs, or the cc_out operand is zero
4932 // outside of an IT block, we have to use the 32-bit encoding, so
4933 // remove the cc_out operand.
4934 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4935 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004936 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004937 !inITBlock() ||
4938 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4939 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4940 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4941 static_cast<ARMOperand*>(Operands[4])->getReg())))
4942 return true;
4943
Jim Grosbachefa7e952011-11-15 19:55:16 +00004944 // Also check the 'mul' syntax variant that doesn't specify an explicit
4945 // destination register.
4946 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4947 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4948 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4949 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4950 // If the registers aren't low regs or the cc_out operand is zero
4951 // outside of an IT block, we have to use the 32-bit encoding, so
4952 // remove the cc_out operand.
4953 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4954 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4955 !inITBlock()))
4956 return true;
4957
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004958
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004959
Jim Grosbach4b701af2011-08-24 21:42:27 +00004960 // Register-register 'add/sub' for thumb does not have a cc_out operand
4961 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4962 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4963 // right, this will result in better diagnostics (which operand is off)
4964 // anyway.
4965 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4966 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004967 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4968 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004969 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4970 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4971 (Operands.size() == 6 &&
4972 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004973 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004974
Jim Grosbach7283da92011-08-16 21:12:37 +00004975 return false;
4976}
4977
Joey Goulye8602552013-07-19 16:34:16 +00004978bool ARMAsmParser::shouldOmitPredicateOperand(
4979 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4980 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4981 unsigned RegIdx = 3;
4982 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4983 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4984 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4985 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4986 RegIdx = 4;
4987
4988 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4989 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4990 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4991 ARMMCRegisterClasses[ARM::QPRRegClassID]
4992 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4993 return true;
4994 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004995 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004996}
4997
Jim Grosbach12952fe2011-11-11 23:08:10 +00004998static bool isDataTypeToken(StringRef Tok) {
4999 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5000 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5001 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5002 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5003 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5004 Tok == ".f" || Tok == ".d";
5005}
5006
5007// FIXME: This bit should probably be handled via an explicit match class
5008// in the .td files that matches the suffix instead of having it be
5009// a literal string token the way it is now.
5010static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5011 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5012}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005013static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5014 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005015/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005016bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5017 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005018 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005019 // Apply mnemonic aliases before doing anything else, as the destination
5020 // mnemnonic may include suffices and we want to handle them normally.
5021 // The generic tblgen'erated code does this later, at the start of
5022 // MatchInstructionImpl(), but that's too late for aliases that include
5023 // any sort of suffix.
5024 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005025 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5026 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005027
Jim Grosbachab5830e2011-12-14 02:16:11 +00005028 // First check for the ARM-specific .req directive.
5029 if (Parser.getTok().is(AsmToken::Identifier) &&
5030 Parser.getTok().getIdentifier() == ".req") {
5031 parseDirectiveReq(Name, NameLoc);
5032 // We always return 'error' for this, as we're done with this
5033 // statement and don't need to match the 'instruction."
5034 return true;
5035 }
5036
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005037 // Create the leading tokens for the mnemonic, split by '.' characters.
5038 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005039 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005040
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005041 // Split out the predication code and carry setting flag from the mnemonic.
5042 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005043 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005044 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005045 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005046 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005047 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005048
Jim Grosbach1c171b12011-08-25 17:23:55 +00005049 // In Thumb1, only the branch (B) instruction can be predicated.
5050 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005051 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005052 return Error(NameLoc, "conditional execution not supported in Thumb1");
5053 }
5054
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005055 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5056
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005057 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5058 // is the mask as it will be for the IT encoding if the conditional
5059 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5060 // where the conditional bit0 is zero, the instruction post-processing
5061 // will adjust the mask accordingly.
5062 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005063 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5064 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005065 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005066 return Error(Loc, "too many conditions on IT instruction");
5067 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005068 unsigned Mask = 8;
5069 for (unsigned i = ITMask.size(); i != 0; --i) {
5070 char pos = ITMask[i - 1];
5071 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005072 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005073 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005074 }
5075 Mask >>= 1;
5076 if (ITMask[i - 1] == 't')
5077 Mask |= 8;
5078 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005079 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005080 }
5081
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005082 // FIXME: This is all a pretty gross hack. We should automatically handle
5083 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005084
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005085 // Next, add the CCOut and ConditionCode operands, if needed.
5086 //
5087 // For mnemonics which can ever incorporate a carry setting bit or predication
5088 // code, our matching model involves us always generating CCOut and
5089 // ConditionCode operands to match the mnemonic "as written" and then we let
5090 // the matcher deal with finding the right instruction or generating an
5091 // appropriate error.
5092 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005093 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005094
Jim Grosbach03a8a162011-07-14 22:04:21 +00005095 // If we had a carry-set on an instruction that can't do that, issue an
5096 // error.
5097 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005098 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005099 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005100 "' can not set flags, but 's' suffix specified");
5101 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005102 // If we had a predication code on an instruction that can't do that, issue an
5103 // error.
5104 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005105 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005106 return Error(NameLoc, "instruction '" + Mnemonic +
5107 "' is not predicable, but condition code specified");
5108 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005109
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005110 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005111 if (CanAcceptCarrySet) {
5112 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005113 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005114 Loc));
5115 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005116
5117 // Add the predication code operand, if necessary.
5118 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005119 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5120 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005121 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005122 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005123 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005124
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005125 // Add the processor imod operand, if necessary.
5126 if (ProcessorIMod) {
5127 Operands.push_back(ARMOperand::CreateImm(
5128 MCConstantExpr::Create(ProcessorIMod, getContext()),
5129 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005130 }
5131
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005132 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005133 while (Next != StringRef::npos) {
5134 Start = Next;
5135 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005136 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005137
Jim Grosbach12952fe2011-11-11 23:08:10 +00005138 // Some NEON instructions have an optional datatype suffix that is
5139 // completely ignored. Check for that.
5140 if (isDataTypeToken(ExtraToken) &&
5141 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5142 continue;
5143
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005144 // For for ARM mode generate an error if the .n qualifier is used.
5145 if (ExtraToken == ".n" && !isThumb()) {
5146 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5147 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5148 "arm mode");
5149 }
5150
5151 // The .n qualifier is always discarded as that is what the tables
5152 // and matcher expect. In ARM mode the .w qualifier has no effect,
5153 // so discard it to avoid errors that can be caused by the matcher.
5154 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005155 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5156 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5157 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005158 }
5159
5160 // Read the remaining operands.
5161 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005162 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005163 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005164 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005165 return true;
5166 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005167
5168 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005169 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005170
5171 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005172 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005173 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005174 return true;
5175 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005176 }
5177 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005178
Chris Lattnera2a9d162010-09-11 16:18:25 +00005179 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005180 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005181 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005182 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005183 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005184
Chris Lattner91689c12010-09-08 05:10:46 +00005185 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005186
Jim Grosbach7283da92011-08-16 21:12:37 +00005187 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5188 // do and don't have a cc_out optional-def operand. With some spot-checks
5189 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005190 // parse and adjust accordingly before actually matching. We shouldn't ever
5191 // try to remove a cc_out operand that was explicitly set on the the
5192 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5193 // table driven matcher doesn't fit well with the ARM instruction set.
5194 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005195 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5196 Operands.erase(Operands.begin() + 1);
5197 delete Op;
5198 }
5199
Joey Goulye8602552013-07-19 16:34:16 +00005200 // Some instructions have the same mnemonic, but don't always
5201 // have a predicate. Distinguish them here and delete the
5202 // predicate if needed.
5203 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5204 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5205 Operands.erase(Operands.begin() + 1);
5206 delete Op;
5207 }
5208
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005209 // ARM mode 'blx' need special handling, as the register operand version
5210 // is predicable, but the label operand version is not. So, we can't rely
5211 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005212 // a k_CondCode operand in the list. If we're trying to match the label
5213 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005214 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5215 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5216 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5217 Operands.erase(Operands.begin() + 1);
5218 delete Op;
5219 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005220
Weiming Zhao8f56f882012-11-16 21:55:34 +00005221 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5222 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5223 // a single GPRPair reg operand is used in the .td file to replace the two
5224 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5225 // expressed as a GPRPair, so we have to manually merge them.
5226 // FIXME: We would really like to be able to tablegen'erate this.
5227 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005228 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5229 Mnemonic == "stlexd")) {
5230 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005231 unsigned Idx = isLoad ? 2 : 3;
5232 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5233 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5234
5235 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5236 // Adjust only if Op1 and Op2 are GPRs.
5237 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5238 MRC.contains(Op2->getReg())) {
5239 unsigned Reg1 = Op1->getReg();
5240 unsigned Reg2 = Op2->getReg();
5241 unsigned Rt = MRI->getEncodingValue(Reg1);
5242 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5243
5244 // Rt2 must be Rt + 1 and Rt must be even.
5245 if (Rt + 1 != Rt2 || (Rt & 1)) {
5246 Error(Op2->getStartLoc(), isLoad ?
5247 "destination operands must be sequential" :
5248 "source operands must be sequential");
5249 return true;
5250 }
5251 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5252 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5253 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5254 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5255 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5256 delete Op1;
5257 delete Op2;
5258 }
5259 }
5260
Kevin Enderby78f95722013-07-31 21:05:30 +00005261 // FIXME: As said above, this is all a pretty gross hack. This instruction
5262 // does not fit with other "subs" and tblgen.
5263 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5264 // so the Mnemonic is the original name "subs" and delete the predicate
5265 // operand so it will match the table entry.
5266 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5267 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5268 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5269 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5270 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5271 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5272 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5273 Operands.erase(Operands.begin());
5274 delete Op0;
5275 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5276
5277 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5278 Operands.erase(Operands.begin() + 1);
5279 delete Op1;
5280 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005281 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005282}
5283
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005284// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005285
5286// return 'true' if register list contains non-low GPR registers,
5287// 'false' otherwise. If Reg is in the register list or is HiReg, set
5288// 'containsReg' to true.
5289static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5290 unsigned HiReg, bool &containsReg) {
5291 containsReg = false;
5292 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5293 unsigned OpReg = Inst.getOperand(i).getReg();
5294 if (OpReg == Reg)
5295 containsReg = true;
5296 // Anything other than a low register isn't legal here.
5297 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5298 return true;
5299 }
5300 return false;
5301}
5302
Jim Grosbacha31f2232011-09-07 18:05:34 +00005303// Check if the specified regisgter is in the register list of the inst,
5304// starting at the indicated operand number.
5305static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5306 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5307 unsigned OpReg = Inst.getOperand(i).getReg();
5308 if (OpReg == Reg)
5309 return true;
5310 }
5311 return false;
5312}
5313
Richard Barton8d519fe2013-09-05 14:14:19 +00005314// Return true if instruction has the interesting property of being
5315// allowed in IT blocks, but not being predicable.
5316static bool instIsBreakpoint(const MCInst &Inst) {
5317 return Inst.getOpcode() == ARM::tBKPT ||
5318 Inst.getOpcode() == ARM::BKPT ||
5319 Inst.getOpcode() == ARM::tHLT ||
5320 Inst.getOpcode() == ARM::HLT;
5321
5322}
5323
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005324// FIXME: We would really like to be able to tablegen'erate this.
5325bool ARMAsmParser::
5326validateInstruction(MCInst &Inst,
5327 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005328 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005329 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005330
Jim Grosbached16ec42011-08-29 22:24:09 +00005331 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005332 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005333 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005334 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005335 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005336 if (ITState.FirstCond)
5337 ITState.FirstCond = false;
5338 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005339 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005340 // The instruction must be predicable.
5341 if (!MCID.isPredicable())
5342 return Error(Loc, "instructions in IT block must be predicable");
5343 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005344 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005345 ARMCC::getOppositeCondition(ITState.Cond);
5346 if (Cond != ITCond) {
5347 // Find the condition code Operand to get its SMLoc information.
5348 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005349 for (unsigned I = 1; I < Operands.size(); ++I)
5350 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5351 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005352 return Error(CondLoc, "incorrect condition in IT block; got '" +
5353 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5354 "', but expected '" +
5355 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5356 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005357 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005358 } else if (isThumbTwo() && MCID.isPredicable() &&
5359 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005360 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5361 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005362 return Error(Loc, "predicated instructions must be in IT block");
5363
Tilmann Scheller255722b2013-09-30 16:11:48 +00005364 const unsigned Opcode = Inst.getOpcode();
5365 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005366 case ARM::LDRD:
5367 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005368 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005369 const unsigned RtReg = Inst.getOperand(0).getReg();
5370
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005371 // Rt can't be R14.
5372 if (RtReg == ARM::LR)
5373 return Error(Operands[3]->getStartLoc(),
5374 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005375
5376 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005377 // Rt must be even-numbered.
5378 if ((Rt & 1) == 1)
5379 return Error(Operands[3]->getStartLoc(),
5380 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005381
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005382 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005383 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005384 if (Rt2 != Rt + 1)
5385 return Error(Operands[3]->getStartLoc(),
5386 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005387
5388 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5389 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5390 // For addressing modes with writeback, the base register needs to be
5391 // different from the destination registers.
5392 if (Rn == Rt || Rn == Rt2)
5393 return Error(Operands[3]->getStartLoc(),
5394 "base register needs to be different from destination "
5395 "registers");
5396 }
5397
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005398 return false;
5399 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005400 case ARM::t2LDRDi8:
5401 case ARM::t2LDRD_PRE:
5402 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005403 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005404 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5405 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5406 if (Rt2 == Rt)
5407 return Error(Operands[3]->getStartLoc(),
5408 "destination operands can't be identical");
5409 return false;
5410 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005411 case ARM::STRD: {
5412 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005413 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5414 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005415 if (Rt2 != Rt + 1)
5416 return Error(Operands[3]->getStartLoc(),
5417 "source operands must be sequential");
5418 return false;
5419 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005420 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005421 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005422 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005423 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5424 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005425 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005426 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005427 "source operands must be sequential");
5428 return false;
5429 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005430 case ARM::SBFX:
5431 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005432 // Width must be in range [1, 32-lsb].
5433 unsigned LSB = Inst.getOperand(2).getImm();
5434 unsigned Widthm1 = Inst.getOperand(3).getImm();
5435 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005436 return Error(Operands[5]->getStartLoc(),
5437 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005438 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005439 }
Tim Northover08a86602013-10-22 19:00:39 +00005440 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005441 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005442 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005443 // most cases that are normally illegal for a Thumb1 LDM instruction.
5444 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005445 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005446 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005447 // in the register list.
5448 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005449 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005450 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5451 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005452 bool ListContainsBase;
5453 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5454 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005455 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005456 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005457 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005458 return Error(Operands[2]->getStartLoc(),
5459 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005460 // If we should not have writeback, there must not be a '!'. This is
5461 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005462 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005463 return Error(Operands[3]->getStartLoc(),
5464 "writeback operator '!' not allowed when base register "
5465 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005466
5467 break;
5468 }
Tim Northover08a86602013-10-22 19:00:39 +00005469 case ARM::LDMIA_UPD:
5470 case ARM::LDMDB_UPD:
5471 case ARM::LDMIB_UPD:
5472 case ARM::LDMDA_UPD:
5473 // ARM variants loading and updating the same register are only officially
5474 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5475 if (!hasV7Ops())
5476 break;
5477 // Fallthrough
5478 case ARM::t2LDMIA_UPD:
5479 case ARM::t2LDMDB_UPD:
5480 case ARM::t2STMIA_UPD:
5481 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005482 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005483 return Error(Operands.back()->getStartLoc(),
5484 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005485 break;
5486 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005487 case ARM::sysLDMIA_UPD:
5488 case ARM::sysLDMDA_UPD:
5489 case ARM::sysLDMDB_UPD:
5490 case ARM::sysLDMIB_UPD:
5491 if (!listContainsReg(Inst, 3, ARM::PC))
5492 return Error(Operands[4]->getStartLoc(),
5493 "writeback register only allowed on system LDM "
5494 "if PC in register-list");
5495 break;
5496 case ARM::sysSTMIA_UPD:
5497 case ARM::sysSTMDA_UPD:
5498 case ARM::sysSTMDB_UPD:
5499 case ARM::sysSTMIB_UPD:
5500 return Error(Operands[2]->getStartLoc(),
5501 "system STM cannot have writeback register");
5502 break;
Chad Rosier8513ffb2012-08-30 23:20:38 +00005503 case ARM::tMUL: {
5504 // The second source operand must be the same register as the destination
5505 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005506 //
5507 // In this case, we must directly check the parsed operands because the
5508 // cvtThumbMultiply() function is written in such a way that it guarantees
5509 // this first statement is always true for the new Inst. Essentially, the
5510 // destination is unconditionally copied into the second source operand
5511 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005512 if (Operands.size() == 6 &&
5513 (((ARMOperand*)Operands[3])->getReg() !=
5514 ((ARMOperand*)Operands[5])->getReg()) &&
5515 (((ARMOperand*)Operands[3])->getReg() !=
5516 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005517 return Error(Operands[3]->getStartLoc(),
5518 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005519 }
5520 break;
5521 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005522 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5523 // so only issue a diagnostic for thumb1. The instructions will be
5524 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005525 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005526 bool ListContainsBase;
5527 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005528 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005529 return Error(Operands[2]->getStartLoc(),
5530 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005531 break;
5532 }
5533 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005534 bool ListContainsBase;
5535 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005536 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005537 return Error(Operands[2]->getStartLoc(),
5538 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005539 break;
5540 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005541 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005542 bool ListContainsBase, InvalidLowList;
5543 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5544 0, ListContainsBase);
5545 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005546 return Error(Operands[4]->getStartLoc(),
5547 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005548
5549 // This would be converted to a 32-bit stm, but that's not valid if the
5550 // writeback register is in the list.
5551 if (InvalidLowList && ListContainsBase)
5552 return Error(Operands[4]->getStartLoc(),
5553 "writeback operator '!' not allowed when base register "
5554 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005555 break;
5556 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005557 case ARM::tADDrSP: {
5558 // If the non-SP source operand and the destination operand are not the
5559 // same, we need thumb2 (for the wide encoding), or we have an error.
5560 if (!isThumbTwo() &&
5561 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5562 return Error(Operands[4]->getStartLoc(),
5563 "source register must be the same as destination");
5564 }
5565 break;
5566 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005567 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005568 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005569 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5570 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005571 break;
5572 case ARM::t2B: {
5573 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005574 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5575 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005576 break;
5577 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005578 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005579 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005580 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5581 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005582 break;
5583 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005584 int Op = (Operands[2]->isImm()) ? 2 : 3;
5585 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5586 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005587 break;
5588 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005589 }
5590
5591 return false;
5592}
5593
Jim Grosbach1a747242012-01-23 23:45:44 +00005594static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005595 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005596 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005597 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005598 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5599 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5600 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5601 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5602 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5603 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5604 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5605 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5606 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005607
5608 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005609 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5610 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5611 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5612 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5613 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005614
Jim Grosbach1e946a42012-01-24 00:43:12 +00005615 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5616 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5617 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5618 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5619 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005620
Jim Grosbach1e946a42012-01-24 00:43:12 +00005621 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5622 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5623 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5624 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5625 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005626
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005627 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005628 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5629 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5630 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5631 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5632 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5633 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5634 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5635 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5636 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5637 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5638 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5639 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5640 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5641 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5642 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005643
Jim Grosbach1a747242012-01-23 23:45:44 +00005644 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005645 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5646 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5647 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5648 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5649 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5650 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5651 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5652 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5653 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5654 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5655 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5656 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5657 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5658 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5659 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5660 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5661 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5662 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005663
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005664 // VST4LN
5665 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5666 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5667 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5668 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5669 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5670 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5671 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5672 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5673 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5674 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5675 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5676 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5677 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5678 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5679 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5680
Jim Grosbachda70eac2012-01-24 00:58:13 +00005681 // VST4
5682 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5683 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5684 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5685 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5686 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5687 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5688 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5689 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5690 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5691 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5692 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5693 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5694 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5695 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5696 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5697 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5698 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5699 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005700 }
5701}
5702
Jim Grosbach1a747242012-01-23 23:45:44 +00005703static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005704 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005705 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005706 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005707 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5708 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5709 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5710 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5711 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5712 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5713 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5714 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5715 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005716
5717 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005718 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5719 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5720 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5721 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5722 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5723 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5724 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5725 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5726 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5727 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5728 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5729 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5730 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5731 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5732 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005733
Jim Grosbachb78403c2012-01-24 23:47:04 +00005734 // VLD3DUP
5735 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5736 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5737 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5738 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5739 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5740 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5741 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5742 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5743 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5744 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5745 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5746 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5747 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5748 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5749 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5750 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5751 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5752 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5753
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005754 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005755 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5756 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5757 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5758 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5759 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5760 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5761 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5762 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5763 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5764 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5765 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5766 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5767 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5768 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5769 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005770
5771 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005772 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5773 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5774 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5775 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5776 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5777 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5778 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5779 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5780 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5781 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5782 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5783 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5784 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5785 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5786 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5787 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5788 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5789 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005790
Jim Grosbach14952a02012-01-24 18:37:25 +00005791 // VLD4LN
5792 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5793 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5794 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5795 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5796 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5797 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5798 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5799 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5800 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5801 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5802 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5803 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5804 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5805 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5806 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5807
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005808 // VLD4DUP
5809 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5810 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5811 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5812 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5813 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5814 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5815 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5816 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5817 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5818 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5819 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5820 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5821 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5822 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5823 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5824 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5825 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5826 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5827
Jim Grosbached561fc2012-01-24 00:43:17 +00005828 // VLD4
5829 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5830 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5831 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5832 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5833 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5834 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5835 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5836 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5837 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5838 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5839 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5840 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5841 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5842 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5843 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5844 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5845 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5846 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005847 }
5848}
5849
Jim Grosbachafad0532011-11-10 23:42:14 +00005850bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005851processInstruction(MCInst &Inst,
5852 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5853 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005854 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5855 case ARM::ADDri: {
5856 if (Inst.getOperand(1).getReg() != ARM::PC ||
5857 Inst.getOperand(5).getReg() != 0)
5858 return false;
5859 MCInst TmpInst;
5860 TmpInst.setOpcode(ARM::ADR);
5861 TmpInst.addOperand(Inst.getOperand(0));
5862 TmpInst.addOperand(Inst.getOperand(2));
5863 TmpInst.addOperand(Inst.getOperand(3));
5864 TmpInst.addOperand(Inst.getOperand(4));
5865 Inst = TmpInst;
5866 return true;
5867 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005868 // Aliases for alternate PC+imm syntax of LDR instructions.
5869 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005870 // Select the narrow version if the immediate will fit.
5871 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005872 Inst.getOperand(1).getImm() <= 0xff &&
5873 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5874 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005875 Inst.setOpcode(ARM::tLDRpci);
5876 else
5877 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005878 return true;
5879 case ARM::t2LDRBpcrel:
5880 Inst.setOpcode(ARM::t2LDRBpci);
5881 return true;
5882 case ARM::t2LDRHpcrel:
5883 Inst.setOpcode(ARM::t2LDRHpci);
5884 return true;
5885 case ARM::t2LDRSBpcrel:
5886 Inst.setOpcode(ARM::t2LDRSBpci);
5887 return true;
5888 case ARM::t2LDRSHpcrel:
5889 Inst.setOpcode(ARM::t2LDRSHpci);
5890 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005891 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005892 case ARM::VST1LNdWB_register_Asm_8:
5893 case ARM::VST1LNdWB_register_Asm_16:
5894 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005895 MCInst TmpInst;
5896 // Shuffle the operands around so the lane index operand is in the
5897 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005898 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005899 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005900 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5901 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5902 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5903 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5904 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5905 TmpInst.addOperand(Inst.getOperand(1)); // lane
5906 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5907 TmpInst.addOperand(Inst.getOperand(6));
5908 Inst = TmpInst;
5909 return true;
5910 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005911
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005912 case ARM::VST2LNdWB_register_Asm_8:
5913 case ARM::VST2LNdWB_register_Asm_16:
5914 case ARM::VST2LNdWB_register_Asm_32:
5915 case ARM::VST2LNqWB_register_Asm_16:
5916 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005917 MCInst TmpInst;
5918 // Shuffle the operands around so the lane index operand is in the
5919 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005920 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005921 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005922 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5923 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5924 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5925 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5926 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005927 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5928 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005929 TmpInst.addOperand(Inst.getOperand(1)); // lane
5930 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5931 TmpInst.addOperand(Inst.getOperand(6));
5932 Inst = TmpInst;
5933 return true;
5934 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005935
5936 case ARM::VST3LNdWB_register_Asm_8:
5937 case ARM::VST3LNdWB_register_Asm_16:
5938 case ARM::VST3LNdWB_register_Asm_32:
5939 case ARM::VST3LNqWB_register_Asm_16:
5940 case ARM::VST3LNqWB_register_Asm_32: {
5941 MCInst TmpInst;
5942 // Shuffle the operands around so the lane index operand is in the
5943 // right place.
5944 unsigned Spacing;
5945 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5946 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5947 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5948 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5949 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5950 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 Spacing));
5953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 Spacing * 2));
5955 TmpInst.addOperand(Inst.getOperand(1)); // lane
5956 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5957 TmpInst.addOperand(Inst.getOperand(6));
5958 Inst = TmpInst;
5959 return true;
5960 }
5961
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005962 case ARM::VST4LNdWB_register_Asm_8:
5963 case ARM::VST4LNdWB_register_Asm_16:
5964 case ARM::VST4LNdWB_register_Asm_32:
5965 case ARM::VST4LNqWB_register_Asm_16:
5966 case ARM::VST4LNqWB_register_Asm_32: {
5967 MCInst TmpInst;
5968 // Shuffle the operands around so the lane index operand is in the
5969 // right place.
5970 unsigned Spacing;
5971 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5972 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5973 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5974 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5975 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5976 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5978 Spacing));
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5980 Spacing * 2));
5981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5982 Spacing * 3));
5983 TmpInst.addOperand(Inst.getOperand(1)); // lane
5984 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5985 TmpInst.addOperand(Inst.getOperand(6));
5986 Inst = TmpInst;
5987 return true;
5988 }
5989
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005990 case ARM::VST1LNdWB_fixed_Asm_8:
5991 case ARM::VST1LNdWB_fixed_Asm_16:
5992 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005993 MCInst TmpInst;
5994 // Shuffle the operands around so the lane index operand is in the
5995 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005996 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005997 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005998 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5999 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6000 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6001 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6002 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6003 TmpInst.addOperand(Inst.getOperand(1)); // lane
6004 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6005 TmpInst.addOperand(Inst.getOperand(5));
6006 Inst = TmpInst;
6007 return true;
6008 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006009
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006010 case ARM::VST2LNdWB_fixed_Asm_8:
6011 case ARM::VST2LNdWB_fixed_Asm_16:
6012 case ARM::VST2LNdWB_fixed_Asm_32:
6013 case ARM::VST2LNqWB_fixed_Asm_16:
6014 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006015 MCInst TmpInst;
6016 // Shuffle the operands around so the lane index operand is in the
6017 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006018 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006019 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006020 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6021 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6022 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6023 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6024 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006025 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6026 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006027 TmpInst.addOperand(Inst.getOperand(1)); // lane
6028 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6029 TmpInst.addOperand(Inst.getOperand(5));
6030 Inst = TmpInst;
6031 return true;
6032 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006033
6034 case ARM::VST3LNdWB_fixed_Asm_8:
6035 case ARM::VST3LNdWB_fixed_Asm_16:
6036 case ARM::VST3LNdWB_fixed_Asm_32:
6037 case ARM::VST3LNqWB_fixed_Asm_16:
6038 case ARM::VST3LNqWB_fixed_Asm_32: {
6039 MCInst TmpInst;
6040 // Shuffle the operands around so the lane index operand is in the
6041 // right place.
6042 unsigned Spacing;
6043 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6044 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6045 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6046 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6047 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6048 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6050 Spacing));
6051 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6052 Spacing * 2));
6053 TmpInst.addOperand(Inst.getOperand(1)); // lane
6054 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6055 TmpInst.addOperand(Inst.getOperand(5));
6056 Inst = TmpInst;
6057 return true;
6058 }
6059
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006060 case ARM::VST4LNdWB_fixed_Asm_8:
6061 case ARM::VST4LNdWB_fixed_Asm_16:
6062 case ARM::VST4LNdWB_fixed_Asm_32:
6063 case ARM::VST4LNqWB_fixed_Asm_16:
6064 case ARM::VST4LNqWB_fixed_Asm_32: {
6065 MCInst TmpInst;
6066 // Shuffle the operands around so the lane index operand is in the
6067 // right place.
6068 unsigned Spacing;
6069 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
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)); // Vd
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6076 Spacing));
6077 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6078 Spacing * 2));
6079 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6080 Spacing * 3));
6081 TmpInst.addOperand(Inst.getOperand(1)); // lane
6082 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6083 TmpInst.addOperand(Inst.getOperand(5));
6084 Inst = TmpInst;
6085 return true;
6086 }
6087
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006088 case ARM::VST1LNdAsm_8:
6089 case ARM::VST1LNdAsm_16:
6090 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006091 MCInst TmpInst;
6092 // Shuffle the operands around so the lane index operand is in the
6093 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006094 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006095 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006096 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6097 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6098 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6099 TmpInst.addOperand(Inst.getOperand(1)); // lane
6100 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6101 TmpInst.addOperand(Inst.getOperand(5));
6102 Inst = TmpInst;
6103 return true;
6104 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006105
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006106 case ARM::VST2LNdAsm_8:
6107 case ARM::VST2LNdAsm_16:
6108 case ARM::VST2LNdAsm_32:
6109 case ARM::VST2LNqAsm_16:
6110 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006111 MCInst TmpInst;
6112 // Shuffle the operands around so the lane index operand is in the
6113 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006114 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006115 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006116 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6117 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6118 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6120 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006121 TmpInst.addOperand(Inst.getOperand(1)); // lane
6122 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6123 TmpInst.addOperand(Inst.getOperand(5));
6124 Inst = TmpInst;
6125 return true;
6126 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006127
6128 case ARM::VST3LNdAsm_8:
6129 case ARM::VST3LNdAsm_16:
6130 case ARM::VST3LNdAsm_32:
6131 case ARM::VST3LNqAsm_16:
6132 case ARM::VST3LNqAsm_32: {
6133 MCInst TmpInst;
6134 // Shuffle the operands around so the lane index operand is in the
6135 // right place.
6136 unsigned Spacing;
6137 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6140 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6142 Spacing));
6143 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6144 Spacing * 2));
6145 TmpInst.addOperand(Inst.getOperand(1)); // lane
6146 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6147 TmpInst.addOperand(Inst.getOperand(5));
6148 Inst = TmpInst;
6149 return true;
6150 }
6151
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006152 case ARM::VST4LNdAsm_8:
6153 case ARM::VST4LNdAsm_16:
6154 case ARM::VST4LNdAsm_32:
6155 case ARM::VST4LNqAsm_16:
6156 case ARM::VST4LNqAsm_32: {
6157 MCInst TmpInst;
6158 // Shuffle the operands around so the lane index operand is in the
6159 // right place.
6160 unsigned Spacing;
6161 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6162 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6163 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6164 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6166 Spacing));
6167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6168 Spacing * 2));
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6170 Spacing * 3));
6171 TmpInst.addOperand(Inst.getOperand(1)); // lane
6172 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6173 TmpInst.addOperand(Inst.getOperand(5));
6174 Inst = TmpInst;
6175 return true;
6176 }
6177
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006178 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006179 case ARM::VLD1LNdWB_register_Asm_8:
6180 case ARM::VLD1LNdWB_register_Asm_16:
6181 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006182 MCInst TmpInst;
6183 // Shuffle the operands around so the lane index operand is in the
6184 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006185 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006186 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006187 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6188 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6189 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6190 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6191 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6192 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6193 TmpInst.addOperand(Inst.getOperand(1)); // lane
6194 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6195 TmpInst.addOperand(Inst.getOperand(6));
6196 Inst = TmpInst;
6197 return true;
6198 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006199
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006200 case ARM::VLD2LNdWB_register_Asm_8:
6201 case ARM::VLD2LNdWB_register_Asm_16:
6202 case ARM::VLD2LNdWB_register_Asm_32:
6203 case ARM::VLD2LNqWB_register_Asm_16:
6204 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006205 MCInst TmpInst;
6206 // Shuffle the operands around so the lane index operand is in the
6207 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006208 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006209 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006210 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006213 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6217 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6219 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006220 TmpInst.addOperand(Inst.getOperand(1)); // lane
6221 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6222 TmpInst.addOperand(Inst.getOperand(6));
6223 Inst = TmpInst;
6224 return true;
6225 }
6226
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006227 case ARM::VLD3LNdWB_register_Asm_8:
6228 case ARM::VLD3LNdWB_register_Asm_16:
6229 case ARM::VLD3LNdWB_register_Asm_32:
6230 case ARM::VLD3LNqWB_register_Asm_16:
6231 case ARM::VLD3LNqWB_register_Asm_32: {
6232 MCInst TmpInst;
6233 // Shuffle the operands around so the lane index operand is in the
6234 // right place.
6235 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006236 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006237 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6238 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6239 Spacing));
6240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006241 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006242 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6243 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6244 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6245 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6246 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 Spacing));
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006250 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006251 TmpInst.addOperand(Inst.getOperand(1)); // lane
6252 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6253 TmpInst.addOperand(Inst.getOperand(6));
6254 Inst = TmpInst;
6255 return true;
6256 }
6257
Jim Grosbach14952a02012-01-24 18:37:25 +00006258 case ARM::VLD4LNdWB_register_Asm_8:
6259 case ARM::VLD4LNdWB_register_Asm_16:
6260 case ARM::VLD4LNdWB_register_Asm_32:
6261 case ARM::VLD4LNqWB_register_Asm_16:
6262 case ARM::VLD4LNqWB_register_Asm_32: {
6263 MCInst TmpInst;
6264 // Shuffle the operands around so the lane index operand is in the
6265 // right place.
6266 unsigned Spacing;
6267 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6268 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 Spacing));
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6272 Spacing * 2));
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6274 Spacing * 3));
6275 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6276 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6277 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6278 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6279 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6281 Spacing));
6282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6283 Spacing * 2));
6284 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6285 Spacing * 3));
6286 TmpInst.addOperand(Inst.getOperand(1)); // lane
6287 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6288 TmpInst.addOperand(Inst.getOperand(6));
6289 Inst = TmpInst;
6290 return true;
6291 }
6292
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006293 case ARM::VLD1LNdWB_fixed_Asm_8:
6294 case ARM::VLD1LNdWB_fixed_Asm_16:
6295 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006296 MCInst TmpInst;
6297 // Shuffle the operands around so the lane index operand is in the
6298 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006299 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006300 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006301 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6302 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6303 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6304 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6305 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6306 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6307 TmpInst.addOperand(Inst.getOperand(1)); // lane
6308 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6309 TmpInst.addOperand(Inst.getOperand(5));
6310 Inst = TmpInst;
6311 return true;
6312 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006313
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006314 case ARM::VLD2LNdWB_fixed_Asm_8:
6315 case ARM::VLD2LNdWB_fixed_Asm_16:
6316 case ARM::VLD2LNdWB_fixed_Asm_32:
6317 case ARM::VLD2LNqWB_fixed_Asm_16:
6318 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006319 MCInst TmpInst;
6320 // Shuffle the operands around so the lane index operand is in the
6321 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006322 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006323 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006324 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6326 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006327 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6328 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6329 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6330 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6331 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6333 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006334 TmpInst.addOperand(Inst.getOperand(1)); // lane
6335 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6336 TmpInst.addOperand(Inst.getOperand(5));
6337 Inst = TmpInst;
6338 return true;
6339 }
6340
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006341 case ARM::VLD3LNdWB_fixed_Asm_8:
6342 case ARM::VLD3LNdWB_fixed_Asm_16:
6343 case ARM::VLD3LNdWB_fixed_Asm_32:
6344 case ARM::VLD3LNqWB_fixed_Asm_16:
6345 case ARM::VLD3LNqWB_fixed_Asm_32: {
6346 MCInst TmpInst;
6347 // Shuffle the operands around so the lane index operand is in the
6348 // right place.
6349 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006350 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006351 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6353 Spacing));
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006355 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006356 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6357 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6358 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6359 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6360 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6361 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6362 Spacing));
6363 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006364 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006365 TmpInst.addOperand(Inst.getOperand(1)); // lane
6366 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6367 TmpInst.addOperand(Inst.getOperand(5));
6368 Inst = TmpInst;
6369 return true;
6370 }
6371
Jim Grosbach14952a02012-01-24 18:37:25 +00006372 case ARM::VLD4LNdWB_fixed_Asm_8:
6373 case ARM::VLD4LNdWB_fixed_Asm_16:
6374 case ARM::VLD4LNdWB_fixed_Asm_32:
6375 case ARM::VLD4LNqWB_fixed_Asm_16:
6376 case ARM::VLD4LNqWB_fixed_Asm_32: {
6377 MCInst TmpInst;
6378 // Shuffle the operands around so the lane index operand is in the
6379 // right place.
6380 unsigned Spacing;
6381 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6382 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6383 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6384 Spacing));
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6386 Spacing * 2));
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6388 Spacing * 3));
6389 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6390 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6391 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6392 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6393 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6395 Spacing));
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6397 Spacing * 2));
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing * 3));
6400 TmpInst.addOperand(Inst.getOperand(1)); // lane
6401 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6402 TmpInst.addOperand(Inst.getOperand(5));
6403 Inst = TmpInst;
6404 return true;
6405 }
6406
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006407 case ARM::VLD1LNdAsm_8:
6408 case ARM::VLD1LNdAsm_16:
6409 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006410 MCInst TmpInst;
6411 // Shuffle the operands around so the lane index operand is in the
6412 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006413 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006414 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006415 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6416 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6417 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6418 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6419 TmpInst.addOperand(Inst.getOperand(1)); // lane
6420 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6421 TmpInst.addOperand(Inst.getOperand(5));
6422 Inst = TmpInst;
6423 return true;
6424 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006425
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006426 case ARM::VLD2LNdAsm_8:
6427 case ARM::VLD2LNdAsm_16:
6428 case ARM::VLD2LNdAsm_32:
6429 case ARM::VLD2LNqAsm_16:
6430 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006431 MCInst TmpInst;
6432 // Shuffle the operands around so the lane index operand is in the
6433 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006434 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006435 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006436 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006439 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6441 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6443 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006444 TmpInst.addOperand(Inst.getOperand(1)); // lane
6445 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6446 TmpInst.addOperand(Inst.getOperand(5));
6447 Inst = TmpInst;
6448 return true;
6449 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006450
6451 case ARM::VLD3LNdAsm_8:
6452 case ARM::VLD3LNdAsm_16:
6453 case ARM::VLD3LNdAsm_32:
6454 case ARM::VLD3LNqAsm_16:
6455 case ARM::VLD3LNqAsm_32: {
6456 MCInst TmpInst;
6457 // Shuffle the operands around so the lane index operand is in the
6458 // right place.
6459 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006460 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006461 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 Spacing));
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006465 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006466 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6467 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6468 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing));
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006472 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006473 TmpInst.addOperand(Inst.getOperand(1)); // lane
6474 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6475 TmpInst.addOperand(Inst.getOperand(5));
6476 Inst = TmpInst;
6477 return true;
6478 }
6479
Jim Grosbach14952a02012-01-24 18:37:25 +00006480 case ARM::VLD4LNdAsm_8:
6481 case ARM::VLD4LNdAsm_16:
6482 case ARM::VLD4LNdAsm_32:
6483 case ARM::VLD4LNqAsm_16:
6484 case ARM::VLD4LNqAsm_32: {
6485 MCInst TmpInst;
6486 // Shuffle the operands around so the lane index operand is in the
6487 // right place.
6488 unsigned Spacing;
6489 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6490 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing));
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 Spacing * 2));
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing * 3));
6497 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6498 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6499 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6500 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 Spacing));
6502 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 Spacing * 2));
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 Spacing * 3));
6506 TmpInst.addOperand(Inst.getOperand(1)); // lane
6507 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6508 TmpInst.addOperand(Inst.getOperand(5));
6509 Inst = TmpInst;
6510 return true;
6511 }
6512
Jim Grosbachb78403c2012-01-24 23:47:04 +00006513 // VLD3DUP single 3-element structure to all lanes instructions.
6514 case ARM::VLD3DUPdAsm_8:
6515 case ARM::VLD3DUPdAsm_16:
6516 case ARM::VLD3DUPdAsm_32:
6517 case ARM::VLD3DUPqAsm_8:
6518 case ARM::VLD3DUPqAsm_16:
6519 case ARM::VLD3DUPqAsm_32: {
6520 MCInst TmpInst;
6521 unsigned Spacing;
6522 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6523 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 Spacing));
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 Spacing * 2));
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6531 TmpInst.addOperand(Inst.getOperand(4));
6532 Inst = TmpInst;
6533 return true;
6534 }
6535
6536 case ARM::VLD3DUPdWB_fixed_Asm_8:
6537 case ARM::VLD3DUPdWB_fixed_Asm_16:
6538 case ARM::VLD3DUPdWB_fixed_Asm_32:
6539 case ARM::VLD3DUPqWB_fixed_Asm_8:
6540 case ARM::VLD3DUPqWB_fixed_Asm_16:
6541 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6542 MCInst TmpInst;
6543 unsigned Spacing;
6544 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6545 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing));
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing * 2));
6550 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6551 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6552 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6553 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6554 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6555 TmpInst.addOperand(Inst.getOperand(4));
6556 Inst = TmpInst;
6557 return true;
6558 }
6559
6560 case ARM::VLD3DUPdWB_register_Asm_8:
6561 case ARM::VLD3DUPdWB_register_Asm_16:
6562 case ARM::VLD3DUPdWB_register_Asm_32:
6563 case ARM::VLD3DUPqWB_register_Asm_8:
6564 case ARM::VLD3DUPqWB_register_Asm_16:
6565 case ARM::VLD3DUPqWB_register_Asm_32: {
6566 MCInst TmpInst;
6567 unsigned Spacing;
6568 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6569 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing));
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing * 2));
6574 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6577 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6578 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(5));
6580 Inst = TmpInst;
6581 return true;
6582 }
6583
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006584 // VLD3 multiple 3-element structure instructions.
6585 case ARM::VLD3dAsm_8:
6586 case ARM::VLD3dAsm_16:
6587 case ARM::VLD3dAsm_32:
6588 case ARM::VLD3qAsm_8:
6589 case ARM::VLD3qAsm_16:
6590 case ARM::VLD3qAsm_32: {
6591 MCInst TmpInst;
6592 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006593 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006594 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing));
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing * 2));
6599 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6600 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6601 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6602 TmpInst.addOperand(Inst.getOperand(4));
6603 Inst = TmpInst;
6604 return true;
6605 }
6606
6607 case ARM::VLD3dWB_fixed_Asm_8:
6608 case ARM::VLD3dWB_fixed_Asm_16:
6609 case ARM::VLD3dWB_fixed_Asm_32:
6610 case ARM::VLD3qWB_fixed_Asm_8:
6611 case ARM::VLD3qWB_fixed_Asm_16:
6612 case ARM::VLD3qWB_fixed_Asm_32: {
6613 MCInst TmpInst;
6614 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006615 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006616 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6618 Spacing));
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing * 2));
6621 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6622 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6623 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6624 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6625 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6626 TmpInst.addOperand(Inst.getOperand(4));
6627 Inst = TmpInst;
6628 return true;
6629 }
6630
6631 case ARM::VLD3dWB_register_Asm_8:
6632 case ARM::VLD3dWB_register_Asm_16:
6633 case ARM::VLD3dWB_register_Asm_32:
6634 case ARM::VLD3qWB_register_Asm_8:
6635 case ARM::VLD3qWB_register_Asm_16:
6636 case ARM::VLD3qWB_register_Asm_32: {
6637 MCInst TmpInst;
6638 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006639 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006640 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 Spacing));
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6644 Spacing * 2));
6645 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6646 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6647 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6648 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6649 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6650 TmpInst.addOperand(Inst.getOperand(5));
6651 Inst = TmpInst;
6652 return true;
6653 }
6654
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006655 // VLD4DUP single 3-element structure to all lanes instructions.
6656 case ARM::VLD4DUPdAsm_8:
6657 case ARM::VLD4DUPdAsm_16:
6658 case ARM::VLD4DUPdAsm_32:
6659 case ARM::VLD4DUPqAsm_8:
6660 case ARM::VLD4DUPqAsm_16:
6661 case ARM::VLD4DUPqAsm_32: {
6662 MCInst TmpInst;
6663 unsigned Spacing;
6664 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6665 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 Spacing));
6668 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6669 Spacing * 2));
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6671 Spacing * 3));
6672 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6673 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6674 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6675 TmpInst.addOperand(Inst.getOperand(4));
6676 Inst = TmpInst;
6677 return true;
6678 }
6679
6680 case ARM::VLD4DUPdWB_fixed_Asm_8:
6681 case ARM::VLD4DUPdWB_fixed_Asm_16:
6682 case ARM::VLD4DUPdWB_fixed_Asm_32:
6683 case ARM::VLD4DUPqWB_fixed_Asm_8:
6684 case ARM::VLD4DUPqWB_fixed_Asm_16:
6685 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6686 MCInst TmpInst;
6687 unsigned Spacing;
6688 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6689 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6691 Spacing));
6692 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6693 Spacing * 2));
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6695 Spacing * 3));
6696 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6697 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6698 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6699 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6700 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6701 TmpInst.addOperand(Inst.getOperand(4));
6702 Inst = TmpInst;
6703 return true;
6704 }
6705
6706 case ARM::VLD4DUPdWB_register_Asm_8:
6707 case ARM::VLD4DUPdWB_register_Asm_16:
6708 case ARM::VLD4DUPdWB_register_Asm_32:
6709 case ARM::VLD4DUPqWB_register_Asm_8:
6710 case ARM::VLD4DUPqWB_register_Asm_16:
6711 case ARM::VLD4DUPqWB_register_Asm_32: {
6712 MCInst TmpInst;
6713 unsigned Spacing;
6714 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6715 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6716 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6717 Spacing));
6718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6719 Spacing * 2));
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6721 Spacing * 3));
6722 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6723 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6724 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6725 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6726 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(5));
6728 Inst = TmpInst;
6729 return true;
6730 }
6731
6732 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006733 case ARM::VLD4dAsm_8:
6734 case ARM::VLD4dAsm_16:
6735 case ARM::VLD4dAsm_32:
6736 case ARM::VLD4qAsm_8:
6737 case ARM::VLD4qAsm_16:
6738 case ARM::VLD4qAsm_32: {
6739 MCInst TmpInst;
6740 unsigned Spacing;
6741 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6742 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6744 Spacing));
6745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 Spacing * 2));
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 Spacing * 3));
6749 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6751 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6752 TmpInst.addOperand(Inst.getOperand(4));
6753 Inst = TmpInst;
6754 return true;
6755 }
6756
6757 case ARM::VLD4dWB_fixed_Asm_8:
6758 case ARM::VLD4dWB_fixed_Asm_16:
6759 case ARM::VLD4dWB_fixed_Asm_32:
6760 case ARM::VLD4qWB_fixed_Asm_8:
6761 case ARM::VLD4qWB_fixed_Asm_16:
6762 case ARM::VLD4qWB_fixed_Asm_32: {
6763 MCInst TmpInst;
6764 unsigned Spacing;
6765 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6766 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6767 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6768 Spacing));
6769 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6770 Spacing * 2));
6771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6772 Spacing * 3));
6773 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6774 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6775 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6776 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6777 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6778 TmpInst.addOperand(Inst.getOperand(4));
6779 Inst = TmpInst;
6780 return true;
6781 }
6782
6783 case ARM::VLD4dWB_register_Asm_8:
6784 case ARM::VLD4dWB_register_Asm_16:
6785 case ARM::VLD4dWB_register_Asm_32:
6786 case ARM::VLD4qWB_register_Asm_8:
6787 case ARM::VLD4qWB_register_Asm_16:
6788 case ARM::VLD4qWB_register_Asm_32: {
6789 MCInst TmpInst;
6790 unsigned Spacing;
6791 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6794 Spacing));
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6796 Spacing * 2));
6797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6798 Spacing * 3));
6799 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6800 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6801 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6802 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6803 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6804 TmpInst.addOperand(Inst.getOperand(5));
6805 Inst = TmpInst;
6806 return true;
6807 }
6808
Jim Grosbach1a747242012-01-23 23:45:44 +00006809 // VST3 multiple 3-element structure instructions.
6810 case ARM::VST3dAsm_8:
6811 case ARM::VST3dAsm_16:
6812 case ARM::VST3dAsm_32:
6813 case ARM::VST3qAsm_8:
6814 case ARM::VST3qAsm_16:
6815 case ARM::VST3qAsm_32: {
6816 MCInst TmpInst;
6817 unsigned Spacing;
6818 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6819 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6820 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 Spacing));
6824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6825 Spacing * 2));
6826 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6827 TmpInst.addOperand(Inst.getOperand(4));
6828 Inst = TmpInst;
6829 return true;
6830 }
6831
6832 case ARM::VST3dWB_fixed_Asm_8:
6833 case ARM::VST3dWB_fixed_Asm_16:
6834 case ARM::VST3dWB_fixed_Asm_32:
6835 case ARM::VST3qWB_fixed_Asm_8:
6836 case ARM::VST3qWB_fixed_Asm_16:
6837 case ARM::VST3qWB_fixed_Asm_32: {
6838 MCInst TmpInst;
6839 unsigned Spacing;
6840 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6841 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6842 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6843 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6844 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6845 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6846 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6847 Spacing));
6848 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6849 Spacing * 2));
6850 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6851 TmpInst.addOperand(Inst.getOperand(4));
6852 Inst = TmpInst;
6853 return true;
6854 }
6855
6856 case ARM::VST3dWB_register_Asm_8:
6857 case ARM::VST3dWB_register_Asm_16:
6858 case ARM::VST3dWB_register_Asm_32:
6859 case ARM::VST3qWB_register_Asm_8:
6860 case ARM::VST3qWB_register_Asm_16:
6861 case ARM::VST3qWB_register_Asm_32: {
6862 MCInst TmpInst;
6863 unsigned Spacing;
6864 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6865 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6866 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6867 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6868 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6869 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6870 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6871 Spacing));
6872 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6873 Spacing * 2));
6874 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6875 TmpInst.addOperand(Inst.getOperand(5));
6876 Inst = TmpInst;
6877 return true;
6878 }
6879
Jim Grosbachda70eac2012-01-24 00:58:13 +00006880 // VST4 multiple 3-element structure instructions.
6881 case ARM::VST4dAsm_8:
6882 case ARM::VST4dAsm_16:
6883 case ARM::VST4dAsm_32:
6884 case ARM::VST4qAsm_8:
6885 case ARM::VST4qAsm_16:
6886 case ARM::VST4qAsm_32: {
6887 MCInst TmpInst;
6888 unsigned Spacing;
6889 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6890 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6891 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6892 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6894 Spacing));
6895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6896 Spacing * 2));
6897 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6898 Spacing * 3));
6899 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6900 TmpInst.addOperand(Inst.getOperand(4));
6901 Inst = TmpInst;
6902 return true;
6903 }
6904
6905 case ARM::VST4dWB_fixed_Asm_8:
6906 case ARM::VST4dWB_fixed_Asm_16:
6907 case ARM::VST4dWB_fixed_Asm_32:
6908 case ARM::VST4qWB_fixed_Asm_8:
6909 case ARM::VST4qWB_fixed_Asm_16:
6910 case ARM::VST4qWB_fixed_Asm_32: {
6911 MCInst TmpInst;
6912 unsigned Spacing;
6913 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6914 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6915 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6916 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6917 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6918 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6920 Spacing));
6921 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6922 Spacing * 2));
6923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6924 Spacing * 3));
6925 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6926 TmpInst.addOperand(Inst.getOperand(4));
6927 Inst = TmpInst;
6928 return true;
6929 }
6930
6931 case ARM::VST4dWB_register_Asm_8:
6932 case ARM::VST4dWB_register_Asm_16:
6933 case ARM::VST4dWB_register_Asm_32:
6934 case ARM::VST4qWB_register_Asm_8:
6935 case ARM::VST4qWB_register_Asm_16:
6936 case ARM::VST4qWB_register_Asm_32: {
6937 MCInst TmpInst;
6938 unsigned Spacing;
6939 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6940 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6941 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6942 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6943 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6946 Spacing));
6947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6948 Spacing * 2));
6949 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6950 Spacing * 3));
6951 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6952 TmpInst.addOperand(Inst.getOperand(5));
6953 Inst = TmpInst;
6954 return true;
6955 }
6956
Jim Grosbachad66de12012-04-11 00:15:16 +00006957 // Handle encoding choice for the shift-immediate instructions.
6958 case ARM::t2LSLri:
6959 case ARM::t2LSRri:
6960 case ARM::t2ASRri: {
6961 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6962 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6963 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6964 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6965 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6966 unsigned NewOpc;
6967 switch (Inst.getOpcode()) {
6968 default: llvm_unreachable("unexpected opcode");
6969 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6970 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6971 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6972 }
6973 // The Thumb1 operands aren't in the same order. Awesome, eh?
6974 MCInst TmpInst;
6975 TmpInst.setOpcode(NewOpc);
6976 TmpInst.addOperand(Inst.getOperand(0));
6977 TmpInst.addOperand(Inst.getOperand(5));
6978 TmpInst.addOperand(Inst.getOperand(1));
6979 TmpInst.addOperand(Inst.getOperand(2));
6980 TmpInst.addOperand(Inst.getOperand(3));
6981 TmpInst.addOperand(Inst.getOperand(4));
6982 Inst = TmpInst;
6983 return true;
6984 }
6985 return false;
6986 }
6987
Jim Grosbach485e5622011-12-13 22:45:11 +00006988 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006989 case ARM::t2MOVsr:
6990 case ARM::t2MOVSsr: {
6991 // Which instruction to expand to depends on the CCOut operand and
6992 // whether we're in an IT block if the register operands are low
6993 // registers.
6994 bool isNarrow = false;
6995 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6996 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6997 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6998 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6999 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7000 isNarrow = true;
7001 MCInst TmpInst;
7002 unsigned newOpc;
7003 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7004 default: llvm_unreachable("unexpected opcode!");
7005 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7006 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7007 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7008 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7009 }
7010 TmpInst.setOpcode(newOpc);
7011 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7012 if (isNarrow)
7013 TmpInst.addOperand(MCOperand::CreateReg(
7014 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7015 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7016 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7017 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7018 TmpInst.addOperand(Inst.getOperand(5));
7019 if (!isNarrow)
7020 TmpInst.addOperand(MCOperand::CreateReg(
7021 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7022 Inst = TmpInst;
7023 return true;
7024 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007025 case ARM::t2MOVsi:
7026 case ARM::t2MOVSsi: {
7027 // Which instruction to expand to depends on the CCOut operand and
7028 // whether we're in an IT block if the register operands are low
7029 // registers.
7030 bool isNarrow = false;
7031 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7032 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7033 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7034 isNarrow = true;
7035 MCInst TmpInst;
7036 unsigned newOpc;
7037 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7038 default: llvm_unreachable("unexpected opcode!");
7039 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7040 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7041 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7042 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007043 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007044 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007045 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7046 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007047 TmpInst.setOpcode(newOpc);
7048 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7049 if (isNarrow)
7050 TmpInst.addOperand(MCOperand::CreateReg(
7051 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7052 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007053 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007054 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007055 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7056 TmpInst.addOperand(Inst.getOperand(4));
7057 if (!isNarrow)
7058 TmpInst.addOperand(MCOperand::CreateReg(
7059 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7060 Inst = TmpInst;
7061 return true;
7062 }
7063 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007064 case ARM::ASRr:
7065 case ARM::LSRr:
7066 case ARM::LSLr:
7067 case ARM::RORr: {
7068 ARM_AM::ShiftOpc ShiftTy;
7069 switch(Inst.getOpcode()) {
7070 default: llvm_unreachable("unexpected opcode!");
7071 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7072 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7073 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7074 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7075 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007076 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7077 MCInst TmpInst;
7078 TmpInst.setOpcode(ARM::MOVsr);
7079 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7080 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7081 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7082 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7083 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7084 TmpInst.addOperand(Inst.getOperand(4));
7085 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7086 Inst = TmpInst;
7087 return true;
7088 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007089 case ARM::ASRi:
7090 case ARM::LSRi:
7091 case ARM::LSLi:
7092 case ARM::RORi: {
7093 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007094 switch(Inst.getOpcode()) {
7095 default: llvm_unreachable("unexpected opcode!");
7096 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7097 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7098 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7099 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7100 }
7101 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007102 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007103 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007104 // A shift by 32 should be encoded as 0 when permitted
7105 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7106 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007107 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007108 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007109 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007110 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7111 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007112 if (Opc == ARM::MOVsi)
7113 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007114 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7115 TmpInst.addOperand(Inst.getOperand(4));
7116 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7117 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007118 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007119 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007120 case ARM::RRXi: {
7121 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7122 MCInst TmpInst;
7123 TmpInst.setOpcode(ARM::MOVsi);
7124 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7125 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7126 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7127 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7128 TmpInst.addOperand(Inst.getOperand(3));
7129 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7130 Inst = TmpInst;
7131 return true;
7132 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007133 case ARM::t2LDMIA_UPD: {
7134 // If this is a load of a single register, then we should use
7135 // a post-indexed LDR instruction instead, per the ARM ARM.
7136 if (Inst.getNumOperands() != 5)
7137 return false;
7138 MCInst TmpInst;
7139 TmpInst.setOpcode(ARM::t2LDR_POST);
7140 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7141 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7142 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7143 TmpInst.addOperand(MCOperand::CreateImm(4));
7144 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7145 TmpInst.addOperand(Inst.getOperand(3));
7146 Inst = TmpInst;
7147 return true;
7148 }
7149 case ARM::t2STMDB_UPD: {
7150 // If this is a store of a single register, then we should use
7151 // a pre-indexed STR instruction instead, per the ARM ARM.
7152 if (Inst.getNumOperands() != 5)
7153 return false;
7154 MCInst TmpInst;
7155 TmpInst.setOpcode(ARM::t2STR_PRE);
7156 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7157 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7158 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7159 TmpInst.addOperand(MCOperand::CreateImm(-4));
7160 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7161 TmpInst.addOperand(Inst.getOperand(3));
7162 Inst = TmpInst;
7163 return true;
7164 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007165 case ARM::LDMIA_UPD:
7166 // If this is a load of a single register via a 'pop', then we should use
7167 // a post-indexed LDR instruction instead, per the ARM ARM.
7168 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7169 Inst.getNumOperands() == 5) {
7170 MCInst TmpInst;
7171 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7172 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7173 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7174 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7175 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7176 TmpInst.addOperand(MCOperand::CreateImm(4));
7177 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7178 TmpInst.addOperand(Inst.getOperand(3));
7179 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007180 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007181 }
7182 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007183 case ARM::STMDB_UPD:
7184 // If this is a store of a single register via a 'push', then we should use
7185 // a pre-indexed STR instruction instead, per the ARM ARM.
7186 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7187 Inst.getNumOperands() == 5) {
7188 MCInst TmpInst;
7189 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7190 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7191 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7192 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7193 TmpInst.addOperand(MCOperand::CreateImm(-4));
7194 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7195 TmpInst.addOperand(Inst.getOperand(3));
7196 Inst = TmpInst;
7197 }
7198 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007199 case ARM::t2ADDri12:
7200 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7201 // mnemonic was used (not "addw"), encoding T3 is preferred.
7202 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7203 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7204 break;
7205 Inst.setOpcode(ARM::t2ADDri);
7206 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7207 break;
7208 case ARM::t2SUBri12:
7209 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7210 // mnemonic was used (not "subw"), encoding T3 is preferred.
7211 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7212 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7213 break;
7214 Inst.setOpcode(ARM::t2SUBri);
7215 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7216 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007217 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007218 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007219 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7220 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7221 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007222 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007223 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007224 return true;
7225 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007226 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007227 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007228 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007229 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7230 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7231 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007232 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007233 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007234 return true;
7235 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007236 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007237 case ARM::t2ADDri:
7238 case ARM::t2SUBri: {
7239 // If the destination and first source operand are the same, and
7240 // the flags are compatible with the current IT status, use encoding T2
7241 // instead of T3. For compatibility with the system 'as'. Make sure the
7242 // wide encoding wasn't explicit.
7243 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007244 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007245 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7246 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7247 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7248 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7249 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7250 break;
7251 MCInst TmpInst;
7252 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7253 ARM::tADDi8 : ARM::tSUBi8);
7254 TmpInst.addOperand(Inst.getOperand(0));
7255 TmpInst.addOperand(Inst.getOperand(5));
7256 TmpInst.addOperand(Inst.getOperand(0));
7257 TmpInst.addOperand(Inst.getOperand(2));
7258 TmpInst.addOperand(Inst.getOperand(3));
7259 TmpInst.addOperand(Inst.getOperand(4));
7260 Inst = TmpInst;
7261 return true;
7262 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007263 case ARM::t2ADDrr: {
7264 // If the destination and first source operand are the same, and
7265 // there's no setting of the flags, use encoding T2 instead of T3.
7266 // Note that this is only for ADD, not SUB. This mirrors the system
7267 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7268 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7269 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007270 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7271 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007272 break;
7273 MCInst TmpInst;
7274 TmpInst.setOpcode(ARM::tADDhirr);
7275 TmpInst.addOperand(Inst.getOperand(0));
7276 TmpInst.addOperand(Inst.getOperand(0));
7277 TmpInst.addOperand(Inst.getOperand(2));
7278 TmpInst.addOperand(Inst.getOperand(3));
7279 TmpInst.addOperand(Inst.getOperand(4));
7280 Inst = TmpInst;
7281 return true;
7282 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007283 case ARM::tADDrSP: {
7284 // If the non-SP source operand and the destination operand are not the
7285 // same, we need to use the 32-bit encoding if it's available.
7286 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7287 Inst.setOpcode(ARM::t2ADDrr);
7288 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7289 return true;
7290 }
7291 break;
7292 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007293 case ARM::tB:
7294 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007295 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007296 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007297 return true;
7298 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007299 break;
7300 case ARM::t2B:
7301 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007302 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007303 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007304 return true;
7305 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007306 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007307 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007308 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007309 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007310 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007311 return true;
7312 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007313 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007314 case ARM::tBcc:
7315 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007316 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007317 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007318 return true;
7319 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007320 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007321 case ARM::tLDMIA: {
7322 // If the register list contains any high registers, or if the writeback
7323 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7324 // instead if we're in Thumb2. Otherwise, this should have generated
7325 // an error in validateInstruction().
7326 unsigned Rn = Inst.getOperand(0).getReg();
7327 bool hasWritebackToken =
7328 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7329 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7330 bool listContainsBase;
7331 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7332 (!listContainsBase && !hasWritebackToken) ||
7333 (listContainsBase && hasWritebackToken)) {
7334 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7335 assert (isThumbTwo());
7336 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7337 // If we're switching to the updating version, we need to insert
7338 // the writeback tied operand.
7339 if (hasWritebackToken)
7340 Inst.insert(Inst.begin(),
7341 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007342 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007343 }
7344 break;
7345 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007346 case ARM::tSTMIA_UPD: {
7347 // If the register list contains any high registers, we need to use
7348 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7349 // should have generated an error in validateInstruction().
7350 unsigned Rn = Inst.getOperand(0).getReg();
7351 bool listContainsBase;
7352 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7353 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7354 assert (isThumbTwo());
7355 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007356 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007357 }
7358 break;
7359 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007360 case ARM::tPOP: {
7361 bool listContainsBase;
7362 // If the register list contains any high registers, we need to use
7363 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7364 // should have generated an error in validateInstruction().
7365 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007366 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007367 assert (isThumbTwo());
7368 Inst.setOpcode(ARM::t2LDMIA_UPD);
7369 // Add the base register and writeback operands.
7370 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7371 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007372 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007373 }
7374 case ARM::tPUSH: {
7375 bool listContainsBase;
7376 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007377 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007378 assert (isThumbTwo());
7379 Inst.setOpcode(ARM::t2STMDB_UPD);
7380 // Add the base register and writeback operands.
7381 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7382 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007383 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007384 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007385 case ARM::t2MOVi: {
7386 // If we can use the 16-bit encoding and the user didn't explicitly
7387 // request the 32-bit variant, transform it here.
7388 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007389 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007390 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7391 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7392 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007393 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7394 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7395 // The operands aren't in the same order for tMOVi8...
7396 MCInst TmpInst;
7397 TmpInst.setOpcode(ARM::tMOVi8);
7398 TmpInst.addOperand(Inst.getOperand(0));
7399 TmpInst.addOperand(Inst.getOperand(4));
7400 TmpInst.addOperand(Inst.getOperand(1));
7401 TmpInst.addOperand(Inst.getOperand(2));
7402 TmpInst.addOperand(Inst.getOperand(3));
7403 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007404 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007405 }
7406 break;
7407 }
7408 case ARM::t2MOVr: {
7409 // If we can use the 16-bit encoding and the user didn't explicitly
7410 // request the 32-bit variant, transform it here.
7411 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7412 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7413 Inst.getOperand(2).getImm() == ARMCC::AL &&
7414 Inst.getOperand(4).getReg() == ARM::CPSR &&
7415 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7416 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7417 // The operands aren't the same for tMOV[S]r... (no cc_out)
7418 MCInst TmpInst;
7419 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7420 TmpInst.addOperand(Inst.getOperand(0));
7421 TmpInst.addOperand(Inst.getOperand(1));
7422 TmpInst.addOperand(Inst.getOperand(2));
7423 TmpInst.addOperand(Inst.getOperand(3));
7424 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007425 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007426 }
7427 break;
7428 }
Jim Grosbach82213192011-09-19 20:29:33 +00007429 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007430 case ARM::t2SXTB:
7431 case ARM::t2UXTH:
7432 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007433 // If we can use the 16-bit encoding and the user didn't explicitly
7434 // request the 32-bit variant, transform it here.
7435 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7436 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7437 Inst.getOperand(2).getImm() == 0 &&
7438 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7439 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007440 unsigned NewOpc;
7441 switch (Inst.getOpcode()) {
7442 default: llvm_unreachable("Illegal opcode!");
7443 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7444 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7445 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7446 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7447 }
Jim Grosbach82213192011-09-19 20:29:33 +00007448 // The operands aren't the same for thumb1 (no rotate operand).
7449 MCInst TmpInst;
7450 TmpInst.setOpcode(NewOpc);
7451 TmpInst.addOperand(Inst.getOperand(0));
7452 TmpInst.addOperand(Inst.getOperand(1));
7453 TmpInst.addOperand(Inst.getOperand(3));
7454 TmpInst.addOperand(Inst.getOperand(4));
7455 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007456 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007457 }
7458 break;
7459 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007460 case ARM::MOVsi: {
7461 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007462 // rrx shifts and asr/lsr of #32 is encoded as 0
7463 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7464 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007465 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7466 // Shifting by zero is accepted as a vanilla 'MOVr'
7467 MCInst TmpInst;
7468 TmpInst.setOpcode(ARM::MOVr);
7469 TmpInst.addOperand(Inst.getOperand(0));
7470 TmpInst.addOperand(Inst.getOperand(1));
7471 TmpInst.addOperand(Inst.getOperand(3));
7472 TmpInst.addOperand(Inst.getOperand(4));
7473 TmpInst.addOperand(Inst.getOperand(5));
7474 Inst = TmpInst;
7475 return true;
7476 }
7477 return false;
7478 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007479 case ARM::ANDrsi:
7480 case ARM::ORRrsi:
7481 case ARM::EORrsi:
7482 case ARM::BICrsi:
7483 case ARM::SUBrsi:
7484 case ARM::ADDrsi: {
7485 unsigned newOpc;
7486 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7487 if (SOpc == ARM_AM::rrx) return false;
7488 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007489 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007490 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7491 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7492 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7493 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7494 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7495 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7496 }
7497 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007498 // The exception is for right shifts, where 0 == 32
7499 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7500 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007501 MCInst TmpInst;
7502 TmpInst.setOpcode(newOpc);
7503 TmpInst.addOperand(Inst.getOperand(0));
7504 TmpInst.addOperand(Inst.getOperand(1));
7505 TmpInst.addOperand(Inst.getOperand(2));
7506 TmpInst.addOperand(Inst.getOperand(4));
7507 TmpInst.addOperand(Inst.getOperand(5));
7508 TmpInst.addOperand(Inst.getOperand(6));
7509 Inst = TmpInst;
7510 return true;
7511 }
7512 return false;
7513 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007514 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007515 case ARM::t2IT: {
7516 // The mask bits for all but the first condition are represented as
7517 // the low bit of the condition code value implies 't'. We currently
7518 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007519 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007520 MCOperand &MO = Inst.getOperand(1);
7521 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007522 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007523 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007524 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007525 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007526 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007527 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007528 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007529
7530 // Set up the IT block state according to the IT instruction we just
7531 // matched.
7532 assert(!inITBlock() && "nested IT blocks?!");
7533 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7534 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7535 ITState.CurPosition = 0;
7536 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007537 break;
7538 }
Richard Bartona39625e2012-07-09 16:12:24 +00007539 case ARM::t2LSLrr:
7540 case ARM::t2LSRrr:
7541 case ARM::t2ASRrr:
7542 case ARM::t2SBCrr:
7543 case ARM::t2RORrr:
7544 case ARM::t2BICrr:
7545 {
Richard Bartond5660372012-07-09 16:14:28 +00007546 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007547 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7548 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7549 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007550 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7551 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007552 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7553 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7554 unsigned NewOpc;
7555 switch (Inst.getOpcode()) {
7556 default: llvm_unreachable("unexpected opcode");
7557 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7558 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7559 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7560 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7561 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7562 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7563 }
7564 MCInst TmpInst;
7565 TmpInst.setOpcode(NewOpc);
7566 TmpInst.addOperand(Inst.getOperand(0));
7567 TmpInst.addOperand(Inst.getOperand(5));
7568 TmpInst.addOperand(Inst.getOperand(1));
7569 TmpInst.addOperand(Inst.getOperand(2));
7570 TmpInst.addOperand(Inst.getOperand(3));
7571 TmpInst.addOperand(Inst.getOperand(4));
7572 Inst = TmpInst;
7573 return true;
7574 }
7575 return false;
7576 }
7577 case ARM::t2ANDrr:
7578 case ARM::t2EORrr:
7579 case ARM::t2ADCrr:
7580 case ARM::t2ORRrr:
7581 {
Richard Bartond5660372012-07-09 16:14:28 +00007582 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007583 // These instructions are special in that they are commutable, so shorter encodings
7584 // are available more often.
7585 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7586 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7587 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7588 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007589 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7590 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007591 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7592 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7593 unsigned NewOpc;
7594 switch (Inst.getOpcode()) {
7595 default: llvm_unreachable("unexpected opcode");
7596 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7597 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7598 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7599 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7600 }
7601 MCInst TmpInst;
7602 TmpInst.setOpcode(NewOpc);
7603 TmpInst.addOperand(Inst.getOperand(0));
7604 TmpInst.addOperand(Inst.getOperand(5));
7605 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7606 TmpInst.addOperand(Inst.getOperand(1));
7607 TmpInst.addOperand(Inst.getOperand(2));
7608 } else {
7609 TmpInst.addOperand(Inst.getOperand(2));
7610 TmpInst.addOperand(Inst.getOperand(1));
7611 }
7612 TmpInst.addOperand(Inst.getOperand(3));
7613 TmpInst.addOperand(Inst.getOperand(4));
7614 Inst = TmpInst;
7615 return true;
7616 }
7617 return false;
7618 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007619 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007620 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007621}
7622
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007623unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7624 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7625 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007626 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007627 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007628 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7629 assert(MCID.hasOptionalDef() &&
7630 "optionally flag setting instruction missing optional def operand");
7631 assert(MCID.NumOperands == Inst.getNumOperands() &&
7632 "operand count mismatch!");
7633 // Find the optional-def operand (cc_out).
7634 unsigned OpNo;
7635 for (OpNo = 0;
7636 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7637 ++OpNo)
7638 ;
7639 // If we're parsing Thumb1, reject it completely.
7640 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7641 return Match_MnemonicFail;
7642 // If we're parsing Thumb2, which form is legal depends on whether we're
7643 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007644 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7645 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007646 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007647 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7648 inITBlock())
7649 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007650 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007651 // Some high-register supporting Thumb1 encodings only allow both registers
7652 // to be from r0-r7 when in Thumb2.
7653 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7654 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7655 isARMLowRegister(Inst.getOperand(2).getReg()))
7656 return Match_RequiresThumb2;
7657 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007658 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007659 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7660 isARMLowRegister(Inst.getOperand(1).getReg()))
7661 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007662 return Match_Success;
7663}
7664
Jim Grosbach5117ef72012-04-24 22:40:08 +00007665static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007666bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007667MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007668 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007669 MCStreamer &Out, unsigned &ErrorInfo,
7670 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007671 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007672 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007673
Chad Rosier2f480a82012-10-12 22:53:36 +00007674 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007675 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007676 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007677 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007678 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007679 // Context sensitive operand constraints aren't handled by the matcher,
7680 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007681 if (validateInstruction(Inst, Operands)) {
7682 // Still progress the IT block, otherwise one wrong condition causes
7683 // nasty cascading errors.
7684 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007685 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007686 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007687
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007688 { // processInstruction() updates inITBlock state, we need to save it away
7689 bool wasInITBlock = inITBlock();
7690
7691 // Some instructions need post-processing to, for example, tweak which
7692 // encoding is selected. Loop on it while changes happen so the
7693 // individual transformations can chain off each other. E.g.,
7694 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7695 while (processInstruction(Inst, Operands))
7696 ;
7697
7698 // Only after the instruction is fully processed, we can validate it
7699 if (wasInITBlock && hasV8Ops() && isThumb() &&
7700 !isV8EligibleForIT(&Inst, 2)) {
7701 Warning(IDLoc, "deprecated instruction in IT block");
7702 }
7703 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007704
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007705 // Only move forward at the very end so that everything in validate
7706 // and process gets a consistent answer about whether we're in an IT
7707 // block.
7708 forwardITPosition();
7709
Jim Grosbach82f76d12012-01-25 19:52:01 +00007710 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7711 // doesn't actually encode.
7712 if (Inst.getOpcode() == ARM::ITasm)
7713 return false;
7714
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007715 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007716 Out.EmitInstruction(Inst);
7717 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007718 case Match_MissingFeature: {
7719 assert(ErrorInfo && "Unknown missing feature!");
7720 // Special case the error message for the very common case where only
7721 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7722 std::string Msg = "instruction requires:";
7723 unsigned Mask = 1;
7724 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7725 if (ErrorInfo & Mask) {
7726 Msg += " ";
7727 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7728 }
7729 Mask <<= 1;
7730 }
7731 return Error(IDLoc, Msg);
7732 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007733 case Match_InvalidOperand: {
7734 SMLoc ErrorLoc = IDLoc;
7735 if (ErrorInfo != ~0U) {
7736 if (ErrorInfo >= Operands.size())
7737 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007738
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007739 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7740 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7741 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007742
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007743 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007744 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007745 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007746 return Error(IDLoc, "invalid instruction",
7747 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007748 case Match_RequiresNotITBlock:
7749 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007750 case Match_RequiresITBlock:
7751 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007752 case Match_RequiresV6:
7753 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7754 case Match_RequiresThumb2:
7755 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007756 case Match_ImmRange0_15: {
7757 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7758 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7759 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7760 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00007761 case Match_ImmRange0_239: {
7762 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7763 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7764 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7765 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007766 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007767
Eric Christopher91d7b902010-10-29 09:26:59 +00007768 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007769}
7770
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007771/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007772bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7773 StringRef IDVal = DirectiveID.getIdentifier();
7774 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007775 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007776 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007777 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007778 else if (IDVal == ".arm")
7779 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007780 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007781 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007782 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007783 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007784 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007785 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007786 else if (IDVal == ".unreq")
7787 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007788 else if (IDVal == ".arch")
7789 return parseDirectiveArch(DirectiveID.getLoc());
7790 else if (IDVal == ".eabi_attribute")
7791 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien8cbb80d2013-10-28 17:51:12 +00007792 else if (IDVal == ".cpu")
7793 return parseDirectiveCPU(DirectiveID.getLoc());
7794 else if (IDVal == ".fpu")
7795 return parseDirectiveFPU(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007796 else if (IDVal == ".fnstart")
7797 return parseDirectiveFnStart(DirectiveID.getLoc());
7798 else if (IDVal == ".fnend")
7799 return parseDirectiveFnEnd(DirectiveID.getLoc());
7800 else if (IDVal == ".cantunwind")
7801 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7802 else if (IDVal == ".personality")
7803 return parseDirectivePersonality(DirectiveID.getLoc());
7804 else if (IDVal == ".handlerdata")
7805 return parseDirectiveHandlerData(DirectiveID.getLoc());
7806 else if (IDVal == ".setfp")
7807 return parseDirectiveSetFP(DirectiveID.getLoc());
7808 else if (IDVal == ".pad")
7809 return parseDirectivePad(DirectiveID.getLoc());
7810 else if (IDVal == ".save")
7811 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7812 else if (IDVal == ".vsave")
7813 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00007814 else if (IDVal == ".inst")
7815 return parseDirectiveInst(DirectiveID.getLoc());
7816 else if (IDVal == ".inst.n")
7817 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7818 else if (IDVal == ".inst.w")
7819 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
Kevin Enderbyccab3172009-09-15 00:27:25 +00007820 return true;
7821}
7822
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007823/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007824/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007825bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007826 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7827 for (;;) {
7828 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007829 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007830 return true;
7831
Eric Christopherbf7bc492013-01-09 03:52:05 +00007832 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007833
7834 if (getLexer().is(AsmToken::EndOfStatement))
7835 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007836
Kevin Enderbyccab3172009-09-15 00:27:25 +00007837 // FIXME: Improve diagnostic.
7838 if (getLexer().isNot(AsmToken::Comma))
7839 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007840 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007841 }
7842 }
7843
Sean Callanana83fd7d2010-01-19 20:27:46 +00007844 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007845 return false;
7846}
7847
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007848/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007849/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007850bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007851 if (getLexer().isNot(AsmToken::EndOfStatement))
7852 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007853 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007854
Tim Northovera2292d02013-06-10 23:20:58 +00007855 if (!hasThumb())
7856 return Error(L, "target does not support Thumb mode");
7857
Jim Grosbach7f882392011-12-07 18:04:19 +00007858 if (!isThumb())
7859 SwitchMode();
7860 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7861 return false;
7862}
7863
7864/// parseDirectiveARM
7865/// ::= .arm
7866bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7867 if (getLexer().isNot(AsmToken::EndOfStatement))
7868 return Error(L, "unexpected token in directive");
7869 Parser.Lex();
7870
Tim Northovera2292d02013-06-10 23:20:58 +00007871 if (!hasARM())
7872 return Error(L, "target does not support ARM mode");
7873
Jim Grosbach7f882392011-12-07 18:04:19 +00007874 if (isThumb())
7875 SwitchMode();
7876 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007877 return false;
7878}
7879
Tim Northover1744d0a2013-10-25 12:49:50 +00007880void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7881 if (NextSymbolIsThumb) {
7882 getParser().getStreamer().EmitThumbFunc(Symbol);
7883 NextSymbolIsThumb = false;
7884 }
7885}
7886
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007887/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007888/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007889bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007890 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7891 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007892
Jim Grosbach1152cc02011-12-21 22:30:16 +00007893 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007894 // ELF doesn't
7895 if (isMachO) {
7896 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007897 if (Tok.isNot(AsmToken::EndOfStatement)) {
7898 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7899 return Error(L, "unexpected token in .thumb_func directive");
Tim Northover1744d0a2013-10-25 12:49:50 +00007900 MCSymbol *Func =
7901 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7902 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00007903 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00007904 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007905 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007906 }
7907
Jim Grosbach1152cc02011-12-21 22:30:16 +00007908 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007909 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007910
Tim Northover1744d0a2013-10-25 12:49:50 +00007911 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00007912
Kevin Enderby146dcf22009-10-15 20:48:48 +00007913 return false;
7914}
7915
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007916/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007917/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007918bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007919 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007920 if (Tok.isNot(AsmToken::Identifier))
7921 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007922 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007923 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007924 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007925 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007926 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007927 else
7928 return Error(L, "unrecognized syntax mode in .syntax directive");
7929
7930 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007931 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007932 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007933
7934 // TODO tell the MC streamer the mode
7935 // getParser().getStreamer().Emit???();
7936 return false;
7937}
7938
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007939/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007940/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007941bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007942 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007943 if (Tok.isNot(AsmToken::Integer))
7944 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007945 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007946 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007947 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007948 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007949 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007950 else
7951 return Error(L, "invalid operand to .code directive");
7952
7953 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007954 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007955 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007956
Evan Cheng284b4672011-07-08 22:36:29 +00007957 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007958 if (!hasThumb())
7959 return Error(L, "target does not support Thumb mode");
7960
Jim Grosbachf471ac32011-09-06 18:46:23 +00007961 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007962 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007963 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007964 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007965 if (!hasARM())
7966 return Error(L, "target does not support ARM mode");
7967
Jim Grosbachf471ac32011-09-06 18:46:23 +00007968 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007969 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007970 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007971 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007972
Kevin Enderby146dcf22009-10-15 20:48:48 +00007973 return false;
7974}
7975
Jim Grosbachab5830e2011-12-14 02:16:11 +00007976/// parseDirectiveReq
7977/// ::= name .req registername
7978bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7979 Parser.Lex(); // Eat the '.req' token.
7980 unsigned Reg;
7981 SMLoc SRegLoc, ERegLoc;
7982 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007983 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007984 return Error(SRegLoc, "register name expected");
7985 }
7986
7987 // Shouldn't be anything else.
7988 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007989 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007990 return Error(Parser.getTok().getLoc(),
7991 "unexpected input in .req directive.");
7992 }
7993
7994 Parser.Lex(); // Consume the EndOfStatement
7995
7996 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7997 return Error(SRegLoc, "redefinition of '" + Name +
7998 "' does not match original.");
7999
8000 return false;
8001}
8002
8003/// parseDirectiveUneq
8004/// ::= .unreq registername
8005bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8006 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008007 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008008 return Error(L, "unexpected input in .unreq directive.");
8009 }
8010 RegisterReqs.erase(Parser.getTok().getIdentifier());
8011 Parser.Lex(); // Eat the identifier.
8012 return false;
8013}
8014
Jason W Kim135d2442011-12-20 17:38:12 +00008015/// parseDirectiveArch
8016/// ::= .arch token
8017bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008018 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8019
8020 unsigned ID = StringSwitch<unsigned>(Arch)
8021#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8022 .Case(NAME, ARM::ID)
8023#include "MCTargetDesc/ARMArchName.def"
8024 .Default(ARM::INVALID_ARCH);
8025
8026 if (ID == ARM::INVALID_ARCH)
8027 return Error(L, "Unknown arch name");
8028
8029 getTargetStreamer().emitArch(ID);
8030 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008031}
8032
8033/// parseDirectiveEabiAttr
8034/// ::= .eabi_attribute int, int
8035bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Logan Chien8cbb80d2013-10-28 17:51:12 +00008036 if (Parser.getTok().isNot(AsmToken::Integer))
8037 return Error(L, "integer expected");
8038 int64_t Tag = Parser.getTok().getIntVal();
8039 Parser.Lex(); // eat tag integer
8040
8041 if (Parser.getTok().isNot(AsmToken::Comma))
8042 return Error(L, "comma expected");
8043 Parser.Lex(); // skip comma
8044
8045 L = Parser.getTok().getLoc();
8046 if (Parser.getTok().isNot(AsmToken::Integer))
8047 return Error(L, "integer expected");
8048 int64_t Value = Parser.getTok().getIntVal();
8049 Parser.Lex(); // eat value integer
8050
8051 getTargetStreamer().emitAttribute(Tag, Value);
8052 return false;
8053}
8054
8055/// parseDirectiveCPU
8056/// ::= .cpu str
8057bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8058 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8059 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8060 return false;
8061}
8062
8063/// parseDirectiveFPU
8064/// ::= .fpu str
8065bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8066 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8067
8068 unsigned ID = StringSwitch<unsigned>(FPU)
8069#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8070#include "ARMFPUName.def"
8071 .Default(ARM::INVALID_FPU);
8072
8073 if (ID == ARM::INVALID_FPU)
8074 return Error(L, "Unknown FPU name");
8075
8076 getTargetStreamer().emitFPU(ID);
8077 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008078}
8079
Logan Chien4ea23b52013-05-10 16:17:24 +00008080/// parseDirectiveFnStart
8081/// ::= .fnstart
8082bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8083 if (FnStartLoc.isValid()) {
8084 Error(L, ".fnstart starts before the end of previous one");
8085 Error(FnStartLoc, "previous .fnstart starts here");
8086 return true;
8087 }
8088
8089 FnStartLoc = L;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008090 getTargetStreamer().emitFnStart();
Logan Chien4ea23b52013-05-10 16:17:24 +00008091 return false;
8092}
8093
8094/// parseDirectiveFnEnd
8095/// ::= .fnend
8096bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8097 // Check the ordering of unwind directives
8098 if (!FnStartLoc.isValid())
8099 return Error(L, ".fnstart must precede .fnend directive");
8100
8101 // Reset the unwind directives parser state
8102 resetUnwindDirectiveParserState();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008103 getTargetStreamer().emitFnEnd();
Logan Chien4ea23b52013-05-10 16:17:24 +00008104 return false;
8105}
8106
8107/// parseDirectiveCantUnwind
8108/// ::= .cantunwind
8109bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8110 // Check the ordering of unwind directives
8111 CantUnwindLoc = L;
8112 if (!FnStartLoc.isValid())
8113 return Error(L, ".fnstart must precede .cantunwind directive");
8114 if (HandlerDataLoc.isValid()) {
8115 Error(L, ".cantunwind can't be used with .handlerdata directive");
8116 Error(HandlerDataLoc, ".handlerdata was specified here");
8117 return true;
8118 }
8119 if (PersonalityLoc.isValid()) {
8120 Error(L, ".cantunwind can't be used with .personality directive");
8121 Error(PersonalityLoc, ".personality was specified here");
8122 return true;
8123 }
8124
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008125 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008126 return false;
8127}
8128
8129/// parseDirectivePersonality
8130/// ::= .personality name
8131bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8132 // Check the ordering of unwind directives
8133 PersonalityLoc = L;
8134 if (!FnStartLoc.isValid())
8135 return Error(L, ".fnstart must precede .personality directive");
8136 if (CantUnwindLoc.isValid()) {
8137 Error(L, ".personality can't be used with .cantunwind directive");
8138 Error(CantUnwindLoc, ".cantunwind was specified here");
8139 return true;
8140 }
8141 if (HandlerDataLoc.isValid()) {
8142 Error(L, ".personality must precede .handlerdata directive");
8143 Error(HandlerDataLoc, ".handlerdata was specified here");
8144 return true;
8145 }
8146
8147 // Parse the name of the personality routine
8148 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8149 Parser.eatToEndOfStatement();
8150 return Error(L, "unexpected input in .personality directive.");
8151 }
8152 StringRef Name(Parser.getTok().getIdentifier());
8153 Parser.Lex();
8154
8155 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008156 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008157 return false;
8158}
8159
8160/// parseDirectiveHandlerData
8161/// ::= .handlerdata
8162bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8163 // Check the ordering of unwind directives
8164 HandlerDataLoc = L;
8165 if (!FnStartLoc.isValid())
8166 return Error(L, ".fnstart must precede .personality directive");
8167 if (CantUnwindLoc.isValid()) {
8168 Error(L, ".handlerdata can't be used with .cantunwind directive");
8169 Error(CantUnwindLoc, ".cantunwind was specified here");
8170 return true;
8171 }
8172
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008173 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008174 return false;
8175}
8176
8177/// parseDirectiveSetFP
8178/// ::= .setfp fpreg, spreg [, offset]
8179bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8180 // Check the ordering of unwind directives
8181 if (!FnStartLoc.isValid())
8182 return Error(L, ".fnstart must precede .setfp directive");
8183 if (HandlerDataLoc.isValid())
8184 return Error(L, ".setfp must precede .handlerdata directive");
8185
8186 // Parse fpreg
8187 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8188 int NewFPReg = tryParseRegister();
8189 if (NewFPReg == -1)
8190 return Error(NewFPRegLoc, "frame pointer register expected");
8191
8192 // Consume comma
8193 if (!Parser.getTok().is(AsmToken::Comma))
8194 return Error(Parser.getTok().getLoc(), "comma expected");
8195 Parser.Lex(); // skip comma
8196
8197 // Parse spreg
8198 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8199 int NewSPReg = tryParseRegister();
8200 if (NewSPReg == -1)
8201 return Error(NewSPRegLoc, "stack pointer register expected");
8202
8203 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8204 return Error(NewSPRegLoc,
8205 "register should be either $sp or the latest fp register");
8206
8207 // Update the frame pointer register
8208 FPReg = NewFPReg;
8209
8210 // Parse offset
8211 int64_t Offset = 0;
8212 if (Parser.getTok().is(AsmToken::Comma)) {
8213 Parser.Lex(); // skip comma
8214
8215 if (Parser.getTok().isNot(AsmToken::Hash) &&
8216 Parser.getTok().isNot(AsmToken::Dollar)) {
8217 return Error(Parser.getTok().getLoc(), "'#' expected");
8218 }
8219 Parser.Lex(); // skip hash token.
8220
8221 const MCExpr *OffsetExpr;
8222 SMLoc ExLoc = Parser.getTok().getLoc();
8223 SMLoc EndLoc;
8224 if (getParser().parseExpression(OffsetExpr, EndLoc))
8225 return Error(ExLoc, "malformed setfp offset");
8226 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8227 if (!CE)
8228 return Error(ExLoc, "setfp offset must be an immediate");
8229
8230 Offset = CE->getValue();
8231 }
8232
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008233 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8234 static_cast<unsigned>(NewSPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008235 return false;
8236}
8237
8238/// parseDirective
8239/// ::= .pad offset
8240bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8241 // Check the ordering of unwind directives
8242 if (!FnStartLoc.isValid())
8243 return Error(L, ".fnstart must precede .pad directive");
8244 if (HandlerDataLoc.isValid())
8245 return Error(L, ".pad must precede .handlerdata directive");
8246
8247 // Parse the offset
8248 if (Parser.getTok().isNot(AsmToken::Hash) &&
8249 Parser.getTok().isNot(AsmToken::Dollar)) {
8250 return Error(Parser.getTok().getLoc(), "'#' expected");
8251 }
8252 Parser.Lex(); // skip hash token.
8253
8254 const MCExpr *OffsetExpr;
8255 SMLoc ExLoc = Parser.getTok().getLoc();
8256 SMLoc EndLoc;
8257 if (getParser().parseExpression(OffsetExpr, EndLoc))
8258 return Error(ExLoc, "malformed pad offset");
8259 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8260 if (!CE)
8261 return Error(ExLoc, "pad offset must be an immediate");
8262
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008263 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008264 return false;
8265}
8266
8267/// parseDirectiveRegSave
8268/// ::= .save { registers }
8269/// ::= .vsave { registers }
8270bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8271 // Check the ordering of unwind directives
8272 if (!FnStartLoc.isValid())
8273 return Error(L, ".fnstart must precede .save or .vsave directives");
8274 if (HandlerDataLoc.isValid())
8275 return Error(L, ".save or .vsave must precede .handlerdata directive");
8276
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008277 // RAII object to make sure parsed operands are deleted.
8278 struct CleanupObject {
8279 SmallVector<MCParsedAsmOperand *, 1> Operands;
8280 ~CleanupObject() {
8281 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8282 delete Operands[I];
8283 }
8284 } CO;
8285
Logan Chien4ea23b52013-05-10 16:17:24 +00008286 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008287 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008288 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008289 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008290 if (!IsVector && !Op->isRegList())
8291 return Error(L, ".save expects GPR registers");
8292 if (IsVector && !Op->isDPRRegList())
8293 return Error(L, ".vsave expects DPR registers");
8294
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008295 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008296 return false;
8297}
8298
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008299/// parseDirectiveInst
8300/// ::= .inst opcode [, ...]
8301/// ::= .inst.n opcode [, ...]
8302/// ::= .inst.w opcode [, ...]
8303bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8304 int Width;
8305
8306 if (isThumb()) {
8307 switch (Suffix) {
8308 case 'n':
8309 Width = 2;
8310 break;
8311 case 'w':
8312 Width = 4;
8313 break;
8314 default:
8315 Parser.eatToEndOfStatement();
8316 return Error(Loc, "cannot determine Thumb instruction size, "
8317 "use inst.n/inst.w instead");
8318 }
8319 } else {
8320 if (Suffix) {
8321 Parser.eatToEndOfStatement();
8322 return Error(Loc, "width suffixes are invalid in ARM mode");
8323 }
8324 Width = 4;
8325 }
8326
8327 if (getLexer().is(AsmToken::EndOfStatement)) {
8328 Parser.eatToEndOfStatement();
8329 return Error(Loc, "expected expression following directive");
8330 }
8331
8332 for (;;) {
8333 const MCExpr *Expr;
8334
8335 if (getParser().parseExpression(Expr))
8336 return Error(Loc, "expected expression");
8337
8338 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8339 if (!Value)
8340 return Error(Loc, "expected constant expression");
8341
8342 switch (Width) {
8343 case 2:
8344 if (Value->getValue() > 0xffff)
8345 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8346 break;
8347 case 4:
8348 if (Value->getValue() > 0xffffffff)
8349 return Error(Loc,
8350 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8351 break;
8352 default:
8353 llvm_unreachable("only supported widths are 2 and 4");
8354 }
8355
8356 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8357
8358 if (getLexer().is(AsmToken::EndOfStatement))
8359 break;
8360
8361 if (getLexer().isNot(AsmToken::Comma))
8362 return Error(Loc, "unexpected token in directive");
8363
8364 Parser.Lex();
8365 }
8366
8367 Parser.Lex();
8368 return false;
8369}
8370
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008371/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008372extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008373 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8374 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008375}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008376
Chris Lattner3e4582a2010-09-06 19:11:01 +00008377#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008378#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008379#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008380#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008381
8382// Define this matcher function after the auto-generated include so we
8383// have the match class enum definitions.
8384unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8385 unsigned Kind) {
8386 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8387 // If the kind is a token for a literal immediate, check if our asm
8388 // operand matches. This is for InstAliases which have a fixed-value
8389 // immediate in the syntax.
8390 if (Kind == MCK__35_0 && Op->isImm()) {
8391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8392 if (!CE)
8393 return Match_InvalidOperand;
8394 if (CE->getValue() == 0)
8395 return Match_Success;
8396 }
8397 return Match_InvalidOperand;
8398}