blob: 6431b75c5480e1722775ab2facc1ea463255dc8a [file] [log] [blame]
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng94b95502011-07-26 00:24:13 +000010#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMMCExpr.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000013#include "llvm/MC/MCParser/MCAsmLexer.h"
14#include "llvm/MC/MCParser/MCAsmParser.h"
15#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Rafael Espindola64695402011-05-16 16:17:21 +000016#include "llvm/MC/MCAsmInfo.h"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000017#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000018#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCInst.h"
Evan Cheng78011362011-08-23 20:15:21 +000021#include "llvm/MC/MCInstrDesc.h"
Evan Cheng94b95502011-07-26 00:24:13 +000022#include "llvm/MC/MCRegisterInfo.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000023#include "llvm/MC/MCSubtargetInfo.h"
Evan Cheng94b95502011-07-26 00:24:13 +000024#include "llvm/MC/MCTargetAsmParser.h"
Jim Grosbach89df9962011-08-26 21:43:41 +000025#include "llvm/Support/MathExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000027#include "llvm/Support/TargetRegistry.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000028#include "llvm/Support/raw_ostream.h"
Jim Grosbach11e03e72011-08-22 18:50:36 +000029#include "llvm/ADT/BitVector.h"
Benjamin Kramer75ca4b92011-07-08 21:06:23 +000030#include "llvm/ADT/OwningPtr.h"
Evan Cheng94b95502011-07-26 00:24:13 +000031#include "llvm/ADT/STLExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000032#include "llvm/ADT/SmallVector.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000033#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000034#include "llvm/ADT/Twine.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000035
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattner3a697562010-10-28 17:20:03 +000038namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000041
Jim Grosbach7636bf62011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbach98b05a52011-11-30 01:09:44 +000043
Evan Cheng94b95502011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Chengffc0e732011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbach28f08c92012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000048
Jim Grosbacha39cda72011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000052 struct {
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
60
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
64 // handling.
65
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
70 } ITState;
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha1109882011-09-02 23:22:08 +000072 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
79 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000080
81
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
Benjamin Kramer362a05a2012-04-15 17:04:27 +000085 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
88 }
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
92 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000093
Jim Grosbach1355cf12011-07-26 17:10:22 +000094 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d87ec22011-07-26 20:41:24 +000096 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000097 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +000098 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000099 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach9a70df92011-12-07 18:04:19 +0000105 bool parseDirectiveARM(SMLoc L);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbacha39cda72011-12-14 02:16:11 +0000109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
Jason W Kimd7c9e082011-12-20 17:38:12 +0000111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +0000113
Jim Grosbach1355cf12011-07-26 17:10:22 +0000114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach89df9962011-08-26 21:43:41 +0000115 bool &CarrySetting, unsigned &ProcessorIMod,
116 StringRef &ITMask);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +0000118 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +0000119
Evan Chengebdeeab2011-07-08 01:53:10 +0000120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +0000122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000123 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000124 bool isThumbOne() const {
Evan Chengffc0e732011-07-09 05:47:46 +0000125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000126 }
Jim Grosbach47a0d522011-08-16 20:45:50 +0000127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
129 }
Jim Grosbach194bd892011-08-16 22:20:01 +0000130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
132 }
James Molloyacad68d2011-09-28 14:21:38 +0000133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
135 }
Evan Cheng32869202011-07-08 22:36:29 +0000136 void SwitchMode() {
Evan Chengffc0e732011-07-09 05:47:46 +0000137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
Evan Cheng32869202011-07-08 22:36:29 +0000139 }
James Molloyacad68d2011-09-28 14:21:38 +0000140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
142 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000143
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000144 /// @name Auto-generated Match Functions
145 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000146
Chris Lattner0692ee62010-09-06 19:11:01 +0000147#define GET_ASSEMBLER_HEADER
148#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000149
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000150 /// }
151
Jim Grosbach89df9962011-08-26 21:43:41 +0000152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000153 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000155 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000159 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000160 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000161 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000162 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000163 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000164 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachf6c05252011-07-21 17:23:04 +0000165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
169 }
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
172 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach580f4a92011-07-25 22:20:28 +0000174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach251bf252011-08-10 21:56:18 +0000178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9d390362011-10-03 23:38:36 +0000179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach862019c2011-10-18 23:02:30 +0000180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7636bf62011-12-02 00:35:16 +0000181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000182
183 // Asm Match Converter Methods
Chad Rosier756d2cc2012-08-31 22:12:31 +0000184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbacheeec0252011-09-08 00:39:19 +0000187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachee2c2a42011-09-16 21:55:56 +0000189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson9ab0f252011-08-26 20:43:14 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbach548340c2011-08-11 19:22:40 +0000195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach7b8f46c2011-08-11 21:17:22 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000200 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000202 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000203 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000204 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000205 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000206 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000207 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach623a4542011-08-10 22:42:16 +0000211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000212 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach88ae2bc2011-08-19 22:07:46 +0000213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000214 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +0000215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000216 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +0000217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000218 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +0000219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000220 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +0000221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach189610f2011-07-26 18:25:39 +0000222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach83ec8772011-11-10 23:42:14 +0000224 bool processInstruction(MCInst &Inst,
Jim Grosbachf8fce712011-08-11 17:35:48 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachd54b4e62011-08-16 21:12:37 +0000226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach189610f2011-07-26 18:25:39 +0000228
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000229public:
Jim Grosbach47a0d522011-08-16 20:45:50 +0000230 enum ARMMatchResultTy {
Jim Grosbach194bd892011-08-16 22:20:01 +0000231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000232 Match_RequiresNotITBlock,
Jim Grosbach194bd892011-08-16 22:20:01 +0000233 Match_RequiresV6,
Jim Grosbach70c9bf32012-06-22 23:56:48 +0000234 Match_RequiresThumb2,
235#define GET_OPERAND_DIAGNOSTIC_TYPES
236#include "ARMGenAsmMatcher.inc"
237
Jim Grosbach47a0d522011-08-16 20:45:50 +0000238 };
239
Evan Chengffc0e732011-07-09 05:47:46 +0000240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng94b95502011-07-26 00:24:13 +0000241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000242 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng32869202011-07-08 22:36:29 +0000243
Jim Grosbach28f08c92012-03-05 19:33:30 +0000244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
246
Evan Chengebdeeab2011-07-08 01:53:10 +0000247 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000249
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
Evan Chengebdeeab2011-07-08 01:53:10 +0000252 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000253
Jim Grosbach1355cf12011-07-26 17:10:22 +0000254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
256 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbach189610f2011-07-26 18:25:39 +0000257 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000258 bool ParseDirective(AsmToken DirectiveID);
259
Jim Grosbach47a0d522011-08-16 20:45:50 +0000260 unsigned checkTargetMatchPredicate(MCInst &Inst);
261
Jim Grosbach1355cf12011-07-26 17:10:22 +0000262 bool MatchAndEmitInstruction(SMLoc IDLoc,
263 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
264 MCStreamer &Out);
Chad Rosier038f3e32012-09-03 18:47:45 +0000265
Chad Rosier5d637d72012-09-05 01:15:43 +0000266 unsigned getMCInstOperandNum(unsigned Kind, MCInst &Inst,
Chad Rosier038f3e32012-09-03 18:47:45 +0000267 const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier2cc97de2012-09-03 20:31:23 +0000268 unsigned OperandNum, unsigned &NumMCOperands) {
Chad Rosier5d637d72012-09-05 01:15:43 +0000269 return getMCInstOperandNumImpl(Kind, Inst, Operands, OperandNum, NumMCOperands);
Chad Rosier038f3e32012-09-03 18:47:45 +0000270 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000271};
Jim Grosbach16c74252010-10-29 14:46:02 +0000272} // end anonymous namespace
273
Chris Lattner3a697562010-10-28 17:20:03 +0000274namespace {
275
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000276/// ARMOperand - Instances of this class represent a parsed ARM machine
277/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000278class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000279 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000280 k_CondCode,
281 k_CCOut,
282 k_ITCondMask,
283 k_CoprocNum,
284 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000285 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000286 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000287 k_MemBarrierOpt,
288 k_Memory,
289 k_PostIndexRegister,
290 k_MSRMask,
291 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000292 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000293 k_Register,
294 k_RegisterList,
295 k_DPRRegisterList,
296 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000297 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000298 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000299 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000300 k_ShiftedRegister,
301 k_ShiftedImmediate,
302 k_ShifterImmediate,
303 k_RotateImmediate,
304 k_BitfieldDescriptor,
305 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000306 } Kind;
307
Sean Callanan76264762010-04-02 22:27:05 +0000308 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000309 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000310
311 union {
312 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000313 ARMCC::CondCodes Val;
314 } CC;
315
316 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000317 unsigned Val;
318 } Cop;
319
320 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000321 unsigned Val;
322 } CoprocOption;
323
324 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000325 unsigned Mask:4;
326 } ITMask;
327
328 struct {
329 ARM_MB::MemBOpt Val;
330 } MBOpt;
331
332 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000333 ARM_PROC::IFlags Val;
334 } IFlags;
335
336 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000337 unsigned Val;
338 } MMask;
339
340 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000341 const char *Data;
342 unsigned Length;
343 } Tok;
344
345 struct {
346 unsigned RegNum;
347 } Reg;
348
Jim Grosbach862019c2011-10-18 23:02:30 +0000349 // A vector register list is a sequential list of 1 to 4 registers.
350 struct {
351 unsigned RegNum;
352 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000353 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000354 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000355 } VectorList;
356
Bill Wendling8155e5b2010-11-06 22:19:43 +0000357 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000358 unsigned Val;
359 } VectorIndex;
360
361 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000362 const MCExpr *Val;
363 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000364
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000365 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000366 struct {
367 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000368 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
369 // was specified.
370 const MCConstantExpr *OffsetImm; // Offset immediate value
371 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
372 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000373 unsigned ShiftImm; // shift for OffsetReg.
374 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000375 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000376 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000377 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000378
379 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000380 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000381 bool isAdd;
382 ARM_AM::ShiftOpc ShiftTy;
383 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000384 } PostIdxReg;
385
386 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000387 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000388 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000389 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000390 struct {
391 ARM_AM::ShiftOpc ShiftTy;
392 unsigned SrcReg;
393 unsigned ShiftReg;
394 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000395 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000396 struct {
397 ARM_AM::ShiftOpc ShiftTy;
398 unsigned SrcReg;
399 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000400 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000401 struct {
402 unsigned Imm;
403 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000404 struct {
405 unsigned LSB;
406 unsigned Width;
407 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000408 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000409
Bill Wendling146018f2010-11-06 21:42:12 +0000410 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
411public:
Sean Callanan76264762010-04-02 22:27:05 +0000412 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
413 Kind = o.Kind;
414 StartLoc = o.StartLoc;
415 EndLoc = o.EndLoc;
416 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000417 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000418 CC = o.CC;
419 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000420 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000421 ITMask = o.ITMask;
422 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000423 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000424 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000425 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000426 case k_CCOut:
427 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000428 Reg = o.Reg;
429 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000430 case k_RegisterList:
431 case k_DPRRegisterList:
432 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000433 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000434 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000435 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000436 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000437 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000438 VectorList = o.VectorList;
439 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000440 case k_CoprocNum:
441 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000442 Cop = o.Cop;
443 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000444 case k_CoprocOption:
445 CoprocOption = o.CoprocOption;
446 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000447 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000448 Imm = o.Imm;
449 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000450 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000451 MBOpt = o.MBOpt;
452 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000453 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000454 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000455 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000456 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000457 PostIdxReg = o.PostIdxReg;
458 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000459 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000460 MMask = o.MMask;
461 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000462 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000463 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000464 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000465 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000466 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000467 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000468 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000469 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000470 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000471 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000472 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000473 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000474 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000475 RotImm = o.RotImm;
476 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000477 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000478 Bitfield = o.Bitfield;
479 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000480 case k_VectorIndex:
481 VectorIndex = o.VectorIndex;
482 break;
Sean Callanan76264762010-04-02 22:27:05 +0000483 }
484 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000485
Sean Callanan76264762010-04-02 22:27:05 +0000486 /// getStartLoc - Get the location of the first token of this operand.
487 SMLoc getStartLoc() const { return StartLoc; }
488 /// getEndLoc - Get the location of the last token of this operand.
489 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier4a6203a2012-09-21 20:51:43 +0000490 /// getLocRange - Get the range between the first and last token of this
491 /// operand.
Benjamin Kramer362a05a2012-04-15 17:04:27 +0000492 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
493
Daniel Dunbar8462b302010-08-11 06:36:53 +0000494 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000495 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000496 return CC.Val;
497 }
498
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000499 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000500 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000501 return Cop.Val;
502 }
503
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000504 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000505 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000506 return StringRef(Tok.Data, Tok.Length);
507 }
508
509 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000510 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000511 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000512 }
513
Bill Wendling5fa22a12010-11-09 23:28:44 +0000514 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000515 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
516 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000517 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000518 }
519
Kevin Enderbycfe07242009-10-13 22:19:02 +0000520 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000521 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000522 return Imm.Val;
523 }
524
Jim Grosbach460a9052011-10-07 23:56:00 +0000525 unsigned getVectorIndex() const {
526 assert(Kind == k_VectorIndex && "Invalid access!");
527 return VectorIndex.Val;
528 }
529
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000530 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000531 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000532 return MBOpt.Val;
533 }
534
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000535 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000536 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000537 return IFlags.Val;
538 }
539
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000540 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000541 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000542 return MMask.Val;
543 }
544
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000545 bool isCoprocNum() const { return Kind == k_CoprocNum; }
546 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000547 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000548 bool isCondCode() const { return Kind == k_CondCode; }
549 bool isCCOut() const { return Kind == k_CCOut; }
550 bool isITMask() const { return Kind == k_ITCondMask; }
551 bool isITCondCode() const { return Kind == k_CondCode; }
552 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000553 bool isFPImm() const {
554 if (!isImm()) return false;
555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
556 if (!CE) return false;
557 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
558 return Val != -1;
559 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000560 bool isFBits16() const {
561 if (!isImm()) return false;
562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
563 if (!CE) return false;
564 int64_t Value = CE->getValue();
565 return Value >= 0 && Value <= 16;
566 }
567 bool isFBits32() const {
568 if (!isImm()) return false;
569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
570 if (!CE) return false;
571 int64_t Value = CE->getValue();
572 return Value >= 1 && Value <= 32;
573 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000574 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000575 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000576 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
577 if (!CE) return false;
578 int64_t Value = CE->getValue();
579 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
580 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000581 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000582 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
584 if (!CE) return false;
585 int64_t Value = CE->getValue();
586 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
587 }
588 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000589 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000590 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
591 if (!CE) return false;
592 int64_t Value = CE->getValue();
593 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
594 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000595 bool isImm0_508s4Neg() const {
596 if (!isImm()) return false;
597 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
598 if (!CE) return false;
599 int64_t Value = -CE->getValue();
600 // explicitly exclude zero. we want that to use the normal 0_508 version.
601 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
602 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000603 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000604 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
606 if (!CE) return false;
607 int64_t Value = CE->getValue();
608 return Value >= 0 && Value < 256;
609 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000610 bool isImm0_4095() const {
611 if (!isImm()) return false;
612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
613 if (!CE) return false;
614 int64_t Value = CE->getValue();
615 return Value >= 0 && Value < 4096;
616 }
617 bool isImm0_4095Neg() const {
618 if (!isImm()) return false;
619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
620 if (!CE) return false;
621 int64_t Value = -CE->getValue();
622 return Value > 0 && Value < 4096;
623 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000624 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000625 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
627 if (!CE) return false;
628 int64_t Value = CE->getValue();
629 return Value >= 0 && Value < 2;
630 }
631 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000632 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
634 if (!CE) return false;
635 int64_t Value = CE->getValue();
636 return Value >= 0 && Value < 4;
637 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000638 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000639 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
641 if (!CE) return false;
642 int64_t Value = CE->getValue();
643 return Value >= 0 && Value < 8;
644 }
645 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000646 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
648 if (!CE) return false;
649 int64_t Value = CE->getValue();
650 return Value >= 0 && Value < 16;
651 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000652 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000653 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int64_t Value = CE->getValue();
657 return Value >= 0 && Value < 32;
658 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000659 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000660 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
664 return Value >= 0 && Value < 64;
665 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000666 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000667 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
671 return Value == 8;
672 }
673 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000674 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return Value == 16;
679 }
680 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000681 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value == 32;
686 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000687 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000688 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return Value > 0 && Value <= 8;
693 }
694 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000695 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return Value > 0 && Value <= 16;
700 }
701 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000702 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return Value > 0 && Value <= 32;
707 }
708 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000709 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = CE->getValue();
713 return Value > 0 && Value <= 64;
714 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000715 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000716 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = CE->getValue();
720 return Value > 0 && Value < 8;
721 }
722 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000723 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value > 0 && Value < 16;
728 }
729 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000730 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 if (!CE) return false;
733 int64_t Value = CE->getValue();
734 return Value > 0 && Value < 32;
735 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000736 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000737 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
739 if (!CE) return false;
740 int64_t Value = CE->getValue();
741 return Value > 0 && Value < 17;
742 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000743 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000744 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
746 if (!CE) return false;
747 int64_t Value = CE->getValue();
748 return Value > 0 && Value < 33;
749 }
Jim Grosbachee10ff82011-11-10 19:18:01 +0000750 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000751 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000752 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
753 if (!CE) return false;
754 int64_t Value = CE->getValue();
755 return Value >= 0 && Value < 33;
756 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000757 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000758 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
760 if (!CE) return false;
761 int64_t Value = CE->getValue();
762 return Value >= 0 && Value < 65536;
763 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000764 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000765 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
767 // If it's not a constant expression, it'll generate a fixup and be
768 // handled later.
769 if (!CE) return true;
770 int64_t Value = CE->getValue();
771 return Value >= 0 && Value < 65536;
772 }
Jim Grosbached838482011-07-26 16:24:27 +0000773 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value >= 0 && Value <= 0xffffff;
779 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000780 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value > 0 && Value < 33;
786 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000787 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000788 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value >= 0 && Value < 32;
793 }
794 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000795 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value > 0 && Value <= 32;
800 }
Jiangning Liu1fb27ec2012-08-02 08:13:13 +0000801 bool isAdrLabel() const {
802 // If we have an immediate that's not a constant, treat it as a label
803 // reference needing a fixup. If it is a constant, but it can't fit
804 // into shift immediate encoding, we reject it.
805 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
806 else return (isARMSOImm() || isARMSOImmNeg());
807 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000808 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return ARM_AM::getSOImmVal(Value) != -1;
814 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000815 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000816 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return ARM_AM::getSOImmVal(~Value) != -1;
821 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000822 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000823 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000827 // Only use this when not representable as a plain so_imm.
828 return ARM_AM::getSOImmVal(Value) == -1 &&
829 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000830 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000831 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000832 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
834 if (!CE) return false;
835 int64_t Value = CE->getValue();
836 return ARM_AM::getT2SOImmVal(Value) != -1;
837 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000838 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000839 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
841 if (!CE) return false;
842 int64_t Value = CE->getValue();
843 return ARM_AM::getT2SOImmVal(~Value) != -1;
844 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000845 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000846 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000847 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
848 if (!CE) return false;
849 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000850 // Only use this when not representable as a plain so_imm.
851 return ARM_AM::getT2SOImmVal(Value) == -1 &&
852 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000853 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000854 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000855 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
857 if (!CE) return false;
858 int64_t Value = CE->getValue();
859 return Value == 1 || Value == 0;
860 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000861 bool isReg() const { return Kind == k_Register; }
862 bool isRegList() const { return Kind == k_RegisterList; }
863 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
864 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
865 bool isToken() const { return Kind == k_Token; }
866 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000867 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000868 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
869 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
870 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
871 bool isRotImm() const { return Kind == k_RotateImmediate; }
872 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
873 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000874 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000875 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000876 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000877 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000878 if (!isMem())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000879 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000880 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000881 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
882 (alignOK || Memory.Alignment == 0);
883 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000884 bool isMemPCRelImm12() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000885 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000886 return false;
887 // Base register must be PC.
888 if (Memory.BaseRegNum != ARM::PC)
889 return false;
890 // Immediate offset in range [-4095, 4095].
891 if (!Memory.OffsetImm) return true;
892 int64_t Val = Memory.OffsetImm->getValue();
893 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
894 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000895 bool isAlignedMemory() const {
896 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000897 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000898 bool isAddrMode2() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000899 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000900 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000901 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000902 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000903 if (!Memory.OffsetImm) return true;
904 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000905 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000906 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000907 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000908 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000909 // Immediate offset in range [-4095, 4095].
910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
911 if (!CE) return false;
912 int64_t Val = CE->getValue();
913 return Val > -4096 && Val < 4096;
914 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000915 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000916 // If we have an immediate that's not a constant, treat it as a label
917 // reference needing a fixup. If it is a constant, it's something else
918 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000919 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000920 return true;
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000921 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000922 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000923 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000924 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000925 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000926 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000927 if (!Memory.OffsetImm) return true;
928 int64_t Val = Memory.OffsetImm->getValue();
Silviu Barangaca3cd412012-05-11 09:10:54 +0000929 // The #-0 offset is encoded as INT32_MIN, and we have to check
930 // for this too.
931 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000932 }
933 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000934 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000935 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000936 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000937 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
938 // Immediate offset in range [-255, 255].
939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000942 // Special case, #-0 is INT32_MIN.
943 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000944 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000945 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000946 // If we have an immediate that's not a constant, treat it as a label
947 // reference needing a fixup. If it is a constant, it's something else
948 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000949 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000950 return true;
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000951 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000952 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000953 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000954 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000955 if (!Memory.OffsetImm) return true;
956 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000957 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000958 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000959 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000960 bool isMemTBB() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000961 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000962 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000963 return false;
964 return true;
965 }
966 bool isMemTBH() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000967 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000968 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
969 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000970 return false;
971 return true;
972 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000973 bool isMemRegOffset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000974 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000975 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000976 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000977 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000978 bool isT2MemRegOffset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000979 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000980 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000981 return false;
982 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000983 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000984 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000985 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000986 return false;
987 return true;
988 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000989 bool isMemThumbRR() const {
990 // Thumb reg+reg addressing is simple. Just two registers, a base and
991 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000992 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000993 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000994 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000995 return isARMLowRegister(Memory.BaseRegNum) &&
996 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +0000997 }
998 bool isMemThumbRIs4() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000999 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001000 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +00001001 return false;
1002 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001003 if (!Memory.OffsetImm) return true;
1004 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001005 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1006 }
Jim Grosbach38466302011-08-19 18:55:51 +00001007 bool isMemThumbRIs2() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001008 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001009 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +00001010 return false;
1011 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001012 if (!Memory.OffsetImm) return true;
1013 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +00001014 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1015 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001016 bool isMemThumbRIs1() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001017 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001018 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001019 return false;
1020 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001021 if (!Memory.OffsetImm) return true;
1022 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001023 return Val >= 0 && Val <= 31;
1024 }
Jim Grosbachecd85892011-08-19 18:13:48 +00001025 bool isMemThumbSPI() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001026 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001027 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +00001028 return false;
1029 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001030 if (!Memory.OffsetImm) return true;
1031 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001032 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001033 }
Jim Grosbacha77295d2011-09-08 22:07:06 +00001034 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +00001035 // If we have an immediate that's not a constant, treat it as a label
1036 // reference needing a fixup. If it is a constant, it's something else
1037 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001038 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +00001039 return true;
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001040 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +00001041 return false;
1042 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001043 if (!Memory.OffsetImm) return true;
1044 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liufd652df2012-08-02 08:29:50 +00001045 // Special case, #-0 is INT32_MIN.
1046 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbacha77295d2011-09-08 22:07:06 +00001047 }
Jim Grosbachb6aed502011-09-09 18:37:27 +00001048 bool isMemImm0_1020s4Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001049 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +00001050 return false;
1051 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001052 if (!Memory.OffsetImm) return true;
1053 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001054 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1055 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001056 bool isMemImm8Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001057 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001058 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001059 // Base reg of PC isn't allowed for these encodings.
1060 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001061 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001062 if (!Memory.OffsetImm) return true;
1063 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001064 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001065 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001066 bool isMemPosImm8Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001067 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001068 return false;
1069 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001070 if (!Memory.OffsetImm) return true;
1071 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001072 return Val >= 0 && Val < 256;
1073 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001074 bool isMemNegImm8Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001075 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001076 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001077 // Base reg of PC isn't allowed for these encodings.
1078 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001079 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001080 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001081 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001082 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001083 }
1084 bool isMemUImm12Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001085 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001086 return false;
1087 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001088 if (!Memory.OffsetImm) return true;
1089 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001090 return (Val >= 0 && Val < 4096);
1091 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001092 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001093 // If we have an immediate that's not a constant, treat it as a label
1094 // reference needing a fixup. If it is a constant, it's something else
1095 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001096 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001097 return true;
1098
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001099 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001100 return false;
1101 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001102 if (!Memory.OffsetImm) return true;
1103 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001104 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001105 }
1106 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001107 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001108 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1109 if (!CE) return false;
1110 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001111 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001112 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001113 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001114 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001115 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1116 if (!CE) return false;
1117 int64_t Val = CE->getValue();
1118 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1119 (Val == INT32_MIN);
1120 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001121
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001122 bool isMSRMask() const { return Kind == k_MSRMask; }
1123 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001124
Jim Grosbach0e387b22011-10-17 22:26:03 +00001125 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001126 bool isSingleSpacedVectorList() const {
1127 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1128 }
1129 bool isDoubleSpacedVectorList() const {
1130 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1131 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001132 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001133 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001134 return VectorList.Count == 1;
1135 }
1136
Jim Grosbach28f08c92012-03-05 19:33:30 +00001137 bool isVecListDPair() const {
1138 if (!isSingleSpacedVectorList()) return false;
1139 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1140 .contains(VectorList.RegNum));
1141 }
1142
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001143 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001144 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001145 return VectorList.Count == 3;
1146 }
1147
Jim Grosbachb6310312011-10-21 20:35:01 +00001148 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001149 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001150 return VectorList.Count == 4;
1151 }
1152
Jim Grosbachc3384c92012-03-05 21:43:40 +00001153 bool isVecListDPairSpaced() const {
Kevin Enderby9f2e1602012-03-20 17:41:51 +00001154 if (isSingleSpacedVectorList()) return false;
Jim Grosbachc3384c92012-03-05 21:43:40 +00001155 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1156 .contains(VectorList.RegNum));
1157 }
1158
Jim Grosbachc387fc62012-01-23 23:20:46 +00001159 bool isVecListThreeQ() const {
1160 if (!isDoubleSpacedVectorList()) return false;
1161 return VectorList.Count == 3;
1162 }
1163
Jim Grosbach7945ead2012-01-24 00:43:12 +00001164 bool isVecListFourQ() const {
1165 if (!isDoubleSpacedVectorList()) return false;
1166 return VectorList.Count == 4;
1167 }
1168
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001169 bool isSingleSpacedVectorAllLanes() const {
1170 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1171 }
1172 bool isDoubleSpacedVectorAllLanes() const {
1173 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1174 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001175 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001176 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001177 return VectorList.Count == 1;
1178 }
1179
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001180 bool isVecListDPairAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001181 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001182 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1183 .contains(VectorList.RegNum));
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001184 }
1185
Jim Grosbach4d0983a2012-03-06 23:10:38 +00001186 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001187 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001188 return VectorList.Count == 2;
1189 }
1190
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001191 bool isVecListThreeDAllLanes() const {
1192 if (!isSingleSpacedVectorAllLanes()) return false;
1193 return VectorList.Count == 3;
1194 }
1195
1196 bool isVecListThreeQAllLanes() const {
1197 if (!isDoubleSpacedVectorAllLanes()) return false;
1198 return VectorList.Count == 3;
1199 }
1200
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001201 bool isVecListFourDAllLanes() const {
1202 if (!isSingleSpacedVectorAllLanes()) return false;
1203 return VectorList.Count == 4;
1204 }
1205
1206 bool isVecListFourQAllLanes() const {
1207 if (!isDoubleSpacedVectorAllLanes()) return false;
1208 return VectorList.Count == 4;
1209 }
1210
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001211 bool isSingleSpacedVectorIndexed() const {
1212 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1213 }
1214 bool isDoubleSpacedVectorIndexed() const {
1215 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1216 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001217 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001218 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001219 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1220 }
1221
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001222 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001223 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001224 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1225 }
1226
1227 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001228 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001229 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1230 }
1231
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001232 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001233 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001234 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1235 }
1236
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001237 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001238 if (!isSingleSpacedVectorIndexed()) return false;
1239 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1240 }
1241
1242 bool isVecListTwoQWordIndexed() const {
1243 if (!isDoubleSpacedVectorIndexed()) return false;
1244 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1245 }
1246
1247 bool isVecListTwoQHWordIndexed() const {
1248 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001249 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1250 }
1251
1252 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001253 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001254 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1255 }
1256
Jim Grosbach3a678af2012-01-23 21:53:26 +00001257 bool isVecListThreeDByteIndexed() const {
1258 if (!isSingleSpacedVectorIndexed()) return false;
1259 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1260 }
1261
1262 bool isVecListThreeDHWordIndexed() const {
1263 if (!isSingleSpacedVectorIndexed()) return false;
1264 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1265 }
1266
1267 bool isVecListThreeQWordIndexed() const {
1268 if (!isDoubleSpacedVectorIndexed()) return false;
1269 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1270 }
1271
1272 bool isVecListThreeQHWordIndexed() const {
1273 if (!isDoubleSpacedVectorIndexed()) return false;
1274 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1275 }
1276
1277 bool isVecListThreeDWordIndexed() const {
1278 if (!isSingleSpacedVectorIndexed()) return false;
1279 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1280 }
1281
Jim Grosbache983a132012-01-24 18:37:25 +00001282 bool isVecListFourDByteIndexed() const {
1283 if (!isSingleSpacedVectorIndexed()) return false;
1284 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1285 }
1286
1287 bool isVecListFourDHWordIndexed() const {
1288 if (!isSingleSpacedVectorIndexed()) return false;
1289 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1290 }
1291
1292 bool isVecListFourQWordIndexed() const {
1293 if (!isDoubleSpacedVectorIndexed()) return false;
1294 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1295 }
1296
1297 bool isVecListFourQHWordIndexed() const {
1298 if (!isDoubleSpacedVectorIndexed()) return false;
1299 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1300 }
1301
1302 bool isVecListFourDWordIndexed() const {
1303 if (!isSingleSpacedVectorIndexed()) return false;
1304 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1305 }
1306
Jim Grosbach460a9052011-10-07 23:56:00 +00001307 bool isVectorIndex8() const {
1308 if (Kind != k_VectorIndex) return false;
1309 return VectorIndex.Val < 8;
1310 }
1311 bool isVectorIndex16() const {
1312 if (Kind != k_VectorIndex) return false;
1313 return VectorIndex.Val < 4;
1314 }
1315 bool isVectorIndex32() const {
1316 if (Kind != k_VectorIndex) return false;
1317 return VectorIndex.Val < 2;
1318 }
1319
Jim Grosbach0e387b22011-10-17 22:26:03 +00001320 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001321 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001322 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1323 // Must be a constant.
1324 if (!CE) return false;
1325 int64_t Value = CE->getValue();
1326 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1327 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001328 return Value >= 0 && Value < 256;
1329 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001330
Jim Grosbachea461102011-10-17 23:09:09 +00001331 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001332 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001333 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1334 // Must be a constant.
1335 if (!CE) return false;
1336 int64_t Value = CE->getValue();
1337 // i16 value in the range [0,255] or [0x0100, 0xff00]
1338 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1339 }
1340
Jim Grosbach6248a542011-10-18 00:22:00 +00001341 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001342 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001343 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1344 // Must be a constant.
1345 if (!CE) return false;
1346 int64_t Value = CE->getValue();
1347 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1348 return (Value >= 0 && Value < 256) ||
1349 (Value >= 0x0100 && Value <= 0xff00) ||
1350 (Value >= 0x010000 && Value <= 0xff0000) ||
1351 (Value >= 0x01000000 && Value <= 0xff000000);
1352 }
1353
1354 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001355 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001356 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1357 // Must be a constant.
1358 if (!CE) return false;
1359 int64_t Value = CE->getValue();
1360 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1361 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1362 return (Value >= 0 && Value < 256) ||
1363 (Value >= 0x0100 && Value <= 0xff00) ||
1364 (Value >= 0x010000 && Value <= 0xff0000) ||
1365 (Value >= 0x01000000 && Value <= 0xff000000) ||
1366 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1367 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1368 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001369 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001370 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001371 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1372 // Must be a constant.
1373 if (!CE) return false;
1374 int64_t Value = ~CE->getValue();
1375 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1376 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1377 return (Value >= 0 && Value < 256) ||
1378 (Value >= 0x0100 && Value <= 0xff00) ||
1379 (Value >= 0x010000 && Value <= 0xff0000) ||
1380 (Value >= 0x01000000 && Value <= 0xff000000) ||
1381 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1382 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1383 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001384
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001385 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001386 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001387 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1388 // Must be a constant.
1389 if (!CE) return false;
1390 uint64_t Value = CE->getValue();
1391 // i64 value with each byte being either 0 or 0xff.
1392 for (unsigned i = 0; i < 8; ++i)
1393 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1394 return true;
1395 }
1396
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001397 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001398 // Add as immediates when possible. Null MCExpr = 0.
1399 if (Expr == 0)
1400 Inst.addOperand(MCOperand::CreateImm(0));
1401 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001402 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1403 else
1404 Inst.addOperand(MCOperand::CreateExpr(Expr));
1405 }
1406
Daniel Dunbar8462b302010-08-11 06:36:53 +00001407 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001408 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001409 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001410 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1411 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001412 }
1413
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001414 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1415 assert(N == 1 && "Invalid number of operands!");
1416 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1417 }
1418
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001419 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1420 assert(N == 1 && "Invalid number of operands!");
1421 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1422 }
1423
1424 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1425 assert(N == 1 && "Invalid number of operands!");
1426 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1427 }
1428
Jim Grosbach89df9962011-08-26 21:43:41 +00001429 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1430 assert(N == 1 && "Invalid number of operands!");
1431 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1432 }
1433
1434 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1435 assert(N == 1 && "Invalid number of operands!");
1436 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1437 }
1438
Jim Grosbachd67641b2010-12-06 18:21:12 +00001439 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1440 assert(N == 1 && "Invalid number of operands!");
1441 Inst.addOperand(MCOperand::CreateReg(getReg()));
1442 }
1443
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001444 void addRegOperands(MCInst &Inst, unsigned N) const {
1445 assert(N == 1 && "Invalid number of operands!");
1446 Inst.addOperand(MCOperand::CreateReg(getReg()));
1447 }
1448
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001449 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001450 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001451 assert(isRegShiftedReg() &&
1452 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001453 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1454 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001455 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001456 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001457 }
1458
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001459 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001460 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001461 assert(isRegShiftedImm() &&
1462 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001463 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonb56e4112012-04-25 18:00:18 +00001464 // Shift of #32 is encoded as 0 where permitted
1465 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Anderson92a20222011-07-21 18:54:16 +00001466 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonb56e4112012-04-25 18:00:18 +00001467 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001468 }
1469
Jim Grosbach580f4a92011-07-25 22:20:28 +00001470 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001471 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001472 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1473 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001474 }
1475
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001476 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001477 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001478 const SmallVectorImpl<unsigned> &RegList = getRegList();
1479 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001480 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1481 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001482 }
1483
Bill Wendling0f630752010-11-17 04:32:08 +00001484 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1485 addRegListOperands(Inst, N);
1486 }
1487
1488 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1489 addRegListOperands(Inst, N);
1490 }
1491
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001492 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1493 assert(N == 1 && "Invalid number of operands!");
1494 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1495 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1496 }
1497
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001498 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1499 assert(N == 1 && "Invalid number of operands!");
1500 // Munge the lsb/width into a bitfield mask.
1501 unsigned lsb = Bitfield.LSB;
1502 unsigned width = Bitfield.Width;
1503 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1504 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1505 (32 - (lsb + width)));
1506 Inst.addOperand(MCOperand::CreateImm(Mask));
1507 }
1508
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001509 void addImmOperands(MCInst &Inst, unsigned N) const {
1510 assert(N == 1 && "Invalid number of operands!");
1511 addExpr(Inst, getImm());
1512 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001513
Jim Grosbach4050bc42011-12-22 22:19:05 +00001514 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1515 assert(N == 1 && "Invalid number of operands!");
1516 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1517 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1518 }
1519
1520 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
1522 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1523 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1524 }
1525
Jim Grosbach9d390362011-10-03 23:38:36 +00001526 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001528 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1529 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1530 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001531 }
1532
Jim Grosbacha77295d2011-09-08 22:07:06 +00001533 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 // FIXME: We really want to scale the value here, but the LDRD/STRD
1536 // instruction don't encode operands that way yet.
1537 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1538 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1539 }
1540
Jim Grosbach72f39f82011-08-24 21:22:15 +00001541 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1542 assert(N == 1 && "Invalid number of operands!");
1543 // The immediate is scaled by four in the encoding and is stored
1544 // in the MCInst as such. Lop off the low two bits here.
1545 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1546 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1547 }
1548
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001549 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1550 assert(N == 1 && "Invalid number of operands!");
1551 // The immediate is scaled by four in the encoding and is stored
1552 // in the MCInst as such. Lop off the low two bits here.
1553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1554 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1555 }
1556
Jim Grosbach72f39f82011-08-24 21:22:15 +00001557 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1558 assert(N == 1 && "Invalid number of operands!");
1559 // The immediate is scaled by four in the encoding and is stored
1560 // in the MCInst as such. Lop off the low two bits here.
1561 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1562 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1563 }
1564
Jim Grosbachf4943352011-07-25 23:09:14 +00001565 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 // The constant encodes as the immediate-1, and we store in the instruction
1568 // the bits as encoded, so subtract off one here.
1569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1570 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1571 }
1572
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001573 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1574 assert(N == 1 && "Invalid number of operands!");
1575 // The constant encodes as the immediate-1, and we store in the instruction
1576 // the bits as encoded, so subtract off one here.
1577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1578 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1579 }
1580
Jim Grosbach70939ee2011-08-17 21:51:27 +00001581 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1582 assert(N == 1 && "Invalid number of operands!");
1583 // The constant encodes as the immediate, except for 32, which encodes as
1584 // zero.
1585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1586 unsigned Imm = CE->getValue();
1587 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1588 }
1589
Jim Grosbachf6c05252011-07-21 17:23:04 +00001590 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1591 assert(N == 1 && "Invalid number of operands!");
1592 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1593 // the instruction as well.
1594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1595 int Val = CE->getValue();
1596 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1597 }
1598
Jim Grosbach89a63372011-10-28 22:36:30 +00001599 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1600 assert(N == 1 && "Invalid number of operands!");
1601 // The operand is actually a t2_so_imm, but we have its bitwise
1602 // negation in the assembly source, so twiddle it here.
1603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1604 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1605 }
1606
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001607 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 // The operand is actually a t2_so_imm, but we have its
1610 // negation in the assembly source, so twiddle it here.
1611 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1612 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1613 }
1614
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001615 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1616 assert(N == 1 && "Invalid number of operands!");
1617 // The operand is actually an imm0_4095, but we have its
1618 // negation in the assembly source, so twiddle it here.
1619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1620 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1621 }
1622
Jim Grosbache70ec842011-10-28 22:50:54 +00001623 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 // The operand is actually a so_imm, but we have its bitwise
1626 // negation in the assembly source, so twiddle it here.
1627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1628 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1629 }
1630
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001631 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1632 assert(N == 1 && "Invalid number of operands!");
1633 // The operand is actually a so_imm, but we have its
1634 // negation in the assembly source, so twiddle it here.
1635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1636 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1637 }
1638
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001639 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1640 assert(N == 1 && "Invalid number of operands!");
1641 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1642 }
1643
Jim Grosbach7ce05792011-08-03 23:50:40 +00001644 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1645 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001646 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001647 }
1648
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001649 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1650 assert(N == 1 && "Invalid number of operands!");
1651 int32_t Imm = Memory.OffsetImm->getValue();
1652 // FIXME: Handle #-0
1653 if (Imm == INT32_MIN) Imm = 0;
1654 Inst.addOperand(MCOperand::CreateImm(Imm));
1655 }
1656
Jiangning Liu1fb27ec2012-08-02 08:13:13 +00001657 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 assert(isImm() && "Not an immediate!");
1660
1661 // If we have an immediate that's not a constant, treat it as a label
1662 // reference needing a fixup.
1663 if (!isa<MCConstantExpr>(getImm())) {
1664 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1665 return;
1666 }
1667
1668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1669 int Val = CE->getValue();
1670 Inst.addOperand(MCOperand::CreateImm(Val));
1671 }
1672
Jim Grosbach57dcb852011-10-11 17:29:55 +00001673 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1674 assert(N == 2 && "Invalid number of operands!");
1675 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1676 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1677 }
1678
Jim Grosbach7ce05792011-08-03 23:50:40 +00001679 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1680 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001681 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1682 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001683 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1684 // Special case for #-0
1685 if (Val == INT32_MIN) Val = 0;
1686 if (Val < 0) Val = -Val;
1687 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1688 } else {
1689 // For register offset, we encode the shift type and negation flag
1690 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001691 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1692 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001693 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001694 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1695 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001696 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001697 }
1698
Jim Grosbach039c2e12011-08-04 23:01:30 +00001699 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1700 assert(N == 2 && "Invalid number of operands!");
1701 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1702 assert(CE && "non-constant AM2OffsetImm operand!");
1703 int32_t Val = CE->getValue();
1704 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1705 // Special case for #-0
1706 if (Val == INT32_MIN) Val = 0;
1707 if (Val < 0) Val = -Val;
1708 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1709 Inst.addOperand(MCOperand::CreateReg(0));
1710 Inst.addOperand(MCOperand::CreateImm(Val));
1711 }
1712
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001713 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1714 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001715 // If we have an immediate that's not a constant, treat it as a label
1716 // reference needing a fixup. If it is a constant, it's something else
1717 // and we reject it.
1718 if (isImm()) {
1719 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1720 Inst.addOperand(MCOperand::CreateReg(0));
1721 Inst.addOperand(MCOperand::CreateImm(0));
1722 return;
1723 }
1724
Jim Grosbache53c87b2011-10-11 15:59:20 +00001725 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1726 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001727 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1728 // Special case for #-0
1729 if (Val == INT32_MIN) Val = 0;
1730 if (Val < 0) Val = -Val;
1731 Val = ARM_AM::getAM3Opc(AddSub, Val);
1732 } else {
1733 // For register offset, we encode the shift type and negation flag
1734 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001735 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001736 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001737 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1738 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001739 Inst.addOperand(MCOperand::CreateImm(Val));
1740 }
1741
1742 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001744 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001745 int32_t Val =
1746 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1747 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1748 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001749 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001750 }
1751
1752 // Constant offset.
1753 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1754 int32_t Val = CE->getValue();
1755 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1756 // Special case for #-0
1757 if (Val == INT32_MIN) Val = 0;
1758 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001759 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001760 Inst.addOperand(MCOperand::CreateReg(0));
1761 Inst.addOperand(MCOperand::CreateImm(Val));
1762 }
1763
Jim Grosbach7ce05792011-08-03 23:50:40 +00001764 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1765 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001766 // If we have an immediate that's not a constant, treat it as a label
1767 // reference needing a fixup. If it is a constant, it's something else
1768 // and we reject it.
1769 if (isImm()) {
1770 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1771 Inst.addOperand(MCOperand::CreateImm(0));
1772 return;
1773 }
1774
Jim Grosbach7ce05792011-08-03 23:50:40 +00001775 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001776 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001777 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1778 // Special case for #-0
1779 if (Val == INT32_MIN) Val = 0;
1780 if (Val < 0) Val = -Val;
1781 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001782 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001783 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001784 }
1785
Jim Grosbacha77295d2011-09-08 22:07:06 +00001786 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1787 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001788 // If we have an immediate that's not a constant, treat it as a label
1789 // reference needing a fixup. If it is a constant, it's something else
1790 // and we reject it.
1791 if (isImm()) {
1792 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1793 Inst.addOperand(MCOperand::CreateImm(0));
1794 return;
1795 }
1796
Jim Grosbache53c87b2011-10-11 15:59:20 +00001797 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1798 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001799 Inst.addOperand(MCOperand::CreateImm(Val));
1800 }
1801
Jim Grosbachb6aed502011-09-09 18:37:27 +00001802 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1803 assert(N == 2 && "Invalid number of operands!");
1804 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001805 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1806 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001807 Inst.addOperand(MCOperand::CreateImm(Val));
1808 }
1809
Jim Grosbach7ce05792011-08-03 23:50:40 +00001810 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001812 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1813 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001814 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001815 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001816
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001817 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1818 addMemImm8OffsetOperands(Inst, N);
1819 }
1820
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001821 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001822 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001823 }
1824
1825 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
1827 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001828 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001829 addExpr(Inst, getImm());
1830 Inst.addOperand(MCOperand::CreateImm(0));
1831 return;
1832 }
1833
1834 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001835 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1836 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001837 Inst.addOperand(MCOperand::CreateImm(Val));
1838 }
1839
Jim Grosbach7ce05792011-08-03 23:50:40 +00001840 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1841 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001842 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001843 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001844 addExpr(Inst, getImm());
1845 Inst.addOperand(MCOperand::CreateImm(0));
1846 return;
1847 }
1848
1849 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001850 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1851 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001852 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001853 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001854
Jim Grosbach7f739be2011-09-19 22:21:13 +00001855 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1856 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001857 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1858 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001859 }
1860
1861 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1862 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001863 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1864 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001865 }
1866
Jim Grosbach7ce05792011-08-03 23:50:40 +00001867 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1868 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001869 unsigned Val =
1870 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1871 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001872 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1873 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001874 Inst.addOperand(MCOperand::CreateImm(Val));
1875 }
1876
Jim Grosbachab899c12011-09-07 23:10:15 +00001877 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1878 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001879 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1880 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1881 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001882 }
1883
Jim Grosbach7ce05792011-08-03 23:50:40 +00001884 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001886 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1887 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001888 }
1889
Jim Grosbach60f91a32011-08-19 17:55:24 +00001890 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1891 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001892 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1893 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001894 Inst.addOperand(MCOperand::CreateImm(Val));
1895 }
1896
Jim Grosbach38466302011-08-19 18:55:51 +00001897 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1898 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001899 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1900 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001901 Inst.addOperand(MCOperand::CreateImm(Val));
1902 }
1903
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001904 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1905 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001906 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1907 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001908 Inst.addOperand(MCOperand::CreateImm(Val));
1909 }
1910
Jim Grosbachecd85892011-08-19 18:13:48 +00001911 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1912 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001913 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1914 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001915 Inst.addOperand(MCOperand::CreateImm(Val));
1916 }
1917
Jim Grosbach7ce05792011-08-03 23:50:40 +00001918 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1919 assert(N == 1 && "Invalid number of operands!");
1920 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1921 assert(CE && "non-constant post-idx-imm8 operand!");
1922 int Imm = CE->getValue();
1923 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001924 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001925 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1926 Inst.addOperand(MCOperand::CreateImm(Imm));
1927 }
1928
Jim Grosbach2bd01182011-10-11 21:55:36 +00001929 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1930 assert(N == 1 && "Invalid number of operands!");
1931 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1932 assert(CE && "non-constant post-idx-imm8s4 operand!");
1933 int Imm = CE->getValue();
1934 bool isAdd = Imm >= 0;
1935 if (Imm == INT32_MIN) Imm = 0;
1936 // Immediate is scaled by 4.
1937 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1938 Inst.addOperand(MCOperand::CreateImm(Imm));
1939 }
1940
Jim Grosbach7ce05792011-08-03 23:50:40 +00001941 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1942 assert(N == 2 && "Invalid number of operands!");
1943 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001944 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1945 }
1946
1947 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1948 assert(N == 2 && "Invalid number of operands!");
1949 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1950 // The sign, shift type, and shift amount are encoded in a single operand
1951 // using the AM2 encoding helpers.
1952 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1953 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1954 PostIdxReg.ShiftTy);
1955 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001956 }
1957
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001958 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1959 assert(N == 1 && "Invalid number of operands!");
1960 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1961 }
1962
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001963 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 1 && "Invalid number of operands!");
1965 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1966 }
1967
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001968 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001969 assert(N == 1 && "Invalid number of operands!");
1970 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1971 }
1972
Jim Grosbach7636bf62011-12-02 00:35:16 +00001973 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 2 && "Invalid number of operands!");
1975 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1976 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1977 }
1978
Jim Grosbach460a9052011-10-07 23:56:00 +00001979 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1980 assert(N == 1 && "Invalid number of operands!");
1981 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1982 }
1983
1984 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1985 assert(N == 1 && "Invalid number of operands!");
1986 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1987 }
1988
1989 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1990 assert(N == 1 && "Invalid number of operands!");
1991 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1992 }
1993
Jim Grosbach0e387b22011-10-17 22:26:03 +00001994 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1995 assert(N == 1 && "Invalid number of operands!");
1996 // The immediate encodes the type of constant as well as the value.
1997 // Mask in that this is an i8 splat.
1998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1999 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2000 }
2001
Jim Grosbachea461102011-10-17 23:09:09 +00002002 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2003 assert(N == 1 && "Invalid number of operands!");
2004 // The immediate encodes the type of constant as well as the value.
2005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2006 unsigned Value = CE->getValue();
2007 if (Value >= 256)
2008 Value = (Value >> 8) | 0xa00;
2009 else
2010 Value |= 0x800;
2011 Inst.addOperand(MCOperand::CreateImm(Value));
2012 }
2013
Jim Grosbach6248a542011-10-18 00:22:00 +00002014 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2015 assert(N == 1 && "Invalid number of operands!");
2016 // The immediate encodes the type of constant as well as the value.
2017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2018 unsigned Value = CE->getValue();
2019 if (Value >= 256 && Value <= 0xff00)
2020 Value = (Value >> 8) | 0x200;
2021 else if (Value > 0xffff && Value <= 0xff0000)
2022 Value = (Value >> 16) | 0x400;
2023 else if (Value > 0xffffff)
2024 Value = (Value >> 24) | 0x600;
2025 Inst.addOperand(MCOperand::CreateImm(Value));
2026 }
2027
2028 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2029 assert(N == 1 && "Invalid number of operands!");
2030 // The immediate encodes the type of constant as well as the value.
2031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2032 unsigned Value = CE->getValue();
2033 if (Value >= 256 && Value <= 0xffff)
2034 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2035 else if (Value > 0xffff && Value <= 0xffffff)
2036 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2037 else if (Value > 0xffffff)
2038 Value = (Value >> 24) | 0x600;
2039 Inst.addOperand(MCOperand::CreateImm(Value));
2040 }
2041
Jim Grosbach9b087852011-12-19 23:51:07 +00002042 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2043 assert(N == 1 && "Invalid number of operands!");
2044 // The immediate encodes the type of constant as well as the value.
2045 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2046 unsigned Value = ~CE->getValue();
2047 if (Value >= 256 && Value <= 0xffff)
2048 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2049 else if (Value > 0xffff && Value <= 0xffffff)
2050 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2051 else if (Value > 0xffffff)
2052 Value = (Value >> 24) | 0x600;
2053 Inst.addOperand(MCOperand::CreateImm(Value));
2054 }
2055
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00002056 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2057 assert(N == 1 && "Invalid number of operands!");
2058 // The immediate encodes the type of constant as well as the value.
2059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2060 uint64_t Value = CE->getValue();
2061 unsigned Imm = 0;
2062 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2063 Imm |= (Value & 1) << i;
2064 }
2065 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2066 }
2067
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002068 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00002069
Jim Grosbach89df9962011-08-26 21:43:41 +00002070 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002071 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00002072 Op->ITMask.Mask = Mask;
2073 Op->StartLoc = S;
2074 Op->EndLoc = S;
2075 return Op;
2076 }
2077
Chris Lattner3a697562010-10-28 17:20:03 +00002078 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002079 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002080 Op->CC.Val = CC;
2081 Op->StartLoc = S;
2082 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002083 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002084 }
2085
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002086 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002087 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002088 Op->Cop.Val = CopVal;
2089 Op->StartLoc = S;
2090 Op->EndLoc = S;
2091 return Op;
2092 }
2093
2094 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002095 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002096 Op->Cop.Val = CopVal;
2097 Op->StartLoc = S;
2098 Op->EndLoc = S;
2099 return Op;
2100 }
2101
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002102 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2103 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2104 Op->Cop.Val = Val;
2105 Op->StartLoc = S;
2106 Op->EndLoc = E;
2107 return Op;
2108 }
2109
Jim Grosbachd67641b2010-12-06 18:21:12 +00002110 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002111 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002112 Op->Reg.RegNum = RegNum;
2113 Op->StartLoc = S;
2114 Op->EndLoc = S;
2115 return Op;
2116 }
2117
Chris Lattner3a697562010-10-28 17:20:03 +00002118 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002119 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002120 Op->Tok.Data = Str.data();
2121 Op->Tok.Length = Str.size();
2122 Op->StartLoc = S;
2123 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002124 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002125 }
2126
Bill Wendling50d0f582010-11-18 23:43:05 +00002127 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002128 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002129 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002130 Op->StartLoc = S;
2131 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002132 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002133 }
2134
Jim Grosbache8606dc2011-07-13 17:50:29 +00002135 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2136 unsigned SrcReg,
2137 unsigned ShiftReg,
2138 unsigned ShiftImm,
2139 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002140 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002141 Op->RegShiftedReg.ShiftTy = ShTy;
2142 Op->RegShiftedReg.SrcReg = SrcReg;
2143 Op->RegShiftedReg.ShiftReg = ShiftReg;
2144 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002145 Op->StartLoc = S;
2146 Op->EndLoc = E;
2147 return Op;
2148 }
2149
Owen Anderson92a20222011-07-21 18:54:16 +00002150 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2151 unsigned SrcReg,
2152 unsigned ShiftImm,
2153 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002154 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002155 Op->RegShiftedImm.ShiftTy = ShTy;
2156 Op->RegShiftedImm.SrcReg = SrcReg;
2157 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002158 Op->StartLoc = S;
2159 Op->EndLoc = E;
2160 return Op;
2161 }
2162
Jim Grosbach580f4a92011-07-25 22:20:28 +00002163 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002164 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002165 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002166 Op->ShifterImm.isASR = isASR;
2167 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002168 Op->StartLoc = S;
2169 Op->EndLoc = E;
2170 return Op;
2171 }
2172
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002173 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002174 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002175 Op->RotImm.Imm = Imm;
2176 Op->StartLoc = S;
2177 Op->EndLoc = E;
2178 return Op;
2179 }
2180
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002181 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2182 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002183 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002184 Op->Bitfield.LSB = LSB;
2185 Op->Bitfield.Width = Width;
2186 Op->StartLoc = S;
2187 Op->EndLoc = E;
2188 return Op;
2189 }
2190
Bill Wendling7729e062010-11-09 22:44:22 +00002191 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002192 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002193 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002194 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002195
Jim Grosbachd300b942011-09-13 22:56:44 +00002196 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002197 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002198 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002199 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002200 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002201
2202 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002203 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002204 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002205 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002206 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002207 Op->StartLoc = StartLoc;
2208 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002209 return Op;
2210 }
2211
Jim Grosbach862019c2011-10-18 23:02:30 +00002212 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002213 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002214 ARMOperand *Op = new ARMOperand(k_VectorList);
2215 Op->VectorList.RegNum = RegNum;
2216 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002217 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002218 Op->StartLoc = S;
2219 Op->EndLoc = E;
2220 return Op;
2221 }
2222
Jim Grosbach98b05a52011-11-30 01:09:44 +00002223 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002224 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002225 SMLoc S, SMLoc E) {
2226 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2227 Op->VectorList.RegNum = RegNum;
2228 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002229 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002230 Op->StartLoc = S;
2231 Op->EndLoc = E;
2232 return Op;
2233 }
2234
Jim Grosbach7636bf62011-12-02 00:35:16 +00002235 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002236 unsigned Index,
2237 bool isDoubleSpaced,
2238 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002239 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2240 Op->VectorList.RegNum = RegNum;
2241 Op->VectorList.Count = Count;
2242 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002243 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002244 Op->StartLoc = S;
2245 Op->EndLoc = E;
2246 return Op;
2247 }
2248
Jim Grosbach460a9052011-10-07 23:56:00 +00002249 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2250 MCContext &Ctx) {
2251 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2252 Op->VectorIndex.Val = Idx;
2253 Op->StartLoc = S;
2254 Op->EndLoc = E;
2255 return Op;
2256 }
2257
Chris Lattner3a697562010-10-28 17:20:03 +00002258 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002259 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002260 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002261 Op->StartLoc = S;
2262 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002263 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002264 }
2265
Jim Grosbach7ce05792011-08-03 23:50:40 +00002266 static ARMOperand *CreateMem(unsigned BaseRegNum,
2267 const MCConstantExpr *OffsetImm,
2268 unsigned OffsetRegNum,
2269 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002270 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002271 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002272 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002273 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002274 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002275 Op->Memory.BaseRegNum = BaseRegNum;
2276 Op->Memory.OffsetImm = OffsetImm;
2277 Op->Memory.OffsetRegNum = OffsetRegNum;
2278 Op->Memory.ShiftType = ShiftType;
2279 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002280 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002281 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002282 Op->StartLoc = S;
2283 Op->EndLoc = E;
2284 return Op;
2285 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002286
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002287 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2288 ARM_AM::ShiftOpc ShiftTy,
2289 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002290 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002291 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002292 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002293 Op->PostIdxReg.isAdd = isAdd;
2294 Op->PostIdxReg.ShiftTy = ShiftTy;
2295 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002296 Op->StartLoc = S;
2297 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002298 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002299 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002300
2301 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002302 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002303 Op->MBOpt.Val = Opt;
2304 Op->StartLoc = S;
2305 Op->EndLoc = S;
2306 return Op;
2307 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002308
2309 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002310 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002311 Op->IFlags.Val = IFlags;
2312 Op->StartLoc = S;
2313 Op->EndLoc = S;
2314 return Op;
2315 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002316
2317 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002318 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002319 Op->MMask.Val = MMask;
2320 Op->StartLoc = S;
2321 Op->EndLoc = S;
2322 return Op;
2323 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002324};
2325
2326} // end anonymous namespace.
2327
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002328void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002329 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002330 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002331 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002332 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002333 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002334 OS << "<ccout " << getReg() << ">";
2335 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002336 case k_ITCondMask: {
Craig Topper032f4412012-05-24 04:11:15 +00002337 static const char *const MaskStr[] = {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002338 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2339 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2340 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002341 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2342 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2343 break;
2344 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002345 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002346 OS << "<coprocessor number: " << getCoproc() << ">";
2347 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002348 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002349 OS << "<coprocessor register: " << getCoproc() << ">";
2350 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002351 case k_CoprocOption:
2352 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2353 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002354 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002355 OS << "<mask: " << getMSRMask() << ">";
2356 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002357 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002358 getImm()->print(OS);
2359 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002360 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002361 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2362 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002363 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002364 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002365 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002366 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002367 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002368 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002369 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2370 << PostIdxReg.RegNum;
2371 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2372 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2373 << PostIdxReg.ShiftImm;
2374 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002375 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002376 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002377 OS << "<ARM_PROC::";
2378 unsigned IFlags = getProcIFlags();
2379 for (int i=2; i >= 0; --i)
2380 if (IFlags & (1 << i))
2381 OS << ARM_PROC::IFlagsToString(1 << i);
2382 OS << ">";
2383 break;
2384 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002385 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002386 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002387 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002388 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002389 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2390 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002391 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002392 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002393 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002394 << RegShiftedReg.SrcReg << " "
2395 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2396 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002397 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002398 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002399 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002400 << RegShiftedImm.SrcReg << " "
2401 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2402 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002403 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002404 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002405 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2406 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002407 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002408 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2409 << ", width: " << Bitfield.Width << ">";
2410 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002411 case k_RegisterList:
2412 case k_DPRRegisterList:
2413 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002414 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002415
Bill Wendling5fa22a12010-11-09 23:28:44 +00002416 const SmallVectorImpl<unsigned> &RegList = getRegList();
2417 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002418 I = RegList.begin(), E = RegList.end(); I != E; ) {
2419 OS << *I;
2420 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002421 }
2422
2423 OS << ">";
2424 break;
2425 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002426 case k_VectorList:
2427 OS << "<vector_list " << VectorList.Count << " * "
2428 << VectorList.RegNum << ">";
2429 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002430 case k_VectorListAllLanes:
2431 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2432 << VectorList.RegNum << ">";
2433 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002434 case k_VectorListIndexed:
2435 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2436 << VectorList.Count << " * " << VectorList.RegNum << ">";
2437 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002438 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002439 OS << "'" << getToken() << "'";
2440 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002441 case k_VectorIndex:
2442 OS << "<vectorindex " << getVectorIndex() << ">";
2443 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002444 }
2445}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002446
2447/// @name Auto-generated Match Functions
2448/// {
2449
2450static unsigned MatchRegisterName(StringRef Name);
2451
2452/// }
2453
Bob Wilson69df7232011-02-03 21:46:10 +00002454bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2455 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002456 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002457 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002458 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002459
2460 return (RegNo == (unsigned)-1);
2461}
2462
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002463/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002464/// and if it is a register name the token is eaten and the register number is
2465/// returned. Otherwise return -1.
2466///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002467int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002468 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002469 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002470
Benjamin Kramer59085362011-11-06 20:37:06 +00002471 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002472 unsigned RegNum = MatchRegisterName(lowerCase);
2473 if (!RegNum) {
2474 RegNum = StringSwitch<unsigned>(lowerCase)
2475 .Case("r13", ARM::SP)
2476 .Case("r14", ARM::LR)
2477 .Case("r15", ARM::PC)
2478 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002479 // Additional register name aliases for 'gas' compatibility.
2480 .Case("a1", ARM::R0)
2481 .Case("a2", ARM::R1)
2482 .Case("a3", ARM::R2)
2483 .Case("a4", ARM::R3)
2484 .Case("v1", ARM::R4)
2485 .Case("v2", ARM::R5)
2486 .Case("v3", ARM::R6)
2487 .Case("v4", ARM::R7)
2488 .Case("v5", ARM::R8)
2489 .Case("v6", ARM::R9)
2490 .Case("v7", ARM::R10)
2491 .Case("v8", ARM::R11)
2492 .Case("sb", ARM::R9)
2493 .Case("sl", ARM::R10)
2494 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002495 .Default(0);
2496 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002497 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002498 // Check for aliases registered via .req. Canonicalize to lower case.
2499 // That's more consistent since register names are case insensitive, and
2500 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2501 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002502 // If no match, return failure.
2503 if (Entry == RegisterReqs.end())
2504 return -1;
2505 Parser.Lex(); // Eat identifier token.
2506 return Entry->getValue();
2507 }
Bob Wilson69df7232011-02-03 21:46:10 +00002508
Chris Lattnere5658fa2010-10-30 04:09:10 +00002509 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002510
Chris Lattnere5658fa2010-10-30 04:09:10 +00002511 return RegNum;
2512}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002513
Jim Grosbach19906722011-07-13 18:49:30 +00002514// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2515// If a recoverable error occurs, return 1. If an irrecoverable error
2516// occurs, return -1. An irrecoverable error is one where tokens have been
2517// consumed in the process of trying to parse the shifter (i.e., when it is
2518// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002519int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002520 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2521 SMLoc S = Parser.getTok().getLoc();
2522 const AsmToken &Tok = Parser.getTok();
2523 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2524
Benjamin Kramer59085362011-11-06 20:37:06 +00002525 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002526 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002527 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002528 .Case("lsl", ARM_AM::lsl)
2529 .Case("lsr", ARM_AM::lsr)
2530 .Case("asr", ARM_AM::asr)
2531 .Case("ror", ARM_AM::ror)
2532 .Case("rrx", ARM_AM::rrx)
2533 .Default(ARM_AM::no_shift);
2534
2535 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002536 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002537
Jim Grosbache8606dc2011-07-13 17:50:29 +00002538 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002539
Jim Grosbache8606dc2011-07-13 17:50:29 +00002540 // The source register for the shift has already been added to the
2541 // operand list, so we need to pop it off and combine it into the shifted
2542 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002543 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002544 if (!PrevOp->isReg())
2545 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2546 int SrcReg = PrevOp->getReg();
2547 int64_t Imm = 0;
2548 int ShiftReg = 0;
2549 if (ShiftTy == ARM_AM::rrx) {
2550 // RRX Doesn't have an explicit shift amount. The encoder expects
2551 // the shift register to be the same as the source register. Seems odd,
2552 // but OK.
2553 ShiftReg = SrcReg;
2554 } else {
2555 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002556 if (Parser.getTok().is(AsmToken::Hash) ||
2557 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002558 Parser.Lex(); // Eat hash.
2559 SMLoc ImmLoc = Parser.getTok().getLoc();
2560 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002561 if (getParser().ParseExpression(ShiftExpr)) {
2562 Error(ImmLoc, "invalid immediate shift value");
2563 return -1;
2564 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002565 // The expression must be evaluatable as an immediate.
2566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002567 if (!CE) {
2568 Error(ImmLoc, "invalid immediate shift value");
2569 return -1;
2570 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002571 // Range check the immediate.
2572 // lsl, ror: 0 <= imm <= 31
2573 // lsr, asr: 0 <= imm <= 32
2574 Imm = CE->getValue();
2575 if (Imm < 0 ||
2576 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2577 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002578 Error(ImmLoc, "immediate shift value out of range");
2579 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002580 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002581 // shift by zero is a nop. Always send it through as lsl.
2582 // ('as' compatibility)
2583 if (Imm == 0)
2584 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002585 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002586 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002587 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002588 if (ShiftReg == -1) {
2589 Error (L, "expected immediate or register in shift operand");
2590 return -1;
2591 }
2592 } else {
2593 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002594 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002595 return -1;
2596 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002597 }
2598
Owen Anderson92a20222011-07-21 18:54:16 +00002599 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2600 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002601 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002602 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002603 else
2604 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2605 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002606
Jim Grosbach19906722011-07-13 18:49:30 +00002607 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002608}
2609
2610
Bill Wendling50d0f582010-11-18 23:43:05 +00002611/// Try to parse a register name. The token must be an Identifier when called.
2612/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2613/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002614///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002615/// TODO this is likely to change to allow different register types and or to
2616/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002617bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002618tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002619 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002620 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002621 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002622 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002623
Bill Wendling50d0f582010-11-18 23:43:05 +00002624 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002625
Chris Lattnere5658fa2010-10-30 04:09:10 +00002626 const AsmToken &ExclaimTok = Parser.getTok();
2627 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002628 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2629 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002630 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002631 return false;
2632 }
2633
2634 // Also check for an index operand. This is only legal for vector registers,
2635 // but that'll get caught OK in operand matching, so we don't need to
2636 // explicitly filter everything else out here.
2637 if (Parser.getTok().is(AsmToken::LBrac)) {
2638 SMLoc SIdx = Parser.getTok().getLoc();
2639 Parser.Lex(); // Eat left bracket token.
2640
2641 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002642 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002643 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002644 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002645 if (!MCE)
2646 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002647
2648 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002649 if (Parser.getTok().isNot(AsmToken::RBrac))
2650 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002651
2652 Parser.Lex(); // Eat right bracket token.
2653
2654 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2655 SIdx, E,
2656 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002657 }
2658
Bill Wendling50d0f582010-11-18 23:43:05 +00002659 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002660}
2661
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002662/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2663/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2664/// "c5", ...
2665static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002666 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2667 // but efficient.
2668 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002669 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002670 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002671 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002672 return -1;
2673 switch (Name[1]) {
2674 default: return -1;
2675 case '0': return 0;
2676 case '1': return 1;
2677 case '2': return 2;
2678 case '3': return 3;
2679 case '4': return 4;
2680 case '5': return 5;
2681 case '6': return 6;
2682 case '7': return 7;
2683 case '8': return 8;
2684 case '9': return 9;
2685 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002686 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002687 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002688 return -1;
2689 switch (Name[2]) {
2690 default: return -1;
2691 case '0': return 10;
2692 case '1': return 11;
2693 case '2': return 12;
2694 case '3': return 13;
2695 case '4': return 14;
2696 case '5': return 15;
2697 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002698 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002699}
2700
Jim Grosbach89df9962011-08-26 21:43:41 +00002701/// parseITCondCode - Try to parse a condition code for an IT instruction.
2702ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2703parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2704 SMLoc S = Parser.getTok().getLoc();
2705 const AsmToken &Tok = Parser.getTok();
2706 if (!Tok.is(AsmToken::Identifier))
2707 return MatchOperand_NoMatch;
Richard Barton04a09a42012-04-27 17:34:01 +00002708 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach89df9962011-08-26 21:43:41 +00002709 .Case("eq", ARMCC::EQ)
2710 .Case("ne", ARMCC::NE)
2711 .Case("hs", ARMCC::HS)
2712 .Case("cs", ARMCC::HS)
2713 .Case("lo", ARMCC::LO)
2714 .Case("cc", ARMCC::LO)
2715 .Case("mi", ARMCC::MI)
2716 .Case("pl", ARMCC::PL)
2717 .Case("vs", ARMCC::VS)
2718 .Case("vc", ARMCC::VC)
2719 .Case("hi", ARMCC::HI)
2720 .Case("ls", ARMCC::LS)
2721 .Case("ge", ARMCC::GE)
2722 .Case("lt", ARMCC::LT)
2723 .Case("gt", ARMCC::GT)
2724 .Case("le", ARMCC::LE)
2725 .Case("al", ARMCC::AL)
2726 .Default(~0U);
2727 if (CC == ~0U)
2728 return MatchOperand_NoMatch;
2729 Parser.Lex(); // Eat the token.
2730
2731 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2732
2733 return MatchOperand_Success;
2734}
2735
Jim Grosbach43904292011-07-25 20:14:50 +00002736/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002737/// token must be an Identifier when called, and if it is a coprocessor
2738/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002739ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002740parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002741 SMLoc S = Parser.getTok().getLoc();
2742 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002743 if (Tok.isNot(AsmToken::Identifier))
2744 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002745
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002746 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002747 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002748 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002749
2750 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002751 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002752 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002753}
2754
Jim Grosbach43904292011-07-25 20:14:50 +00002755/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002756/// token must be an Identifier when called, and if it is a coprocessor
2757/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002758ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002759parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002760 SMLoc S = Parser.getTok().getLoc();
2761 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002762 if (Tok.isNot(AsmToken::Identifier))
2763 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002764
2765 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2766 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002767 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002768
2769 Parser.Lex(); // Eat identifier token.
2770 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002771 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002772}
2773
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002774/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2775/// coproc_option : '{' imm0_255 '}'
2776ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2777parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2778 SMLoc S = Parser.getTok().getLoc();
2779
2780 // If this isn't a '{', this isn't a coprocessor immediate operand.
2781 if (Parser.getTok().isNot(AsmToken::LCurly))
2782 return MatchOperand_NoMatch;
2783 Parser.Lex(); // Eat the '{'
2784
2785 const MCExpr *Expr;
2786 SMLoc Loc = Parser.getTok().getLoc();
2787 if (getParser().ParseExpression(Expr)) {
2788 Error(Loc, "illegal expression");
2789 return MatchOperand_ParseFail;
2790 }
2791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2792 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2793 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2794 return MatchOperand_ParseFail;
2795 }
2796 int Val = CE->getValue();
2797
2798 // Check for and consume the closing '}'
2799 if (Parser.getTok().isNot(AsmToken::RCurly))
2800 return MatchOperand_ParseFail;
2801 SMLoc E = Parser.getTok().getLoc();
2802 Parser.Lex(); // Eat the '}'
2803
2804 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2805 return MatchOperand_Success;
2806}
2807
Jim Grosbachd0588e22011-09-14 18:08:35 +00002808// For register list parsing, we need to map from raw GPR register numbering
2809// to the enumeration values. The enumeration values aren't sorted by
2810// register number due to our using "sp", "lr" and "pc" as canonical names.
2811static unsigned getNextRegister(unsigned Reg) {
2812 // If this is a GPR, we need to do it manually, otherwise we can rely
2813 // on the sort ordering of the enumeration since the other reg-classes
2814 // are sane.
2815 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2816 return Reg + 1;
2817 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002818 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002819 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2820 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2821 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2822 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2823 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2824 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2825 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2826 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2827 }
2828}
2829
Jim Grosbachce485e72011-11-11 21:27:40 +00002830// Return the low-subreg of a given Q register.
2831static unsigned getDRegFromQReg(unsigned QReg) {
2832 switch (QReg) {
2833 default: llvm_unreachable("expected a Q register!");
2834 case ARM::Q0: return ARM::D0;
2835 case ARM::Q1: return ARM::D2;
2836 case ARM::Q2: return ARM::D4;
2837 case ARM::Q3: return ARM::D6;
2838 case ARM::Q4: return ARM::D8;
2839 case ARM::Q5: return ARM::D10;
2840 case ARM::Q6: return ARM::D12;
2841 case ARM::Q7: return ARM::D14;
2842 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002843 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002844 case ARM::Q10: return ARM::D20;
2845 case ARM::Q11: return ARM::D22;
2846 case ARM::Q12: return ARM::D24;
2847 case ARM::Q13: return ARM::D26;
2848 case ARM::Q14: return ARM::D28;
2849 case ARM::Q15: return ARM::D30;
2850 }
2851}
2852
Jim Grosbachd0588e22011-09-14 18:08:35 +00002853/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002854bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002855parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002856 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002857 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002858 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002859 Parser.Lex(); // Eat '{' token.
2860 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002861
Jim Grosbachd0588e22011-09-14 18:08:35 +00002862 // Check the first register in the list to see what register class
2863 // this is a list of.
2864 int Reg = tryParseRegister();
2865 if (Reg == -1)
2866 return Error(RegLoc, "register expected");
2867
Jim Grosbachce485e72011-11-11 21:27:40 +00002868 // The reglist instructions have at most 16 registers, so reserve
2869 // space for that many.
2870 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2871
2872 // Allow Q regs and just interpret them as the two D sub-registers.
2873 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2874 Reg = getDRegFromQReg(Reg);
2875 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2876 ++Reg;
2877 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002878 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002879 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2880 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2881 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2882 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2883 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2884 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2885 else
2886 return Error(RegLoc, "invalid register in register list");
2887
Jim Grosbachce485e72011-11-11 21:27:40 +00002888 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002889 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002890
Jim Grosbachd0588e22011-09-14 18:08:35 +00002891 // This starts immediately after the first register token in the list,
2892 // so we can see either a comma or a minus (range separator) as a legal
2893 // next token.
2894 while (Parser.getTok().is(AsmToken::Comma) ||
2895 Parser.getTok().is(AsmToken::Minus)) {
2896 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002897 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002898 SMLoc EndLoc = Parser.getTok().getLoc();
2899 int EndReg = tryParseRegister();
2900 if (EndReg == -1)
2901 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002902 // Allow Q regs and just interpret them as the two D sub-registers.
2903 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2904 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002905 // If the register is the same as the start reg, there's nothing
2906 // more to do.
2907 if (Reg == EndReg)
2908 continue;
2909 // The register must be in the same register class as the first.
2910 if (!RC->contains(EndReg))
2911 return Error(EndLoc, "invalid register in register list");
2912 // Ranges must go from low to high.
Eric Christopherdf1c6372012-08-09 22:10:21 +00002913 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jim Grosbachd0588e22011-09-14 18:08:35 +00002914 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002915
Jim Grosbachd0588e22011-09-14 18:08:35 +00002916 // Add all the registers in the range to the register list.
2917 while (Reg != EndReg) {
2918 Reg = getNextRegister(Reg);
2919 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2920 }
2921 continue;
2922 }
2923 Parser.Lex(); // Eat the comma.
2924 RegLoc = Parser.getTok().getLoc();
2925 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002926 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002927 Reg = tryParseRegister();
2928 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002929 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002930 // Allow Q regs and just interpret them as the two D sub-registers.
2931 bool isQReg = false;
2932 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2933 Reg = getDRegFromQReg(Reg);
2934 isQReg = true;
2935 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002936 // The register must be in the same register class as the first.
2937 if (!RC->contains(Reg))
2938 return Error(RegLoc, "invalid register in register list");
2939 // List must be monotonically increasing.
Eric Christopherdf1c6372012-08-09 22:10:21 +00002940 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbachbe7cf2b2012-03-16 20:48:38 +00002941 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2942 Warning(RegLoc, "register list not in ascending order");
2943 else
2944 return Error(RegLoc, "register list not in ascending order");
2945 }
Eric Christopherdf1c6372012-08-09 22:10:21 +00002946 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002947 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2948 ") in register list");
2949 continue;
2950 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002951 // VFP register lists must also be contiguous.
2952 // It's OK to use the enumeration values directly here rather, as the
2953 // VFP register classes have the enum sorted properly.
2954 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2955 Reg != OldReg + 1)
2956 return Error(RegLoc, "non-contiguous register range");
2957 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002958 if (isQReg)
2959 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002960 }
2961
Jim Grosbachd0588e22011-09-14 18:08:35 +00002962 SMLoc E = Parser.getTok().getLoc();
2963 if (Parser.getTok().isNot(AsmToken::RCurly))
2964 return Error(E, "'}' expected");
2965 Parser.Lex(); // Eat '}' token.
2966
Jim Grosbach27debd62011-12-13 21:48:29 +00002967 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002968 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002969
2970 // The ARM system instruction variants for LDM/STM have a '^' token here.
2971 if (Parser.getTok().is(AsmToken::Caret)) {
2972 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2973 Parser.Lex(); // Eat '^' token.
2974 }
2975
Bill Wendling50d0f582010-11-18 23:43:05 +00002976 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002977}
2978
Jim Grosbach98b05a52011-11-30 01:09:44 +00002979// Helper function to parse the lane index for vector lists.
2980ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002981parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2982 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002983 if (Parser.getTok().is(AsmToken::LBrac)) {
2984 Parser.Lex(); // Eat the '['.
2985 if (Parser.getTok().is(AsmToken::RBrac)) {
2986 // "Dn[]" is the 'all lanes' syntax.
2987 LaneKind = AllLanes;
2988 Parser.Lex(); // Eat the ']'.
2989 return MatchOperand_Success;
2990 }
Jim Grosbachceee9842012-03-19 20:39:53 +00002991
2992 // There's an optional '#' token here. Normally there wouldn't be, but
2993 // inline assemble puts one in, and it's friendly to accept that.
2994 if (Parser.getTok().is(AsmToken::Hash))
2995 Parser.Lex(); // Eat the '#'
2996
Jim Grosbachc9313252011-12-21 01:19:23 +00002997 const MCExpr *LaneIndex;
2998 SMLoc Loc = Parser.getTok().getLoc();
2999 if (getParser().ParseExpression(LaneIndex)) {
3000 Error(Loc, "illegal expression");
3001 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003002 }
Jim Grosbachc9313252011-12-21 01:19:23 +00003003 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3004 if (!CE) {
3005 Error(Loc, "lane index must be empty or an integer");
3006 return MatchOperand_ParseFail;
3007 }
3008 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3009 Error(Parser.getTok().getLoc(), "']' expected");
3010 return MatchOperand_ParseFail;
3011 }
3012 Parser.Lex(); // Eat the ']'.
3013 int64_t Val = CE->getValue();
3014
3015 // FIXME: Make this range check context sensitive for .8, .16, .32.
3016 if (Val < 0 || Val > 7) {
3017 Error(Parser.getTok().getLoc(), "lane index out of range");
3018 return MatchOperand_ParseFail;
3019 }
3020 Index = Val;
3021 LaneKind = IndexedLane;
3022 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003023 }
3024 LaneKind = NoLanes;
3025 return MatchOperand_Success;
3026}
3027
Jim Grosbach862019c2011-10-18 23:02:30 +00003028// parse a vector register list
3029ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3030parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003031 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003032 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00003033 SMLoc S = Parser.getTok().getLoc();
3034 // As an extension (to match gas), support a plain D register or Q register
3035 // (without encosing curly braces) as a single or double entry list,
3036 // respectively.
3037 if (Parser.getTok().is(AsmToken::Identifier)) {
3038 int Reg = tryParseRegister();
3039 if (Reg == -1)
3040 return MatchOperand_NoMatch;
3041 SMLoc E = Parser.getTok().getLoc();
3042 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00003043 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003044 if (Res != MatchOperand_Success)
3045 return Res;
3046 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003047 case NoLanes:
3048 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003049 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003050 break;
3051 case AllLanes:
3052 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003053 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3054 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003055 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003056 case IndexedLane:
3057 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003058 LaneIndex,
3059 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003060 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003061 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003062 return MatchOperand_Success;
3063 }
3064 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3065 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00003066 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003067 if (Res != MatchOperand_Success)
3068 return Res;
3069 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003070 case NoLanes:
3071 E = Parser.getTok().getLoc();
Jim Grosbach28f08c92012-03-05 19:33:30 +00003072 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003073 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003074 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003075 break;
3076 case AllLanes:
3077 E = Parser.getTok().getLoc();
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003078 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3079 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003080 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3081 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003082 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003083 case IndexedLane:
3084 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003085 LaneIndex,
3086 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003087 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003088 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003089 return MatchOperand_Success;
3090 }
3091 Error(S, "vector register expected");
3092 return MatchOperand_ParseFail;
3093 }
3094
3095 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003096 return MatchOperand_NoMatch;
3097
Jim Grosbach862019c2011-10-18 23:02:30 +00003098 Parser.Lex(); // Eat '{' token.
3099 SMLoc RegLoc = Parser.getTok().getLoc();
3100
3101 int Reg = tryParseRegister();
3102 if (Reg == -1) {
3103 Error(RegLoc, "register expected");
3104 return MatchOperand_ParseFail;
3105 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003106 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003107 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003108 unsigned FirstReg = Reg;
3109 // The list is of D registers, but we also allow Q regs and just interpret
3110 // them as the two D sub-registers.
3111 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3112 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003113 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3114 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003115 ++Reg;
3116 ++Count;
3117 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003118 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003119 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003120
Jim Grosbache43862b2011-11-15 23:19:15 +00003121 while (Parser.getTok().is(AsmToken::Comma) ||
3122 Parser.getTok().is(AsmToken::Minus)) {
3123 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003124 if (!Spacing)
3125 Spacing = 1; // Register range implies a single spaced list.
3126 else if (Spacing == 2) {
3127 Error(Parser.getTok().getLoc(),
3128 "sequential registers in double spaced list");
3129 return MatchOperand_ParseFail;
3130 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003131 Parser.Lex(); // Eat the minus.
3132 SMLoc EndLoc = Parser.getTok().getLoc();
3133 int EndReg = tryParseRegister();
3134 if (EndReg == -1) {
3135 Error(EndLoc, "register expected");
3136 return MatchOperand_ParseFail;
3137 }
3138 // Allow Q regs and just interpret them as the two D sub-registers.
3139 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3140 EndReg = getDRegFromQReg(EndReg) + 1;
3141 // If the register is the same as the start reg, there's nothing
3142 // more to do.
3143 if (Reg == EndReg)
3144 continue;
3145 // The register must be in the same register class as the first.
3146 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3147 Error(EndLoc, "invalid register in register list");
3148 return MatchOperand_ParseFail;
3149 }
3150 // Ranges must go from low to high.
3151 if (Reg > EndReg) {
3152 Error(EndLoc, "bad range in register list");
3153 return MatchOperand_ParseFail;
3154 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003155 // Parse the lane specifier if present.
3156 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003157 unsigned NextLaneIndex;
3158 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003159 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003160 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003161 Error(EndLoc, "mismatched lane index in register list");
3162 return MatchOperand_ParseFail;
3163 }
3164 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003165
3166 // Add all the registers in the range to the register list.
3167 Count += EndReg - Reg;
3168 Reg = EndReg;
3169 continue;
3170 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003171 Parser.Lex(); // Eat the comma.
3172 RegLoc = Parser.getTok().getLoc();
3173 int OldReg = Reg;
3174 Reg = tryParseRegister();
3175 if (Reg == -1) {
3176 Error(RegLoc, "register expected");
3177 return MatchOperand_ParseFail;
3178 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003179 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003180 // It's OK to use the enumeration values directly here rather, as the
3181 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003182 //
3183 // The list is of D registers, but we also allow Q regs and just interpret
3184 // them as the two D sub-registers.
3185 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003186 if (!Spacing)
3187 Spacing = 1; // Register range implies a single spaced list.
3188 else if (Spacing == 2) {
3189 Error(RegLoc,
3190 "invalid register in double-spaced list (must be 'D' register')");
3191 return MatchOperand_ParseFail;
3192 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003193 Reg = getDRegFromQReg(Reg);
3194 if (Reg != OldReg + 1) {
3195 Error(RegLoc, "non-contiguous register range");
3196 return MatchOperand_ParseFail;
3197 }
3198 ++Reg;
3199 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003200 // Parse the lane specifier if present.
3201 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003202 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003203 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003204 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003205 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003206 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003207 Error(EndLoc, "mismatched lane index in register list");
3208 return MatchOperand_ParseFail;
3209 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003210 continue;
3211 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003212 // Normal D register.
3213 // Figure out the register spacing (single or double) of the list if
3214 // we don't know it already.
3215 if (!Spacing)
3216 Spacing = 1 + (Reg == OldReg + 2);
3217
3218 // Just check that it's contiguous and keep going.
3219 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003220 Error(RegLoc, "non-contiguous register range");
3221 return MatchOperand_ParseFail;
3222 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003223 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003224 // Parse the lane specifier if present.
3225 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003226 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003227 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003228 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003229 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003230 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003231 Error(EndLoc, "mismatched lane index in register list");
3232 return MatchOperand_ParseFail;
3233 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003234 }
3235
3236 SMLoc E = Parser.getTok().getLoc();
3237 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3238 Error(E, "'}' expected");
3239 return MatchOperand_ParseFail;
3240 }
3241 Parser.Lex(); // Eat '}' token.
3242
Jim Grosbach98b05a52011-11-30 01:09:44 +00003243 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003244 case NoLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003245 // Two-register operands have been converted to the
Jim Grosbachc3384c92012-03-05 21:43:40 +00003246 // composite register classes.
3247 if (Count == 2) {
3248 const MCRegisterClass *RC = (Spacing == 1) ?
3249 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3250 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3251 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3252 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003253
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003254 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3255 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003256 break;
3257 case AllLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003258 // Two-register operands have been converted to the
3259 // composite register classes.
Jim Grosbach4d0983a2012-03-06 23:10:38 +00003260 if (Count == 2) {
3261 const MCRegisterClass *RC = (Spacing == 1) ?
3262 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3263 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003264 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3265 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003266 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003267 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003268 S, E));
3269 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003270 case IndexedLane:
3271 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003272 LaneIndex,
3273 (Spacing == 2),
3274 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003275 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003276 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003277 return MatchOperand_Success;
3278}
3279
Jim Grosbach43904292011-07-25 20:14:50 +00003280/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003281ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003282parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003283 SMLoc S = Parser.getTok().getLoc();
3284 const AsmToken &Tok = Parser.getTok();
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003285 unsigned Opt;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003286
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003287 if (Tok.is(AsmToken::Identifier)) {
3288 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003289
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003290 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3291 .Case("sy", ARM_MB::SY)
3292 .Case("st", ARM_MB::ST)
3293 .Case("sh", ARM_MB::ISH)
3294 .Case("ish", ARM_MB::ISH)
3295 .Case("shst", ARM_MB::ISHST)
3296 .Case("ishst", ARM_MB::ISHST)
3297 .Case("nsh", ARM_MB::NSH)
3298 .Case("un", ARM_MB::NSH)
3299 .Case("nshst", ARM_MB::NSHST)
3300 .Case("unst", ARM_MB::NSHST)
3301 .Case("osh", ARM_MB::OSH)
3302 .Case("oshst", ARM_MB::OSHST)
3303 .Default(~0U);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003304
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003305 if (Opt == ~0U)
3306 return MatchOperand_NoMatch;
3307
3308 Parser.Lex(); // Eat identifier token.
3309 } else if (Tok.is(AsmToken::Hash) ||
3310 Tok.is(AsmToken::Dollar) ||
3311 Tok.is(AsmToken::Integer)) {
3312 if (Parser.getTok().isNot(AsmToken::Integer))
3313 Parser.Lex(); // Eat the '#'.
3314 SMLoc Loc = Parser.getTok().getLoc();
3315
3316 const MCExpr *MemBarrierID;
3317 if (getParser().ParseExpression(MemBarrierID)) {
3318 Error(Loc, "illegal expression");
3319 return MatchOperand_ParseFail;
3320 }
3321
3322 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3323 if (!CE) {
3324 Error(Loc, "constant expression expected");
3325 return MatchOperand_ParseFail;
3326 }
3327
3328 int Val = CE->getValue();
3329 if (Val & ~0xf) {
3330 Error(Loc, "immediate value out of range");
3331 return MatchOperand_ParseFail;
3332 }
3333
3334 Opt = ARM_MB::RESERVED_0 + Val;
3335 } else
3336 return MatchOperand_ParseFail;
3337
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003338 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003339 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003340}
3341
Jim Grosbach43904292011-07-25 20:14:50 +00003342/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003343ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003344parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003345 SMLoc S = Parser.getTok().getLoc();
3346 const AsmToken &Tok = Parser.getTok();
Richard Bartona1c73672012-06-14 10:48:04 +00003347 if (!Tok.is(AsmToken::Identifier))
3348 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003349 StringRef IFlagsStr = Tok.getString();
3350
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003351 // An iflags string of "none" is interpreted to mean that none of the AIF
3352 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003353 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003354 if (IFlagsStr != "none") {
3355 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3356 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3357 .Case("a", ARM_PROC::A)
3358 .Case("i", ARM_PROC::I)
3359 .Case("f", ARM_PROC::F)
3360 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003361
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003362 // If some specific iflag is already set, it means that some letter is
3363 // present more than once, this is not acceptable.
3364 if (Flag == ~0U || (IFlags & Flag))
3365 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003366
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003367 IFlags |= Flag;
3368 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003369 }
3370
3371 Parser.Lex(); // Eat identifier token.
3372 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3373 return MatchOperand_Success;
3374}
3375
Jim Grosbach43904292011-07-25 20:14:50 +00003376/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003377ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003378parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003379 SMLoc S = Parser.getTok().getLoc();
3380 const AsmToken &Tok = Parser.getTok();
3381 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3382 StringRef Mask = Tok.getString();
3383
James Molloyacad68d2011-09-28 14:21:38 +00003384 if (isMClass()) {
3385 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003386 std::string Name = Mask.lower();
3387 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003388 // Note: in the documentation:
3389 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3390 // for MSR APSR_nzcvq.
3391 // but we do make it an alias here. This is so to get the "mask encoding"
3392 // bits correct on MSR APSR writes.
3393 //
3394 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3395 // should really only be allowed when writing a special register. Note
3396 // they get dropped in the MRS instruction reading a special register as
3397 // the SYSm field is only 8 bits.
3398 //
3399 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3400 // includes the DSP extension but that is not checked.
3401 .Case("apsr", 0x800)
3402 .Case("apsr_nzcvq", 0x800)
3403 .Case("apsr_g", 0x400)
3404 .Case("apsr_nzcvqg", 0xc00)
3405 .Case("iapsr", 0x801)
3406 .Case("iapsr_nzcvq", 0x801)
3407 .Case("iapsr_g", 0x401)
3408 .Case("iapsr_nzcvqg", 0xc01)
3409 .Case("eapsr", 0x802)
3410 .Case("eapsr_nzcvq", 0x802)
3411 .Case("eapsr_g", 0x402)
3412 .Case("eapsr_nzcvqg", 0xc02)
3413 .Case("xpsr", 0x803)
3414 .Case("xpsr_nzcvq", 0x803)
3415 .Case("xpsr_g", 0x403)
3416 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003417 .Case("ipsr", 0x805)
3418 .Case("epsr", 0x806)
3419 .Case("iepsr", 0x807)
3420 .Case("msp", 0x808)
3421 .Case("psp", 0x809)
3422 .Case("primask", 0x810)
3423 .Case("basepri", 0x811)
3424 .Case("basepri_max", 0x812)
3425 .Case("faultmask", 0x813)
3426 .Case("control", 0x814)
James Molloyacad68d2011-09-28 14:21:38 +00003427 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003428
James Molloyacad68d2011-09-28 14:21:38 +00003429 if (FlagsVal == ~0U)
3430 return MatchOperand_NoMatch;
3431
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003432 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloyacad68d2011-09-28 14:21:38 +00003433 // basepri, basepri_max and faultmask only valid for V7m.
3434 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003435
James Molloyacad68d2011-09-28 14:21:38 +00003436 Parser.Lex(); // Eat identifier token.
3437 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3438 return MatchOperand_Success;
3439 }
3440
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003441 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3442 size_t Start = 0, Next = Mask.find('_');
3443 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003444 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003445 if (Next != StringRef::npos)
3446 Flags = Mask.slice(Next+1, Mask.size());
3447
3448 // FlagsVal contains the complete mask:
3449 // 3-0: Mask
3450 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3451 unsigned FlagsVal = 0;
3452
3453 if (SpecReg == "apsr") {
3454 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003455 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003456 .Case("g", 0x4) // same as CPSR_s
3457 .Case("nzcvqg", 0xc) // same as CPSR_fs
3458 .Default(~0U);
3459
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003460 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003461 if (!Flags.empty())
3462 return MatchOperand_NoMatch;
3463 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003464 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003465 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003466 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbachb657a902012-04-05 03:17:53 +00003467 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3468 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003469 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003470 for (int i = 0, e = Flags.size(); i != e; ++i) {
3471 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3472 .Case("c", 1)
3473 .Case("x", 2)
3474 .Case("s", 4)
3475 .Case("f", 8)
3476 .Default(~0U);
3477
3478 // If some specific flag is already set, it means that some letter is
3479 // present more than once, this is not acceptable.
3480 if (FlagsVal == ~0U || (FlagsVal & Flag))
3481 return MatchOperand_NoMatch;
3482 FlagsVal |= Flag;
3483 }
3484 } else // No match for special register.
3485 return MatchOperand_NoMatch;
3486
Owen Anderson7784f1d2011-10-21 18:43:28 +00003487 // Special register without flags is NOT equivalent to "fc" flags.
3488 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3489 // two lines would enable gas compatibility at the expense of breaking
3490 // round-tripping.
3491 //
3492 // if (!FlagsVal)
3493 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003494
3495 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3496 if (SpecReg == "spsr")
3497 FlagsVal |= 16;
3498
3499 Parser.Lex(); // Eat identifier token.
3500 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3501 return MatchOperand_Success;
3502}
3503
Jim Grosbachf6c05252011-07-21 17:23:04 +00003504ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3505parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3506 int Low, int High) {
3507 const AsmToken &Tok = Parser.getTok();
3508 if (Tok.isNot(AsmToken::Identifier)) {
3509 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3510 return MatchOperand_ParseFail;
3511 }
3512 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003513 std::string LowerOp = Op.lower();
3514 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003515 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3516 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3517 return MatchOperand_ParseFail;
3518 }
3519 Parser.Lex(); // Eat shift type token.
3520
3521 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003522 if (Parser.getTok().isNot(AsmToken::Hash) &&
3523 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003524 Error(Parser.getTok().getLoc(), "'#' expected");
3525 return MatchOperand_ParseFail;
3526 }
3527 Parser.Lex(); // Eat hash token.
3528
3529 const MCExpr *ShiftAmount;
3530 SMLoc Loc = Parser.getTok().getLoc();
3531 if (getParser().ParseExpression(ShiftAmount)) {
3532 Error(Loc, "illegal expression");
3533 return MatchOperand_ParseFail;
3534 }
3535 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3536 if (!CE) {
3537 Error(Loc, "constant expression expected");
3538 return MatchOperand_ParseFail;
3539 }
3540 int Val = CE->getValue();
3541 if (Val < Low || Val > High) {
3542 Error(Loc, "immediate value out of range");
3543 return MatchOperand_ParseFail;
3544 }
3545
3546 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3547
3548 return MatchOperand_Success;
3549}
3550
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003551ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3552parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3553 const AsmToken &Tok = Parser.getTok();
3554 SMLoc S = Tok.getLoc();
3555 if (Tok.isNot(AsmToken::Identifier)) {
3556 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3557 return MatchOperand_ParseFail;
3558 }
3559 int Val = StringSwitch<int>(Tok.getString())
3560 .Case("be", 1)
3561 .Case("le", 0)
3562 .Default(-1);
3563 Parser.Lex(); // Eat the token.
3564
3565 if (Val == -1) {
3566 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3567 return MatchOperand_ParseFail;
3568 }
3569 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3570 getContext()),
3571 S, Parser.getTok().getLoc()));
3572 return MatchOperand_Success;
3573}
3574
Jim Grosbach580f4a92011-07-25 22:20:28 +00003575/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3576/// instructions. Legal values are:
3577/// lsl #n 'n' in [0,31]
3578/// asr #n 'n' in [1,32]
3579/// n == 32 encoded as n == 0.
3580ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3581parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3582 const AsmToken &Tok = Parser.getTok();
3583 SMLoc S = Tok.getLoc();
3584 if (Tok.isNot(AsmToken::Identifier)) {
3585 Error(S, "shift operator 'asr' or 'lsl' expected");
3586 return MatchOperand_ParseFail;
3587 }
3588 StringRef ShiftName = Tok.getString();
3589 bool isASR;
3590 if (ShiftName == "lsl" || ShiftName == "LSL")
3591 isASR = false;
3592 else if (ShiftName == "asr" || ShiftName == "ASR")
3593 isASR = true;
3594 else {
3595 Error(S, "shift operator 'asr' or 'lsl' expected");
3596 return MatchOperand_ParseFail;
3597 }
3598 Parser.Lex(); // Eat the operator.
3599
3600 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003601 if (Parser.getTok().isNot(AsmToken::Hash) &&
3602 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003603 Error(Parser.getTok().getLoc(), "'#' expected");
3604 return MatchOperand_ParseFail;
3605 }
3606 Parser.Lex(); // Eat hash token.
3607
3608 const MCExpr *ShiftAmount;
3609 SMLoc E = Parser.getTok().getLoc();
3610 if (getParser().ParseExpression(ShiftAmount)) {
3611 Error(E, "malformed shift expression");
3612 return MatchOperand_ParseFail;
3613 }
3614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3615 if (!CE) {
3616 Error(E, "shift amount must be an immediate");
3617 return MatchOperand_ParseFail;
3618 }
3619
3620 int64_t Val = CE->getValue();
3621 if (isASR) {
3622 // Shift amount must be in [1,32]
3623 if (Val < 1 || Val > 32) {
3624 Error(E, "'asr' shift amount must be in range [1,32]");
3625 return MatchOperand_ParseFail;
3626 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003627 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3628 if (isThumb() && Val == 32) {
3629 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3630 return MatchOperand_ParseFail;
3631 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003632 if (Val == 32) Val = 0;
3633 } else {
3634 // Shift amount must be in [1,32]
3635 if (Val < 0 || Val > 31) {
3636 Error(E, "'lsr' shift amount must be in range [0,31]");
3637 return MatchOperand_ParseFail;
3638 }
3639 }
3640
3641 E = Parser.getTok().getLoc();
3642 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3643
3644 return MatchOperand_Success;
3645}
3646
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003647/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3648/// of instructions. Legal values are:
3649/// ror #n 'n' in {0, 8, 16, 24}
3650ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3651parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3652 const AsmToken &Tok = Parser.getTok();
3653 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003654 if (Tok.isNot(AsmToken::Identifier))
3655 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003656 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003657 if (ShiftName != "ror" && ShiftName != "ROR")
3658 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003659 Parser.Lex(); // Eat the operator.
3660
3661 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003662 if (Parser.getTok().isNot(AsmToken::Hash) &&
3663 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003664 Error(Parser.getTok().getLoc(), "'#' expected");
3665 return MatchOperand_ParseFail;
3666 }
3667 Parser.Lex(); // Eat hash token.
3668
3669 const MCExpr *ShiftAmount;
3670 SMLoc E = Parser.getTok().getLoc();
3671 if (getParser().ParseExpression(ShiftAmount)) {
3672 Error(E, "malformed rotate expression");
3673 return MatchOperand_ParseFail;
3674 }
3675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3676 if (!CE) {
3677 Error(E, "rotate amount must be an immediate");
3678 return MatchOperand_ParseFail;
3679 }
3680
3681 int64_t Val = CE->getValue();
3682 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3683 // normally, zero is represented in asm by omitting the rotate operand
3684 // entirely.
3685 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3686 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3687 return MatchOperand_ParseFail;
3688 }
3689
3690 E = Parser.getTok().getLoc();
3691 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3692
3693 return MatchOperand_Success;
3694}
3695
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003696ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3697parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3698 SMLoc S = Parser.getTok().getLoc();
3699 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003700 if (Parser.getTok().isNot(AsmToken::Hash) &&
3701 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003702 Error(Parser.getTok().getLoc(), "'#' expected");
3703 return MatchOperand_ParseFail;
3704 }
3705 Parser.Lex(); // Eat hash token.
3706
3707 const MCExpr *LSBExpr;
3708 SMLoc E = Parser.getTok().getLoc();
3709 if (getParser().ParseExpression(LSBExpr)) {
3710 Error(E, "malformed immediate expression");
3711 return MatchOperand_ParseFail;
3712 }
3713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3714 if (!CE) {
3715 Error(E, "'lsb' operand must be an immediate");
3716 return MatchOperand_ParseFail;
3717 }
3718
3719 int64_t LSB = CE->getValue();
3720 // The LSB must be in the range [0,31]
3721 if (LSB < 0 || LSB > 31) {
3722 Error(E, "'lsb' operand must be in the range [0,31]");
3723 return MatchOperand_ParseFail;
3724 }
3725 E = Parser.getTok().getLoc();
3726
3727 // Expect another immediate operand.
3728 if (Parser.getTok().isNot(AsmToken::Comma)) {
3729 Error(Parser.getTok().getLoc(), "too few operands");
3730 return MatchOperand_ParseFail;
3731 }
3732 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003733 if (Parser.getTok().isNot(AsmToken::Hash) &&
3734 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003735 Error(Parser.getTok().getLoc(), "'#' expected");
3736 return MatchOperand_ParseFail;
3737 }
3738 Parser.Lex(); // Eat hash token.
3739
3740 const MCExpr *WidthExpr;
3741 if (getParser().ParseExpression(WidthExpr)) {
3742 Error(E, "malformed immediate expression");
3743 return MatchOperand_ParseFail;
3744 }
3745 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3746 if (!CE) {
3747 Error(E, "'width' operand must be an immediate");
3748 return MatchOperand_ParseFail;
3749 }
3750
3751 int64_t Width = CE->getValue();
3752 // The LSB must be in the range [1,32-lsb]
3753 if (Width < 1 || Width > 32 - LSB) {
3754 Error(E, "'width' operand must be in the range [1,32-lsb]");
3755 return MatchOperand_ParseFail;
3756 }
3757 E = Parser.getTok().getLoc();
3758
3759 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3760
3761 return MatchOperand_Success;
3762}
3763
Jim Grosbach7ce05792011-08-03 23:50:40 +00003764ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3765parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3766 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003767 // postidx_reg := '+' register {, shift}
3768 // | '-' register {, shift}
3769 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003770
3771 // This method must return MatchOperand_NoMatch without consuming any tokens
3772 // in the case where there is no match, as other alternatives take other
3773 // parse methods.
3774 AsmToken Tok = Parser.getTok();
3775 SMLoc S = Tok.getLoc();
3776 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003777 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003778 int Reg = -1;
3779 if (Tok.is(AsmToken::Plus)) {
3780 Parser.Lex(); // Eat the '+' token.
3781 haveEaten = true;
3782 } else if (Tok.is(AsmToken::Minus)) {
3783 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003784 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003785 haveEaten = true;
3786 }
3787 if (Parser.getTok().is(AsmToken::Identifier))
3788 Reg = tryParseRegister();
3789 if (Reg == -1) {
3790 if (!haveEaten)
3791 return MatchOperand_NoMatch;
3792 Error(Parser.getTok().getLoc(), "register expected");
3793 return MatchOperand_ParseFail;
3794 }
3795 SMLoc E = Parser.getTok().getLoc();
3796
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003797 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3798 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003799 if (Parser.getTok().is(AsmToken::Comma)) {
3800 Parser.Lex(); // Eat the ','.
3801 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3802 return MatchOperand_ParseFail;
3803 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003804
3805 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3806 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003807
3808 return MatchOperand_Success;
3809}
3810
Jim Grosbach251bf252011-08-10 21:56:18 +00003811ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3812parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3813 // Check for a post-index addressing register operand. Specifically:
3814 // am3offset := '+' register
3815 // | '-' register
3816 // | register
3817 // | # imm
3818 // | # + imm
3819 // | # - imm
3820
3821 // This method must return MatchOperand_NoMatch without consuming any tokens
3822 // in the case where there is no match, as other alternatives take other
3823 // parse methods.
3824 AsmToken Tok = Parser.getTok();
3825 SMLoc S = Tok.getLoc();
3826
3827 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003828 if (Parser.getTok().is(AsmToken::Hash) ||
3829 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003830 Parser.Lex(); // Eat the '#'.
3831 // Explicitly look for a '-', as we need to encode negative zero
3832 // differently.
3833 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3834 const MCExpr *Offset;
3835 if (getParser().ParseExpression(Offset))
3836 return MatchOperand_ParseFail;
3837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3838 if (!CE) {
3839 Error(S, "constant expression expected");
3840 return MatchOperand_ParseFail;
3841 }
3842 SMLoc E = Tok.getLoc();
3843 // Negative zero is encoded as the flag value INT32_MIN.
3844 int32_t Val = CE->getValue();
3845 if (isNegative && Val == 0)
3846 Val = INT32_MIN;
3847
3848 Operands.push_back(
3849 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3850
3851 return MatchOperand_Success;
3852 }
3853
3854
3855 bool haveEaten = false;
3856 bool isAdd = true;
3857 int Reg = -1;
3858 if (Tok.is(AsmToken::Plus)) {
3859 Parser.Lex(); // Eat the '+' token.
3860 haveEaten = true;
3861 } else if (Tok.is(AsmToken::Minus)) {
3862 Parser.Lex(); // Eat the '-' token.
3863 isAdd = false;
3864 haveEaten = true;
3865 }
3866 if (Parser.getTok().is(AsmToken::Identifier))
3867 Reg = tryParseRegister();
3868 if (Reg == -1) {
3869 if (!haveEaten)
3870 return MatchOperand_NoMatch;
3871 Error(Parser.getTok().getLoc(), "register expected");
3872 return MatchOperand_ParseFail;
3873 }
3874 SMLoc E = Parser.getTok().getLoc();
3875
3876 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3877 0, S, E));
3878
3879 return MatchOperand_Success;
3880}
3881
Jim Grosbacha77295d2011-09-08 22:07:06 +00003882/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3883/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3884/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003885void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003886cvtT2LdrdPre(MCInst &Inst,
Jim Grosbacha77295d2011-09-08 22:07:06 +00003887 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3888 // Rt, Rt2
3889 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3890 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3891 // Create a writeback register dummy placeholder.
3892 Inst.addOperand(MCOperand::CreateReg(0));
3893 // addr
3894 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3895 // pred
3896 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacha77295d2011-09-08 22:07:06 +00003897}
3898
3899/// cvtT2StrdPre - Convert parsed operands to MCInst.
3900/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3901/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003902void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003903cvtT2StrdPre(MCInst &Inst,
Jim Grosbacha77295d2011-09-08 22:07:06 +00003904 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3905 // Create a writeback register dummy placeholder.
3906 Inst.addOperand(MCOperand::CreateReg(0));
3907 // Rt, Rt2
3908 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3909 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3910 // addr
3911 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3912 // pred
3913 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacha77295d2011-09-08 22:07:06 +00003914}
3915
Jim Grosbacheeec0252011-09-08 00:39:19 +00003916/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3917/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3918/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003919void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003920cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbacheeec0252011-09-08 00:39:19 +00003921 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3922 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3923
3924 // Create a writeback register dummy placeholder.
3925 Inst.addOperand(MCOperand::CreateImm(0));
3926
3927 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3928 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheeec0252011-09-08 00:39:19 +00003929}
3930
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003931/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3932/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3933/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003934void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003935cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003936 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3937 // Create a writeback register dummy placeholder.
3938 Inst.addOperand(MCOperand::CreateImm(0));
3939 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3940 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3941 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003942}
3943
Jim Grosbach1355cf12011-07-26 17:10:22 +00003944/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003945/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3946/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003947void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003948cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003949 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3950 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3951
3952 // Create a writeback register dummy placeholder.
3953 Inst.addOperand(MCOperand::CreateImm(0));
3954
Jim Grosbach7ce05792011-08-03 23:50:40 +00003955 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003956 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003957}
3958
Owen Anderson9ab0f252011-08-26 20:43:14 +00003959/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3960/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3961/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003962void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003963cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003964 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3965 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3966
3967 // Create a writeback register dummy placeholder.
3968 Inst.addOperand(MCOperand::CreateImm(0));
3969
3970 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3971 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson9ab0f252011-08-26 20:43:14 +00003972}
3973
3974
Jim Grosbach548340c2011-08-11 19:22:40 +00003975/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3976/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3977/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003978void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003979cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbach548340c2011-08-11 19:22:40 +00003980 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3981 // Create a writeback register dummy placeholder.
3982 Inst.addOperand(MCOperand::CreateImm(0));
3983 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3984 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3985 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach548340c2011-08-11 19:22:40 +00003986}
3987
Jim Grosbach1355cf12011-07-26 17:10:22 +00003988/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003989/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3990/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003991void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003992cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003993 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3994 // Create a writeback register dummy placeholder.
3995 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003996 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3997 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3998 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003999}
4000
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004001/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4002/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4003/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004004void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004005cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004006 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4007 // Create a writeback register dummy placeholder.
4008 Inst.addOperand(MCOperand::CreateImm(0));
4009 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4010 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4011 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004012}
4013
Jim Grosbach7ce05792011-08-03 23:50:40 +00004014/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4015/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4016/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004017void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004018cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004019 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4020 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004021 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004022 // Create a writeback register dummy placeholder.
4023 Inst.addOperand(MCOperand::CreateImm(0));
4024 // addr
4025 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4026 // offset
4027 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4028 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004029 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004030}
4031
Jim Grosbach7ce05792011-08-03 23:50:40 +00004032/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004033/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4034/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004035void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004036cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004037 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4038 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00004039 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004040 // Create a writeback register dummy placeholder.
4041 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004042 // addr
4043 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4044 // offset
4045 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4046 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004047 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004048}
4049
Jim Grosbach7ce05792011-08-03 23:50:40 +00004050/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004051/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4052/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004053void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004054cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004055 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004056 // Create a writeback register dummy placeholder.
4057 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004058 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004059 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004060 // addr
4061 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4062 // offset
4063 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4064 // pred
4065 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004066}
4067
4068/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4069/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4070/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004071void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004072cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004073 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4074 // Create a writeback register dummy placeholder.
4075 Inst.addOperand(MCOperand::CreateImm(0));
4076 // Rt
4077 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4078 // addr
4079 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4080 // offset
4081 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4082 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004083 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004084}
4085
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004086/// cvtLdrdPre - Convert parsed operands to MCInst.
4087/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4088/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004089void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004090cvtLdrdPre(MCInst &Inst,
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004091 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4092 // Rt, Rt2
4093 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4094 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4095 // Create a writeback register dummy placeholder.
4096 Inst.addOperand(MCOperand::CreateImm(0));
4097 // addr
4098 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4099 // pred
4100 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004101}
4102
Jim Grosbach14605d12011-08-11 20:28:23 +00004103/// cvtStrdPre - Convert parsed operands to MCInst.
4104/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4105/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004106void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004107cvtStrdPre(MCInst &Inst,
Jim Grosbach14605d12011-08-11 20:28:23 +00004108 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4109 // Create a writeback register dummy placeholder.
4110 Inst.addOperand(MCOperand::CreateImm(0));
4111 // Rt, Rt2
4112 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4113 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4114 // addr
4115 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4116 // pred
4117 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach14605d12011-08-11 20:28:23 +00004118}
4119
Jim Grosbach623a4542011-08-10 22:42:16 +00004120/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4121/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4122/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004123void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004124cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach623a4542011-08-10 22:42:16 +00004125 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4126 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4127 // Create a writeback register dummy placeholder.
4128 Inst.addOperand(MCOperand::CreateImm(0));
4129 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4130 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach623a4542011-08-10 22:42:16 +00004131}
4132
Chad Rosier1122fc42012-08-30 23:00:00 +00004133/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004134/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4135/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004136void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004137cvtThumbMultiply(MCInst &Inst,
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004138 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004139 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4140 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004141 // If we have a three-operand form, make sure to set Rn to be the operand
4142 // that isn't the same as Rd.
4143 unsigned RegOp = 4;
4144 if (Operands.size() == 6 &&
4145 ((ARMOperand*)Operands[4])->getReg() ==
4146 ((ARMOperand*)Operands[3])->getReg())
4147 RegOp = 5;
4148 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4149 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004150 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004151}
Jim Grosbach623a4542011-08-10 22:42:16 +00004152
Chad Rosier359956d2012-08-31 00:03:31 +00004153void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004154cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +00004155 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4156 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004157 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004158 // Create a writeback register dummy placeholder.
4159 Inst.addOperand(MCOperand::CreateImm(0));
4160 // Vn
4161 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4162 // pred
4163 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach12431322011-10-24 22:16:58 +00004164}
4165
Chad Rosier359956d2012-08-31 00:03:31 +00004166void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004167cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +00004168 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4169 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004170 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004171 // Create a writeback register dummy placeholder.
4172 Inst.addOperand(MCOperand::CreateImm(0));
4173 // Vn
4174 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4175 // Vm
4176 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4177 // pred
4178 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach12431322011-10-24 22:16:58 +00004179}
4180
Chad Rosier359956d2012-08-31 00:03:31 +00004181void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004182cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +00004183 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4184 // Create a writeback register dummy placeholder.
4185 Inst.addOperand(MCOperand::CreateImm(0));
4186 // Vn
4187 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4188 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004189 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004190 // pred
4191 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach4334e032011-10-31 21:50:31 +00004192}
4193
Chad Rosier359956d2012-08-31 00:03:31 +00004194void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004195cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +00004196 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4197 // Create a writeback register dummy placeholder.
4198 Inst.addOperand(MCOperand::CreateImm(0));
4199 // Vn
4200 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4201 // Vm
4202 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4203 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004204 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004205 // pred
4206 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach4334e032011-10-31 21:50:31 +00004207}
4208
Bill Wendlinge7176102010-11-06 22:36:58 +00004209/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004210/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004211bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004212parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004213 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004214 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004215 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004216 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004217 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004218
Sean Callanan18b83232010-01-19 21:44:56 +00004219 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004220 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004221 if (BaseRegNum == -1)
4222 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004223
Daniel Dunbar05710932011-01-18 05:34:17 +00004224 // The next token must either be a comma or a closing bracket.
4225 const AsmToken &Tok = Parser.getTok();
4226 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004227 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004228
Jim Grosbach7ce05792011-08-03 23:50:40 +00004229 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004230 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004231 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004232
Jim Grosbach7ce05792011-08-03 23:50:40 +00004233 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004234 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004235
Jim Grosbachfb12f352011-09-19 18:42:21 +00004236 // If there's a pre-indexing writeback marker, '!', just add it as a token
4237 // operand. It's rather odd, but syntactically valid.
4238 if (Parser.getTok().is(AsmToken::Exclaim)) {
4239 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4240 Parser.Lex(); // Eat the '!'.
4241 }
4242
Jim Grosbach7ce05792011-08-03 23:50:40 +00004243 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004244 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004245
Jim Grosbach7ce05792011-08-03 23:50:40 +00004246 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4247 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004248
Jim Grosbach57dcb852011-10-11 17:29:55 +00004249 // If we have a ':', it's an alignment specifier.
4250 if (Parser.getTok().is(AsmToken::Colon)) {
4251 Parser.Lex(); // Eat the ':'.
4252 E = Parser.getTok().getLoc();
4253
4254 const MCExpr *Expr;
4255 if (getParser().ParseExpression(Expr))
4256 return true;
4257
4258 // The expression has to be a constant. Memory references with relocations
4259 // don't come through here, as they use the <label> forms of the relevant
4260 // instructions.
4261 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4262 if (!CE)
4263 return Error (E, "constant expression expected");
4264
4265 unsigned Align = 0;
4266 switch (CE->getValue()) {
4267 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004268 return Error(E,
4269 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4270 case 16: Align = 2; break;
4271 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004272 case 64: Align = 8; break;
4273 case 128: Align = 16; break;
4274 case 256: Align = 32; break;
4275 }
4276
4277 // Now we should have the closing ']'
4278 E = Parser.getTok().getLoc();
4279 if (Parser.getTok().isNot(AsmToken::RBrac))
4280 return Error(E, "']' expected");
4281 Parser.Lex(); // Eat right bracket token.
4282
4283 // Don't worry about range checking the value here. That's handled by
4284 // the is*() predicates.
4285 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4286 ARM_AM::no_shift, 0, Align,
4287 false, S, E));
4288
4289 // If there's a pre-indexing writeback marker, '!', just add it as a token
4290 // operand.
4291 if (Parser.getTok().is(AsmToken::Exclaim)) {
4292 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4293 Parser.Lex(); // Eat the '!'.
4294 }
4295
4296 return false;
4297 }
4298
4299 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004300 // offset. Be friendly and also accept a plain integer (without a leading
4301 // hash) for gas compatibility.
4302 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004303 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004304 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004305 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004306 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004307 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004308
Owen Anderson0da10cf2011-08-29 19:36:44 +00004309 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004310 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004311 if (getParser().ParseExpression(Offset))
4312 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004313
4314 // The expression has to be a constant. Memory references with relocations
4315 // don't come through here, as they use the <label> forms of the relevant
4316 // instructions.
4317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4318 if (!CE)
4319 return Error (E, "constant expression expected");
4320
Owen Anderson0da10cf2011-08-29 19:36:44 +00004321 // If the constant was #-0, represent it as INT32_MIN.
4322 int32_t Val = CE->getValue();
4323 if (isNegative && Val == 0)
4324 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4325
Jim Grosbach7ce05792011-08-03 23:50:40 +00004326 // Now we should have the closing ']'
4327 E = Parser.getTok().getLoc();
4328 if (Parser.getTok().isNot(AsmToken::RBrac))
4329 return Error(E, "']' expected");
4330 Parser.Lex(); // Eat right bracket token.
4331
4332 // Don't worry about range checking the value here. That's handled by
4333 // the is*() predicates.
4334 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004335 ARM_AM::no_shift, 0, 0,
4336 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004337
4338 // If there's a pre-indexing writeback marker, '!', just add it as a token
4339 // operand.
4340 if (Parser.getTok().is(AsmToken::Exclaim)) {
4341 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4342 Parser.Lex(); // Eat the '!'.
4343 }
4344
4345 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004346 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004347
4348 // The register offset is optionally preceded by a '+' or '-'
4349 bool isNegative = false;
4350 if (Parser.getTok().is(AsmToken::Minus)) {
4351 isNegative = true;
4352 Parser.Lex(); // Eat the '-'.
4353 } else if (Parser.getTok().is(AsmToken::Plus)) {
4354 // Nothing to do.
4355 Parser.Lex(); // Eat the '+'.
4356 }
4357
4358 E = Parser.getTok().getLoc();
4359 int OffsetRegNum = tryParseRegister();
4360 if (OffsetRegNum == -1)
4361 return Error(E, "register expected");
4362
4363 // If there's a shift operator, handle it.
4364 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004365 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004366 if (Parser.getTok().is(AsmToken::Comma)) {
4367 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004368 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004369 return true;
4370 }
4371
4372 // Now we should have the closing ']'
4373 E = Parser.getTok().getLoc();
4374 if (Parser.getTok().isNot(AsmToken::RBrac))
4375 return Error(E, "']' expected");
4376 Parser.Lex(); // Eat right bracket token.
4377
4378 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004379 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004380 S, E));
4381
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004382 // If there's a pre-indexing writeback marker, '!', just add it as a token
4383 // operand.
4384 if (Parser.getTok().is(AsmToken::Exclaim)) {
4385 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4386 Parser.Lex(); // Eat the '!'.
4387 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004388
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004389 return false;
4390}
4391
Jim Grosbach7ce05792011-08-03 23:50:40 +00004392/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004393/// ( lsl | lsr | asr | ror ) , # shift_amount
4394/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004395/// return true if it parses a shift otherwise it returns false.
4396bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4397 unsigned &Amount) {
4398 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004399 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004400 if (Tok.isNot(AsmToken::Identifier))
4401 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004402 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004403 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4404 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004405 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004406 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004407 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004408 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004409 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004410 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004411 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004412 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004413 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004414 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004415 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004416 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004417
Jim Grosbach7ce05792011-08-03 23:50:40 +00004418 // rrx stands alone.
4419 Amount = 0;
4420 if (St != ARM_AM::rrx) {
4421 Loc = Parser.getTok().getLoc();
4422 // A '#' and a shift amount.
4423 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004424 if (HashTok.isNot(AsmToken::Hash) &&
4425 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004426 return Error(HashTok.getLoc(), "'#' expected");
4427 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004428
Jim Grosbach7ce05792011-08-03 23:50:40 +00004429 const MCExpr *Expr;
4430 if (getParser().ParseExpression(Expr))
4431 return true;
4432 // Range check the immediate.
4433 // lsl, ror: 0 <= imm <= 31
4434 // lsr, asr: 0 <= imm <= 32
4435 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4436 if (!CE)
4437 return Error(Loc, "shift amount must be an immediate");
4438 int64_t Imm = CE->getValue();
4439 if (Imm < 0 ||
4440 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4441 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4442 return Error(Loc, "immediate shift value out of range");
4443 Amount = Imm;
4444 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004445
4446 return false;
4447}
4448
Jim Grosbach9d390362011-10-03 23:38:36 +00004449/// parseFPImm - A floating point immediate expression operand.
4450ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4451parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004452 // Anything that can accept a floating point constant as an operand
4453 // needs to go through here, as the regular ParseExpression is
4454 // integer only.
4455 //
4456 // This routine still creates a generic Immediate operand, containing
4457 // a bitcast of the 64-bit floating point value. The various operands
4458 // that accept floats can check whether the value is valid for them
4459 // via the standard is*() predicates.
4460
Jim Grosbach9d390362011-10-03 23:38:36 +00004461 SMLoc S = Parser.getTok().getLoc();
4462
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004463 if (Parser.getTok().isNot(AsmToken::Hash) &&
4464 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004465 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004466
4467 // Disambiguate the VMOV forms that can accept an FP immediate.
4468 // vmov.f32 <sreg>, #imm
4469 // vmov.f64 <dreg>, #imm
4470 // vmov.f32 <dreg>, #imm @ vector f32x2
4471 // vmov.f32 <qreg>, #imm @ vector f32x4
4472 //
4473 // There are also the NEON VMOV instructions which expect an
4474 // integer constant. Make sure we don't try to parse an FPImm
4475 // for these:
4476 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4477 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4478 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4479 TyOp->getToken() != ".f64"))
4480 return MatchOperand_NoMatch;
4481
Jim Grosbach9d390362011-10-03 23:38:36 +00004482 Parser.Lex(); // Eat the '#'.
4483
4484 // Handle negation, as that still comes through as a separate token.
4485 bool isNegative = false;
4486 if (Parser.getTok().is(AsmToken::Minus)) {
4487 isNegative = true;
4488 Parser.Lex();
4489 }
4490 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004491 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004492 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004493 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004494 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4495 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004496 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004497 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004498 Operands.push_back(ARMOperand::CreateImm(
4499 MCConstantExpr::Create(IntVal, getContext()),
4500 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004501 return MatchOperand_Success;
4502 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004503 // Also handle plain integers. Instructions which allow floating point
4504 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004505 if (Tok.is(AsmToken::Integer)) {
4506 int64_t Val = Tok.getIntVal();
4507 Parser.Lex(); // Eat the token.
4508 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004509 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004510 return MatchOperand_ParseFail;
4511 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004512 double RealVal = ARM_AM::getFPImmFloat(Val);
4513 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4514 Operands.push_back(ARMOperand::CreateImm(
4515 MCConstantExpr::Create(Val, getContext()), S,
4516 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004517 return MatchOperand_Success;
4518 }
4519
Jim Grosbachae69f702012-01-19 02:47:30 +00004520 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004521 return MatchOperand_ParseFail;
4522}
Jim Grosbach51222d12012-01-20 18:09:51 +00004523
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004524/// Parse a arm instruction operand. For now this parses the operand regardless
4525/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004526bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004527 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004528 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004529
4530 // Check if the current operand has a custom associated parser, if so, try to
4531 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004532 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4533 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004534 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004535 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4536 // there was a match, but an error occurred, in which case, just return that
4537 // the operand parsing failed.
4538 if (ResTy == MatchOperand_ParseFail)
4539 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004540
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004541 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004542 default:
4543 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004544 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004545 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004546 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004547 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004548 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004549 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004550 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004551 else if (Res == -1) // irrecoverable error
4552 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004553 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004554 if (Mnemonic == "vmrs" &&
4555 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004556 S = Parser.getTok().getLoc();
4557 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004558 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004559 return false;
4560 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004561
4562 // Fall though for the Identifier case that is not a register or a
4563 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004564 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004565 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004566 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004567 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004568 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004569 // This was not a register so parse other operands that start with an
4570 // identifier (like labels) as expressions and create them as immediates.
4571 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004572 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004573 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004574 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004575 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004576 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4577 return false;
4578 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004579 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004580 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004581 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004582 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004583 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004584 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004585 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004586 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004587 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004588
4589 if (Parser.getTok().isNot(AsmToken::Colon)) {
4590 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4591 const MCExpr *ImmVal;
4592 if (getParser().ParseExpression(ImmVal))
4593 return true;
4594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4595 if (CE) {
4596 int32_t Val = CE->getValue();
4597 if (isNegative && Val == 0)
4598 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4599 }
4600 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4601 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4602 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004603 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004604 // w/ a ':' after the '#', it's just like a plain ':'.
4605 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004606 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004607 case AsmToken::Colon: {
4608 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004609 // FIXME: Check it's an expression prefix,
4610 // e.g. (FOO - :lower16:BAR) isn't legal.
4611 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004612 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004613 return true;
4614
Evan Cheng75972122011-01-13 07:58:56 +00004615 const MCExpr *SubExprVal;
4616 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004617 return true;
4618
Evan Cheng75972122011-01-13 07:58:56 +00004619 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach1f9f5992012-09-21 00:26:53 +00004620 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004621 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004622 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004623 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004624 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004625 }
4626}
4627
Jim Grosbach1355cf12011-07-26 17:10:22 +00004628// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004629// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004630bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004631 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004632
4633 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004634 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004635 Parser.Lex(); // Eat ':'
4636
4637 if (getLexer().isNot(AsmToken::Identifier)) {
4638 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4639 return true;
4640 }
4641
4642 StringRef IDVal = Parser.getTok().getIdentifier();
4643 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004644 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004645 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004646 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004647 } else {
4648 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4649 return true;
4650 }
4651 Parser.Lex();
4652
4653 if (getLexer().isNot(AsmToken::Colon)) {
4654 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4655 return true;
4656 }
4657 Parser.Lex(); // Eat the last ':'
4658 return false;
4659}
4660
Daniel Dunbar352e1482011-01-11 15:59:50 +00004661/// \brief Given a mnemonic, split out possible predication code and carry
4662/// setting letters to form a canonical mnemonic and flags.
4663//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004664// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004665// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004666StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004667 unsigned &PredicationCode,
4668 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004669 unsigned &ProcessorIMod,
4670 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004671 PredicationCode = ARMCC::AL;
4672 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004673 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004674
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004675 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004676 //
4677 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004678 if ((Mnemonic == "movs" && isThumb()) ||
4679 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4680 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4681 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4682 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4683 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4684 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004685 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4686 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004687 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004688
Jim Grosbach3f00e312011-07-11 17:09:57 +00004689 // First, split out any predication code. Ignore mnemonics we know aren't
4690 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004691 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004692 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004693 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004694 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004695 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4696 .Case("eq", ARMCC::EQ)
4697 .Case("ne", ARMCC::NE)
4698 .Case("hs", ARMCC::HS)
4699 .Case("cs", ARMCC::HS)
4700 .Case("lo", ARMCC::LO)
4701 .Case("cc", ARMCC::LO)
4702 .Case("mi", ARMCC::MI)
4703 .Case("pl", ARMCC::PL)
4704 .Case("vs", ARMCC::VS)
4705 .Case("vc", ARMCC::VC)
4706 .Case("hi", ARMCC::HI)
4707 .Case("ls", ARMCC::LS)
4708 .Case("ge", ARMCC::GE)
4709 .Case("lt", ARMCC::LT)
4710 .Case("gt", ARMCC::GT)
4711 .Case("le", ARMCC::LE)
4712 .Case("al", ARMCC::AL)
4713 .Default(~0U);
4714 if (CC != ~0U) {
4715 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4716 PredicationCode = CC;
4717 }
Bill Wendling52925b62010-10-29 23:50:21 +00004718 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004719
Daniel Dunbar352e1482011-01-11 15:59:50 +00004720 // Next, determine if we have a carry setting bit. We explicitly ignore all
4721 // the instructions we know end in 's'.
4722 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004723 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004724 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4725 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4726 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004727 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004728 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004729 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004730 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004731 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004732 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004733 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4734 CarrySetting = true;
4735 }
4736
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004737 // The "cps" instruction can have a interrupt mode operand which is glued into
4738 // the mnemonic. Check if this is the case, split it and parse the imod op
4739 if (Mnemonic.startswith("cps")) {
4740 // Split out any imod code.
4741 unsigned IMod =
4742 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4743 .Case("ie", ARM_PROC::IE)
4744 .Case("id", ARM_PROC::ID)
4745 .Default(~0U);
4746 if (IMod != ~0U) {
4747 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4748 ProcessorIMod = IMod;
4749 }
4750 }
4751
Jim Grosbach89df9962011-08-26 21:43:41 +00004752 // The "it" instruction has the condition mask on the end of the mnemonic.
4753 if (Mnemonic.startswith("it")) {
4754 ITMask = Mnemonic.slice(2, Mnemonic.size());
4755 Mnemonic = Mnemonic.slice(0, 2);
4756 }
4757
Daniel Dunbar352e1482011-01-11 15:59:50 +00004758 return Mnemonic;
4759}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004760
4761/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4762/// inclusion of carry set or predication code operands.
4763//
4764// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004765void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004766getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004767 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004768 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4769 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004770 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004771 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004772 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004773 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004774 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004775 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004776 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004777 Mnemonic == "mla" || Mnemonic == "smlal" ||
4778 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004779 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004780 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004781 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004782
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004783 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4784 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4785 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4786 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004787 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4788 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004789 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004790 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4791 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4792 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004793 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4794 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004795 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004796 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004797 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004798 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004799
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004800 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004801 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004802 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004803 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004804 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004805}
4806
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004807bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4808 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004809 // FIXME: This is all horribly hacky. We really need a better way to deal
4810 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004811
4812 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4813 // another does not. Specifically, the MOVW instruction does not. So we
4814 // special case it here and remove the defaulted (non-setting) cc_out
4815 // operand if that's the instruction we're trying to match.
4816 //
4817 // We do this as post-processing of the explicit operands rather than just
4818 // conditionally adding the cc_out in the first place because we need
4819 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004820 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004821 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4822 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4823 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4824 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004825
4826 // Register-register 'add' for thumb does not have a cc_out operand
4827 // when there are only two register operands.
4828 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4829 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4830 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4831 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4832 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004833 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004834 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4835 // have to check the immediate range here since Thumb2 has a variant
4836 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004837 if (((isThumb() && Mnemonic == "add") ||
4838 (isThumbTwo() && Mnemonic == "sub")) &&
4839 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004840 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4841 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4842 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004843 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004844 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004845 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004846 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004847 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4848 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004849 // selecting via the generic "add" mnemonic, so to know that we
4850 // should remove the cc_out operand, we have to explicitly check that
4851 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004852 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4853 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004854 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4855 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4857 // Nest conditions rather than one big 'if' statement for readability.
4858 //
4859 // If either register is a high reg, it's either one of the SP
4860 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004861 // check against T3. If the second register is the PC, this is an
4862 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004863 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4864 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004865 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004866 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4867 return false;
4868 // If both registers are low, we're in an IT block, and the immediate is
4869 // in range, we should use encoding T1 instead, which has a cc_out.
4870 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004871 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004872 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4873 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4874 return false;
4875
4876 // Otherwise, we use encoding T4, which does not have a cc_out
4877 // operand.
4878 return true;
4879 }
4880
Jim Grosbach64944f42011-09-14 21:00:40 +00004881 // The thumb2 multiply instruction doesn't have a CCOut register, so
4882 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4883 // use the 16-bit encoding or not.
4884 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4885 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4886 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4887 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4888 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4889 // If the registers aren't low regs, the destination reg isn't the
4890 // same as one of the source regs, or the cc_out operand is zero
4891 // outside of an IT block, we have to use the 32-bit encoding, so
4892 // remove the cc_out operand.
4893 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4894 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004895 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004896 !inITBlock() ||
4897 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4898 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4899 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4900 static_cast<ARMOperand*>(Operands[4])->getReg())))
4901 return true;
4902
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004903 // Also check the 'mul' syntax variant that doesn't specify an explicit
4904 // destination register.
4905 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4906 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4907 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4908 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4909 // If the registers aren't low regs or the cc_out operand is zero
4910 // outside of an IT block, we have to use the 32-bit encoding, so
4911 // remove the cc_out operand.
4912 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4913 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4914 !inITBlock()))
4915 return true;
4916
Jim Grosbach64944f42011-09-14 21:00:40 +00004917
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004918
Jim Grosbachf69c8042011-08-24 21:42:27 +00004919 // Register-register 'add/sub' for thumb does not have a cc_out operand
4920 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4921 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4922 // right, this will result in better diagnostics (which operand is off)
4923 // anyway.
4924 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4925 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004926 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4927 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004928 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4929 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4930 (Operands.size() == 6 &&
4931 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004932 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004933
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004934 return false;
4935}
4936
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004937static bool isDataTypeToken(StringRef Tok) {
4938 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4939 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4940 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4941 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4942 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4943 Tok == ".f" || Tok == ".d";
4944}
4945
4946// FIXME: This bit should probably be handled via an explicit match class
4947// in the .td files that matches the suffix instead of having it be
4948// a literal string token the way it is now.
4949static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4950 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4951}
4952
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004953static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004954/// Parse an arm instruction mnemonic followed by its operands.
4955bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4956 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004957 // Apply mnemonic aliases before doing anything else, as the destination
4958 // mnemnonic may include suffices and we want to handle them normally.
4959 // The generic tblgen'erated code does this later, at the start of
4960 // MatchInstructionImpl(), but that's too late for aliases that include
4961 // any sort of suffix.
4962 unsigned AvailableFeatures = getAvailableFeatures();
4963 applyMnemonicAliases(Name, AvailableFeatures);
4964
Jim Grosbacha39cda72011-12-14 02:16:11 +00004965 // First check for the ARM-specific .req directive.
4966 if (Parser.getTok().is(AsmToken::Identifier) &&
4967 Parser.getTok().getIdentifier() == ".req") {
4968 parseDirectiveReq(Name, NameLoc);
4969 // We always return 'error' for this, as we're done with this
4970 // statement and don't need to match the 'instruction."
4971 return true;
4972 }
4973
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004974 // Create the leading tokens for the mnemonic, split by '.' characters.
4975 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004976 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004977
Daniel Dunbar352e1482011-01-11 15:59:50 +00004978 // Split out the predication code and carry setting flag from the mnemonic.
4979 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004980 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004981 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004982 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004983 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004984 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004985
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004986 // In Thumb1, only the branch (B) instruction can be predicated.
4987 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4988 Parser.EatToEndOfStatement();
4989 return Error(NameLoc, "conditional execution not supported in Thumb1");
4990 }
4991
Jim Grosbachffa32252011-07-19 19:13:28 +00004992 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4993
Jim Grosbach89df9962011-08-26 21:43:41 +00004994 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4995 // is the mask as it will be for the IT encoding if the conditional
4996 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4997 // where the conditional bit0 is zero, the instruction post-processing
4998 // will adjust the mask accordingly.
4999 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005000 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5001 if (ITMask.size() > 3) {
5002 Parser.EatToEndOfStatement();
5003 return Error(Loc, "too many conditions on IT instruction");
5004 }
Jim Grosbach89df9962011-08-26 21:43:41 +00005005 unsigned Mask = 8;
5006 for (unsigned i = ITMask.size(); i != 0; --i) {
5007 char pos = ITMask[i - 1];
5008 if (pos != 't' && pos != 'e') {
5009 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005010 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00005011 }
5012 Mask >>= 1;
5013 if (ITMask[i - 1] == 't')
5014 Mask |= 8;
5015 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005016 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00005017 }
5018
Jim Grosbachffa32252011-07-19 19:13:28 +00005019 // FIXME: This is all a pretty gross hack. We should automatically handle
5020 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00005021
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005022 // Next, add the CCOut and ConditionCode operands, if needed.
5023 //
5024 // For mnemonics which can ever incorporate a carry setting bit or predication
5025 // code, our matching model involves us always generating CCOut and
5026 // ConditionCode operands to match the mnemonic "as written" and then we let
5027 // the matcher deal with finding the right instruction or generating an
5028 // appropriate error.
5029 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005030 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005031
Jim Grosbach33c16a22011-07-14 22:04:21 +00005032 // If we had a carry-set on an instruction that can't do that, issue an
5033 // error.
5034 if (!CanAcceptCarrySet && CarrySetting) {
5035 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005036 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005037 "' can not set flags, but 's' suffix specified");
5038 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005039 // If we had a predication code on an instruction that can't do that, issue an
5040 // error.
5041 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5042 Parser.EatToEndOfStatement();
5043 return Error(NameLoc, "instruction '" + Mnemonic +
5044 "' is not predicable, but condition code specified");
5045 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005046
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005047 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005048 if (CanAcceptCarrySet) {
5049 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005050 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005051 Loc));
5052 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005053
5054 // Add the predication code operand, if necessary.
5055 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005056 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5057 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005058 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005059 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005060 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005061
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005062 // Add the processor imod operand, if necessary.
5063 if (ProcessorIMod) {
5064 Operands.push_back(ARMOperand::CreateImm(
5065 MCConstantExpr::Create(ProcessorIMod, getContext()),
5066 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005067 }
5068
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005069 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005070 while (Next != StringRef::npos) {
5071 Start = Next;
5072 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005073 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005074
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005075 // Some NEON instructions have an optional datatype suffix that is
5076 // completely ignored. Check for that.
5077 if (isDataTypeToken(ExtraToken) &&
5078 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5079 continue;
5080
Jim Grosbach81d2e392011-09-07 16:06:04 +00005081 if (ExtraToken != ".n") {
5082 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5083 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5084 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005085 }
5086
5087 // Read the remaining operands.
5088 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005089 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005090 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005091 Parser.EatToEndOfStatement();
5092 return true;
5093 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005094
5095 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005096 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005097
5098 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005099 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005100 Parser.EatToEndOfStatement();
5101 return true;
5102 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005103 }
5104 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005105
Chris Lattnercbf8a982010-09-11 16:18:25 +00005106 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005107 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005108 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005109 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005110 }
Bill Wendling146018f2010-11-06 21:42:12 +00005111
Chris Lattner34e53142010-09-08 05:10:46 +00005112 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005113
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005114 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5115 // do and don't have a cc_out optional-def operand. With some spot-checks
5116 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005117 // parse and adjust accordingly before actually matching. We shouldn't ever
5118 // try to remove a cc_out operand that was explicitly set on the the
5119 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5120 // table driven matcher doesn't fit well with the ARM instruction set.
5121 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005122 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5123 Operands.erase(Operands.begin() + 1);
5124 delete Op;
5125 }
5126
Jim Grosbachcf121c32011-07-28 21:57:55 +00005127 // ARM mode 'blx' need special handling, as the register operand version
5128 // is predicable, but the label operand version is not. So, we can't rely
5129 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005130 // a k_CondCode operand in the list. If we're trying to match the label
5131 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005132 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5133 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5134 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5135 Operands.erase(Operands.begin() + 1);
5136 delete Op;
5137 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005138
5139 // The vector-compare-to-zero instructions have a literal token "#0" at
5140 // the end that comes to here as an immediate operand. Convert it to a
5141 // token to play nicely with the matcher.
5142 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5143 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5144 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5145 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5146 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5147 if (CE && CE->getValue() == 0) {
5148 Operands.erase(Operands.begin() + 5);
5149 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5150 delete Op;
5151 }
5152 }
Jim Grosbach68259142011-10-03 22:30:24 +00005153 // VCMP{E} does the same thing, but with a different operand count.
5154 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5155 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5156 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5157 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5158 if (CE && CE->getValue() == 0) {
5159 Operands.erase(Operands.begin() + 4);
5160 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5161 delete Op;
5162 }
5163 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005164 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005165 // end. Convert it to a token here. Take care not to convert those
5166 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005167 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005168 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5169 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005170 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5171 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5172 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005173 if (CE && CE->getValue() == 0 &&
5174 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005175 // The cc_out operand matches the IT block.
5176 ((inITBlock() != CarrySetting) &&
5177 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005178 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005179 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005180 Operands.erase(Operands.begin() + 5);
5181 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5182 delete Op;
5183 }
5184 }
5185
Chris Lattner98986712010-01-14 22:21:20 +00005186 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005187}
5188
Jim Grosbach189610f2011-07-26 18:25:39 +00005189// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005190
5191// return 'true' if register list contains non-low GPR registers,
5192// 'false' otherwise. If Reg is in the register list or is HiReg, set
5193// 'containsReg' to true.
5194static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5195 unsigned HiReg, bool &containsReg) {
5196 containsReg = false;
5197 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5198 unsigned OpReg = Inst.getOperand(i).getReg();
5199 if (OpReg == Reg)
5200 containsReg = true;
5201 // Anything other than a low register isn't legal here.
5202 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5203 return true;
5204 }
5205 return false;
5206}
5207
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005208// Check if the specified regisgter is in the register list of the inst,
5209// starting at the indicated operand number.
5210static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5211 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5212 unsigned OpReg = Inst.getOperand(i).getReg();
5213 if (OpReg == Reg)
5214 return true;
5215 }
5216 return false;
5217}
5218
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005219// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5220// the ARMInsts array) instead. Getting that here requires awkward
5221// API changes, though. Better way?
5222namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005223extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005224}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005225static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005226 return ARMInsts[Opcode];
5227}
5228
Jim Grosbach189610f2011-07-26 18:25:39 +00005229// FIXME: We would really like to be able to tablegen'erate this.
5230bool ARMAsmParser::
5231validateInstruction(MCInst &Inst,
5232 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005233 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005234 SMLoc Loc = Operands[0]->getStartLoc();
5235 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005236 // NOTE: BKPT instruction has the interesting property of being
5237 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005238 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005239 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5240 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005241 unsigned bit = 1;
5242 if (ITState.FirstCond)
5243 ITState.FirstCond = false;
5244 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005245 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005246 // The instruction must be predicable.
5247 if (!MCID.isPredicable())
5248 return Error(Loc, "instructions in IT block must be predicable");
5249 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5250 unsigned ITCond = bit ? ITState.Cond :
5251 ARMCC::getOppositeCondition(ITState.Cond);
5252 if (Cond != ITCond) {
5253 // Find the condition code Operand to get its SMLoc information.
5254 SMLoc CondLoc;
5255 for (unsigned i = 1; i < Operands.size(); ++i)
5256 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5257 CondLoc = Operands[i]->getStartLoc();
5258 return Error(CondLoc, "incorrect condition in IT block; got '" +
5259 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5260 "', but expected '" +
5261 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5262 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005263 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005264 } else if (isThumbTwo() && MCID.isPredicable() &&
5265 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005266 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5267 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005268 return Error(Loc, "predicated instructions must be in IT block");
5269
Jim Grosbach189610f2011-07-26 18:25:39 +00005270 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005271 case ARM::LDRD:
5272 case ARM::LDRD_PRE:
5273 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005274 case ARM::LDREXD: {
5275 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005276 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5277 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005278 if (Rt2 != Rt + 1)
5279 return Error(Operands[3]->getStartLoc(),
5280 "destination operands must be sequential");
5281 return false;
5282 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005283 case ARM::STRD: {
5284 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005285 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5286 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach14605d12011-08-11 20:28:23 +00005287 if (Rt2 != Rt + 1)
5288 return Error(Operands[3]->getStartLoc(),
5289 "source operands must be sequential");
5290 return false;
5291 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005292 case ARM::STRD_PRE:
5293 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005294 case ARM::STREXD: {
5295 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005296 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5297 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005298 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005299 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005300 "source operands must be sequential");
5301 return false;
5302 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005303 case ARM::SBFX:
5304 case ARM::UBFX: {
5305 // width must be in range [1, 32-lsb]
5306 unsigned lsb = Inst.getOperand(2).getImm();
5307 unsigned widthm1 = Inst.getOperand(3).getImm();
5308 if (widthm1 >= 32 - lsb)
5309 return Error(Operands[5]->getStartLoc(),
5310 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005311 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005312 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005313 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005314 // If we're parsing Thumb2, the .w variant is available and handles
5315 // most cases that are normally illegal for a Thumb1 LDM
5316 // instruction. We'll make the transformation in processInstruction()
5317 // if necessary.
5318 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005319 // Thumb LDM instructions are writeback iff the base register is not
5320 // in the register list.
5321 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005322 bool hasWritebackToken =
5323 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5324 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005325 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005326 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005327 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5328 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005329 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005330 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005331 return Error(Operands[2]->getStartLoc(),
5332 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005333 // If we should not have writeback, there must not be a '!'. This is
5334 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005335 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005336 return Error(Operands[3]->getStartLoc(),
5337 "writeback operator '!' not allowed when base register "
5338 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005339
5340 break;
5341 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005342 case ARM::t2LDMIA_UPD: {
5343 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5344 return Error(Operands[4]->getStartLoc(),
5345 "writeback operator '!' not allowed when base register "
5346 "in register list");
5347 break;
5348 }
Chad Rosier64b34442012-08-30 23:20:38 +00005349 case ARM::tMUL: {
5350 // The second source operand must be the same register as the destination
5351 // operand.
Chad Rosier429af6f2012-08-31 17:24:10 +00005352 //
5353 // In this case, we must directly check the parsed operands because the
5354 // cvtThumbMultiply() function is written in such a way that it guarantees
5355 // this first statement is always true for the new Inst. Essentially, the
5356 // destination is unconditionally copied into the second source operand
5357 // without checking to see if it matches what we actually parsed.
Chad Rosier64b34442012-08-30 23:20:38 +00005358 if (Operands.size() == 6 &&
5359 (((ARMOperand*)Operands[3])->getReg() !=
5360 ((ARMOperand*)Operands[5])->getReg()) &&
5361 (((ARMOperand*)Operands[3])->getReg() !=
5362 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierfafa2832012-08-30 23:22:05 +00005363 return Error(Operands[3]->getStartLoc(),
5364 "destination register must match source register");
Chad Rosier64b34442012-08-30 23:20:38 +00005365 }
5366 break;
5367 }
Jim Grosbach54026372011-11-10 23:17:11 +00005368 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5369 // so only issue a diagnostic for thumb1. The instructions will be
5370 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005371 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005372 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005373 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5374 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005375 return Error(Operands[2]->getStartLoc(),
5376 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005377 break;
5378 }
5379 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005380 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005381 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5382 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005383 return Error(Operands[2]->getStartLoc(),
5384 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005385 break;
5386 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005387 case ARM::tSTMIA_UPD: {
5388 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005389 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005390 return Error(Operands[4]->getStartLoc(),
5391 "registers must be in range r0-r7");
5392 break;
5393 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005394 case ARM::tADDrSP: {
5395 // If the non-SP source operand and the destination operand are not the
5396 // same, we need thumb2 (for the wide encoding), or we have an error.
5397 if (!isThumbTwo() &&
5398 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5399 return Error(Operands[4]->getStartLoc(),
5400 "source register must be the same as destination");
5401 }
5402 break;
5403 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005404 }
5405
5406 return false;
5407}
5408
Jim Grosbachd7433e22012-01-23 23:45:44 +00005409static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005410 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005411 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005412 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005413 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5414 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5415 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5416 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5417 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5418 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5419 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5420 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5421 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005422
5423 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005424 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5425 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5426 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5427 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5428 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005429
Jim Grosbach7945ead2012-01-24 00:43:12 +00005430 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5431 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5432 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5433 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5434 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005435
Jim Grosbach7945ead2012-01-24 00:43:12 +00005436 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5437 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5438 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5439 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5440 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005441
Jim Grosbach4adb1822012-01-24 00:07:41 +00005442 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005443 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5444 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5445 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5446 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5447 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5448 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5449 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5450 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5451 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5452 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5453 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5454 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5455 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5456 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5457 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005458
Jim Grosbachd7433e22012-01-23 23:45:44 +00005459 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005460 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5461 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5462 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5463 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5464 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5465 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5466 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5467 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5468 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5469 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5470 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5471 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5472 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5473 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5474 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5475 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5476 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5477 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005478
Jim Grosbach88a54de2012-01-24 18:53:13 +00005479 // VST4LN
5480 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5481 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5482 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5483 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5484 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5485 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5486 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5487 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5488 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5489 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5490 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5491 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5492 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5493 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5494 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5495
Jim Grosbach539aab72012-01-24 00:58:13 +00005496 // VST4
5497 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5498 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5499 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5500 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5501 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5502 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5503 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5504 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5505 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5506 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5507 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5508 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5509 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5510 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5511 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5512 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5513 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5514 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005515 }
5516}
5517
Jim Grosbachd7433e22012-01-23 23:45:44 +00005518static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005519 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005520 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005521 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005522 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5523 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5524 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5525 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5526 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5527 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5528 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5529 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5530 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005531
5532 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005533 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5534 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5535 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5536 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5537 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5538 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5539 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5540 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5541 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5542 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5543 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5544 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5545 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5546 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5547 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005548
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005549 // VLD3DUP
5550 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5551 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5552 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5553 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5554 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5555 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5556 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5557 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5558 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5559 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5560 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5561 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5562 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5563 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5564 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5565 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5566 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5567 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5568
Jim Grosbach3a678af2012-01-23 21:53:26 +00005569 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005570 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5571 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5572 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5573 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5574 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5575 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5576 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5577 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5578 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5579 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5580 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5581 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5582 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5583 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5584 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005585
5586 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005587 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5588 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5589 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5590 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5591 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5592 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5593 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5594 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5595 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5596 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5597 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5598 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5599 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5600 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5601 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5602 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5603 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5604 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005605
Jim Grosbache983a132012-01-24 18:37:25 +00005606 // VLD4LN
5607 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5608 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5609 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5610 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5611 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5612 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5613 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5614 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5615 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5616 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5617 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5618 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5619 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5620 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5621 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5622
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005623 // VLD4DUP
5624 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5625 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5626 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5627 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5628 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5629 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5630 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5631 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5632 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5633 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5634 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5635 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5636 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5637 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5638 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5639 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5640 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5641 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5642
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005643 // VLD4
5644 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5645 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5646 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5647 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5648 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5649 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5650 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5651 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5652 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5653 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5654 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5655 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5656 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5657 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5658 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5659 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5660 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5661 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005662 }
5663}
5664
Jim Grosbach83ec8772011-11-10 23:42:14 +00005665bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005666processInstruction(MCInst &Inst,
5667 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5668 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005669 // Aliases for alternate PC+imm syntax of LDR instructions.
5670 case ARM::t2LDRpcrel:
5671 Inst.setOpcode(ARM::t2LDRpci);
5672 return true;
5673 case ARM::t2LDRBpcrel:
5674 Inst.setOpcode(ARM::t2LDRBpci);
5675 return true;
5676 case ARM::t2LDRHpcrel:
5677 Inst.setOpcode(ARM::t2LDRHpci);
5678 return true;
5679 case ARM::t2LDRSBpcrel:
5680 Inst.setOpcode(ARM::t2LDRSBpci);
5681 return true;
5682 case ARM::t2LDRSHpcrel:
5683 Inst.setOpcode(ARM::t2LDRSHpci);
5684 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005685 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005686 case ARM::VST1LNdWB_register_Asm_8:
5687 case ARM::VST1LNdWB_register_Asm_16:
5688 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005689 MCInst TmpInst;
5690 // Shuffle the operands around so the lane index operand is in the
5691 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005692 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005693 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005694 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5695 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5696 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5697 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5698 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5699 TmpInst.addOperand(Inst.getOperand(1)); // lane
5700 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5701 TmpInst.addOperand(Inst.getOperand(6));
5702 Inst = TmpInst;
5703 return true;
5704 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005705
Jim Grosbach8b31f952012-01-23 19:39:08 +00005706 case ARM::VST2LNdWB_register_Asm_8:
5707 case ARM::VST2LNdWB_register_Asm_16:
5708 case ARM::VST2LNdWB_register_Asm_32:
5709 case ARM::VST2LNqWB_register_Asm_16:
5710 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005711 MCInst TmpInst;
5712 // Shuffle the operands around so the lane index operand is in the
5713 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005714 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005715 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005716 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5717 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5718 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5719 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5720 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5722 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005723 TmpInst.addOperand(Inst.getOperand(1)); // lane
5724 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5725 TmpInst.addOperand(Inst.getOperand(6));
5726 Inst = TmpInst;
5727 return true;
5728 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005729
5730 case ARM::VST3LNdWB_register_Asm_8:
5731 case ARM::VST3LNdWB_register_Asm_16:
5732 case ARM::VST3LNdWB_register_Asm_32:
5733 case ARM::VST3LNqWB_register_Asm_16:
5734 case ARM::VST3LNqWB_register_Asm_32: {
5735 MCInst TmpInst;
5736 // Shuffle the operands around so the lane index operand is in the
5737 // right place.
5738 unsigned Spacing;
5739 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5740 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5741 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5742 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5743 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5744 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5746 Spacing));
5747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5748 Spacing * 2));
5749 TmpInst.addOperand(Inst.getOperand(1)); // lane
5750 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5751 TmpInst.addOperand(Inst.getOperand(6));
5752 Inst = TmpInst;
5753 return true;
5754 }
5755
Jim Grosbach88a54de2012-01-24 18:53:13 +00005756 case ARM::VST4LNdWB_register_Asm_8:
5757 case ARM::VST4LNdWB_register_Asm_16:
5758 case ARM::VST4LNdWB_register_Asm_32:
5759 case ARM::VST4LNqWB_register_Asm_16:
5760 case ARM::VST4LNqWB_register_Asm_32: {
5761 MCInst TmpInst;
5762 // Shuffle the operands around so the lane index operand is in the
5763 // right place.
5764 unsigned Spacing;
5765 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5766 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5767 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5768 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5769 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5770 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5772 Spacing));
5773 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5774 Spacing * 2));
5775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5776 Spacing * 3));
5777 TmpInst.addOperand(Inst.getOperand(1)); // lane
5778 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5779 TmpInst.addOperand(Inst.getOperand(6));
5780 Inst = TmpInst;
5781 return true;
5782 }
5783
Jim Grosbach8b31f952012-01-23 19:39:08 +00005784 case ARM::VST1LNdWB_fixed_Asm_8:
5785 case ARM::VST1LNdWB_fixed_Asm_16:
5786 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005787 MCInst TmpInst;
5788 // Shuffle the operands around so the lane index operand is in the
5789 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005790 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005791 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005792 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5793 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5794 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5795 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5796 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5797 TmpInst.addOperand(Inst.getOperand(1)); // lane
5798 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5799 TmpInst.addOperand(Inst.getOperand(5));
5800 Inst = TmpInst;
5801 return true;
5802 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005803
Jim Grosbach8b31f952012-01-23 19:39:08 +00005804 case ARM::VST2LNdWB_fixed_Asm_8:
5805 case ARM::VST2LNdWB_fixed_Asm_16:
5806 case ARM::VST2LNdWB_fixed_Asm_32:
5807 case ARM::VST2LNqWB_fixed_Asm_16:
5808 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005809 MCInst TmpInst;
5810 // Shuffle the operands around so the lane index operand is in the
5811 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005812 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005813 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005814 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5815 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5816 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5817 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5818 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5820 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005821 TmpInst.addOperand(Inst.getOperand(1)); // lane
5822 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5823 TmpInst.addOperand(Inst.getOperand(5));
5824 Inst = TmpInst;
5825 return true;
5826 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005827
5828 case ARM::VST3LNdWB_fixed_Asm_8:
5829 case ARM::VST3LNdWB_fixed_Asm_16:
5830 case ARM::VST3LNdWB_fixed_Asm_32:
5831 case ARM::VST3LNqWB_fixed_Asm_16:
5832 case ARM::VST3LNqWB_fixed_Asm_32: {
5833 MCInst TmpInst;
5834 // Shuffle the operands around so the lane index operand is in the
5835 // right place.
5836 unsigned Spacing;
5837 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5838 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5839 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5840 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5841 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5842 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5844 Spacing));
5845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5846 Spacing * 2));
5847 TmpInst.addOperand(Inst.getOperand(1)); // lane
5848 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5849 TmpInst.addOperand(Inst.getOperand(5));
5850 Inst = TmpInst;
5851 return true;
5852 }
5853
Jim Grosbach88a54de2012-01-24 18:53:13 +00005854 case ARM::VST4LNdWB_fixed_Asm_8:
5855 case ARM::VST4LNdWB_fixed_Asm_16:
5856 case ARM::VST4LNdWB_fixed_Asm_32:
5857 case ARM::VST4LNqWB_fixed_Asm_16:
5858 case ARM::VST4LNqWB_fixed_Asm_32: {
5859 MCInst TmpInst;
5860 // Shuffle the operands around so the lane index operand is in the
5861 // right place.
5862 unsigned Spacing;
5863 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5864 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5865 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5866 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5867 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5868 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5869 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5870 Spacing));
5871 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5872 Spacing * 2));
5873 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5874 Spacing * 3));
5875 TmpInst.addOperand(Inst.getOperand(1)); // lane
5876 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5877 TmpInst.addOperand(Inst.getOperand(5));
5878 Inst = TmpInst;
5879 return true;
5880 }
5881
Jim Grosbach8b31f952012-01-23 19:39:08 +00005882 case ARM::VST1LNdAsm_8:
5883 case ARM::VST1LNdAsm_16:
5884 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005885 MCInst TmpInst;
5886 // Shuffle the operands around so the lane index operand is in the
5887 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005888 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005889 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005890 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5891 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5892 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5893 TmpInst.addOperand(Inst.getOperand(1)); // lane
5894 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5895 TmpInst.addOperand(Inst.getOperand(5));
5896 Inst = TmpInst;
5897 return true;
5898 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005899
Jim Grosbach8b31f952012-01-23 19:39:08 +00005900 case ARM::VST2LNdAsm_8:
5901 case ARM::VST2LNdAsm_16:
5902 case ARM::VST2LNdAsm_32:
5903 case ARM::VST2LNqAsm_16:
5904 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005905 MCInst TmpInst;
5906 // Shuffle the operands around so the lane index operand is in the
5907 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005908 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005909 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005910 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5911 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5912 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005913 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5914 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005915 TmpInst.addOperand(Inst.getOperand(1)); // lane
5916 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5917 TmpInst.addOperand(Inst.getOperand(5));
5918 Inst = TmpInst;
5919 return true;
5920 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005921
5922 case ARM::VST3LNdAsm_8:
5923 case ARM::VST3LNdAsm_16:
5924 case ARM::VST3LNdAsm_32:
5925 case ARM::VST3LNqAsm_16:
5926 case ARM::VST3LNqAsm_32: {
5927 MCInst TmpInst;
5928 // Shuffle the operands around so the lane index operand is in the
5929 // right place.
5930 unsigned Spacing;
5931 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5932 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5933 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5934 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5935 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5936 Spacing));
5937 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5938 Spacing * 2));
5939 TmpInst.addOperand(Inst.getOperand(1)); // lane
5940 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5941 TmpInst.addOperand(Inst.getOperand(5));
5942 Inst = TmpInst;
5943 return true;
5944 }
5945
Jim Grosbach88a54de2012-01-24 18:53:13 +00005946 case ARM::VST4LNdAsm_8:
5947 case ARM::VST4LNdAsm_16:
5948 case ARM::VST4LNdAsm_32:
5949 case ARM::VST4LNqAsm_16:
5950 case ARM::VST4LNqAsm_32: {
5951 MCInst TmpInst;
5952 // Shuffle the operands around so the lane index operand is in the
5953 // right place.
5954 unsigned Spacing;
5955 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5956 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5957 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5958 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5960 Spacing));
5961 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5962 Spacing * 2));
5963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5964 Spacing * 3));
5965 TmpInst.addOperand(Inst.getOperand(1)); // lane
5966 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5967 TmpInst.addOperand(Inst.getOperand(5));
5968 Inst = TmpInst;
5969 return true;
5970 }
5971
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005972 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005973 case ARM::VLD1LNdWB_register_Asm_8:
5974 case ARM::VLD1LNdWB_register_Asm_16:
5975 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005976 MCInst TmpInst;
5977 // Shuffle the operands around so the lane index operand is in the
5978 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005979 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005980 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005981 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5982 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5983 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5984 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5985 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5986 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5987 TmpInst.addOperand(Inst.getOperand(1)); // lane
5988 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5989 TmpInst.addOperand(Inst.getOperand(6));
5990 Inst = TmpInst;
5991 return true;
5992 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005993
Jim Grosbach8b31f952012-01-23 19:39:08 +00005994 case ARM::VLD2LNdWB_register_Asm_8:
5995 case ARM::VLD2LNdWB_register_Asm_16:
5996 case ARM::VLD2LNdWB_register_Asm_32:
5997 case ARM::VLD2LNqWB_register_Asm_16:
5998 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005999 MCInst TmpInst;
6000 // Shuffle the operands around so the lane index operand is in the
6001 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006002 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006003 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006004 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6006 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006007 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6008 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6009 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6010 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6011 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6013 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006014 TmpInst.addOperand(Inst.getOperand(1)); // lane
6015 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6016 TmpInst.addOperand(Inst.getOperand(6));
6017 Inst = TmpInst;
6018 return true;
6019 }
6020
Jim Grosbach3a678af2012-01-23 21:53:26 +00006021 case ARM::VLD3LNdWB_register_Asm_8:
6022 case ARM::VLD3LNdWB_register_Asm_16:
6023 case ARM::VLD3LNdWB_register_Asm_32:
6024 case ARM::VLD3LNqWB_register_Asm_16:
6025 case ARM::VLD3LNqWB_register_Asm_32: {
6026 MCInst TmpInst;
6027 // Shuffle the operands around so the lane index operand is in the
6028 // right place.
6029 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006030 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006031 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6032 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6033 Spacing));
6034 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006035 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006036 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6037 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6038 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6039 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6040 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6041 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6042 Spacing));
6043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006044 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006045 TmpInst.addOperand(Inst.getOperand(1)); // lane
6046 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6047 TmpInst.addOperand(Inst.getOperand(6));
6048 Inst = TmpInst;
6049 return true;
6050 }
6051
Jim Grosbache983a132012-01-24 18:37:25 +00006052 case ARM::VLD4LNdWB_register_Asm_8:
6053 case ARM::VLD4LNdWB_register_Asm_16:
6054 case ARM::VLD4LNdWB_register_Asm_32:
6055 case ARM::VLD4LNqWB_register_Asm_16:
6056 case ARM::VLD4LNqWB_register_Asm_32: {
6057 MCInst TmpInst;
6058 // Shuffle the operands around so the lane index operand is in the
6059 // right place.
6060 unsigned Spacing;
6061 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6062 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6063 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6064 Spacing));
6065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6066 Spacing * 2));
6067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6068 Spacing * 3));
6069 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6070 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6071 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6072 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6073 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 Spacing));
6076 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 Spacing * 2));
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 Spacing * 3));
6080 TmpInst.addOperand(Inst.getOperand(1)); // lane
6081 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6082 TmpInst.addOperand(Inst.getOperand(6));
6083 Inst = TmpInst;
6084 return true;
6085 }
6086
Jim Grosbach8b31f952012-01-23 19:39:08 +00006087 case ARM::VLD1LNdWB_fixed_Asm_8:
6088 case ARM::VLD1LNdWB_fixed_Asm_16:
6089 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006090 MCInst TmpInst;
6091 // Shuffle the operands around so the lane index operand is in the
6092 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006093 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006094 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006095 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6096 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6097 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6098 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6099 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6100 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6101 TmpInst.addOperand(Inst.getOperand(1)); // lane
6102 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6103 TmpInst.addOperand(Inst.getOperand(5));
6104 Inst = TmpInst;
6105 return true;
6106 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006107
Jim Grosbach8b31f952012-01-23 19:39:08 +00006108 case ARM::VLD2LNdWB_fixed_Asm_8:
6109 case ARM::VLD2LNdWB_fixed_Asm_16:
6110 case ARM::VLD2LNdWB_fixed_Asm_32:
6111 case ARM::VLD2LNqWB_fixed_Asm_16:
6112 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006113 MCInst TmpInst;
6114 // Shuffle the operands around so the lane index operand is in the
6115 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006116 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006117 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006118 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6120 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006121 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6122 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6123 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6124 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6125 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006128 TmpInst.addOperand(Inst.getOperand(1)); // lane
6129 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6130 TmpInst.addOperand(Inst.getOperand(5));
6131 Inst = TmpInst;
6132 return true;
6133 }
6134
Jim Grosbach3a678af2012-01-23 21:53:26 +00006135 case ARM::VLD3LNdWB_fixed_Asm_8:
6136 case ARM::VLD3LNdWB_fixed_Asm_16:
6137 case ARM::VLD3LNdWB_fixed_Asm_32:
6138 case ARM::VLD3LNqWB_fixed_Asm_16:
6139 case ARM::VLD3LNqWB_fixed_Asm_32: {
6140 MCInst TmpInst;
6141 // Shuffle the operands around so the lane index operand is in the
6142 // right place.
6143 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006144 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006145 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6146 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 Spacing));
6148 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006149 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006150 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6151 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6152 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6153 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6154 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6156 Spacing));
6157 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006158 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006159 TmpInst.addOperand(Inst.getOperand(1)); // lane
6160 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6161 TmpInst.addOperand(Inst.getOperand(5));
6162 Inst = TmpInst;
6163 return true;
6164 }
6165
Jim Grosbache983a132012-01-24 18:37:25 +00006166 case ARM::VLD4LNdWB_fixed_Asm_8:
6167 case ARM::VLD4LNdWB_fixed_Asm_16:
6168 case ARM::VLD4LNdWB_fixed_Asm_32:
6169 case ARM::VLD4LNqWB_fixed_Asm_16:
6170 case ARM::VLD4LNqWB_fixed_Asm_32: {
6171 MCInst TmpInst;
6172 // Shuffle the operands around so the lane index operand is in the
6173 // right place.
6174 unsigned Spacing;
6175 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6176 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6178 Spacing));
6179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6180 Spacing * 2));
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6182 Spacing * 3));
6183 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6184 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6185 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6186 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6187 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6188 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 Spacing));
6190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 Spacing * 2));
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 Spacing * 3));
6194 TmpInst.addOperand(Inst.getOperand(1)); // lane
6195 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6196 TmpInst.addOperand(Inst.getOperand(5));
6197 Inst = TmpInst;
6198 return true;
6199 }
6200
Jim Grosbach8b31f952012-01-23 19:39:08 +00006201 case ARM::VLD1LNdAsm_8:
6202 case ARM::VLD1LNdAsm_16:
6203 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006204 MCInst TmpInst;
6205 // Shuffle the operands around so the lane index operand is in the
6206 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006207 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006208 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006209 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6210 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6211 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6212 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6213 TmpInst.addOperand(Inst.getOperand(1)); // lane
6214 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6215 TmpInst.addOperand(Inst.getOperand(5));
6216 Inst = TmpInst;
6217 return true;
6218 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006219
Jim Grosbach8b31f952012-01-23 19:39:08 +00006220 case ARM::VLD2LNdAsm_8:
6221 case ARM::VLD2LNdAsm_16:
6222 case ARM::VLD2LNdAsm_32:
6223 case ARM::VLD2LNqAsm_16:
6224 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006225 MCInst TmpInst;
6226 // Shuffle the operands around so the lane index operand is in the
6227 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006228 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006229 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006230 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006231 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6232 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006233 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6234 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6235 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6237 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006238 TmpInst.addOperand(Inst.getOperand(1)); // lane
6239 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6240 TmpInst.addOperand(Inst.getOperand(5));
6241 Inst = TmpInst;
6242 return true;
6243 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006244
6245 case ARM::VLD3LNdAsm_8:
6246 case ARM::VLD3LNdAsm_16:
6247 case ARM::VLD3LNdAsm_32:
6248 case ARM::VLD3LNqAsm_16:
6249 case ARM::VLD3LNqAsm_32: {
6250 MCInst TmpInst;
6251 // Shuffle the operands around so the lane index operand is in the
6252 // right place.
6253 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006254 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006255 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 Spacing));
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006259 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006260 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6261 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6262 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 Spacing));
6265 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006266 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006267 TmpInst.addOperand(Inst.getOperand(1)); // lane
6268 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6269 TmpInst.addOperand(Inst.getOperand(5));
6270 Inst = TmpInst;
6271 return true;
6272 }
6273
Jim Grosbache983a132012-01-24 18:37:25 +00006274 case ARM::VLD4LNdAsm_8:
6275 case ARM::VLD4LNdAsm_16:
6276 case ARM::VLD4LNdAsm_32:
6277 case ARM::VLD4LNqAsm_16:
6278 case ARM::VLD4LNqAsm_32: {
6279 MCInst TmpInst;
6280 // Shuffle the operands around so the lane index operand is in the
6281 // right place.
6282 unsigned Spacing;
6283 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6284 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6286 Spacing));
6287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6288 Spacing * 2));
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6290 Spacing * 3));
6291 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6292 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6293 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 Spacing));
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing * 2));
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing * 3));
6300 TmpInst.addOperand(Inst.getOperand(1)); // lane
6301 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6302 TmpInst.addOperand(Inst.getOperand(5));
6303 Inst = TmpInst;
6304 return true;
6305 }
6306
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006307 // VLD3DUP single 3-element structure to all lanes instructions.
6308 case ARM::VLD3DUPdAsm_8:
6309 case ARM::VLD3DUPdAsm_16:
6310 case ARM::VLD3DUPdAsm_32:
6311 case ARM::VLD3DUPqAsm_8:
6312 case ARM::VLD3DUPqAsm_16:
6313 case ARM::VLD3DUPqAsm_32: {
6314 MCInst TmpInst;
6315 unsigned Spacing;
6316 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6317 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6318 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6319 Spacing));
6320 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6321 Spacing * 2));
6322 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6323 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6324 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6325 TmpInst.addOperand(Inst.getOperand(4));
6326 Inst = TmpInst;
6327 return true;
6328 }
6329
6330 case ARM::VLD3DUPdWB_fixed_Asm_8:
6331 case ARM::VLD3DUPdWB_fixed_Asm_16:
6332 case ARM::VLD3DUPdWB_fixed_Asm_32:
6333 case ARM::VLD3DUPqWB_fixed_Asm_8:
6334 case ARM::VLD3DUPqWB_fixed_Asm_16:
6335 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6336 MCInst TmpInst;
6337 unsigned Spacing;
6338 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6339 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6341 Spacing));
6342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6343 Spacing * 2));
6344 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6345 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6346 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6347 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6348 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6349 TmpInst.addOperand(Inst.getOperand(4));
6350 Inst = TmpInst;
6351 return true;
6352 }
6353
6354 case ARM::VLD3DUPdWB_register_Asm_8:
6355 case ARM::VLD3DUPdWB_register_Asm_16:
6356 case ARM::VLD3DUPdWB_register_Asm_32:
6357 case ARM::VLD3DUPqWB_register_Asm_8:
6358 case ARM::VLD3DUPqWB_register_Asm_16:
6359 case ARM::VLD3DUPqWB_register_Asm_32: {
6360 MCInst TmpInst;
6361 unsigned Spacing;
6362 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6363 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 Spacing));
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 Spacing * 2));
6368 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6369 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6370 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6371 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6372 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6373 TmpInst.addOperand(Inst.getOperand(5));
6374 Inst = TmpInst;
6375 return true;
6376 }
6377
Jim Grosbachc387fc62012-01-23 23:20:46 +00006378 // VLD3 multiple 3-element structure instructions.
6379 case ARM::VLD3dAsm_8:
6380 case ARM::VLD3dAsm_16:
6381 case ARM::VLD3dAsm_32:
6382 case ARM::VLD3qAsm_8:
6383 case ARM::VLD3qAsm_16:
6384 case ARM::VLD3qAsm_32: {
6385 MCInst TmpInst;
6386 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006387 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006388 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6390 Spacing));
6391 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6392 Spacing * 2));
6393 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6394 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6395 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6396 TmpInst.addOperand(Inst.getOperand(4));
6397 Inst = TmpInst;
6398 return true;
6399 }
6400
6401 case ARM::VLD3dWB_fixed_Asm_8:
6402 case ARM::VLD3dWB_fixed_Asm_16:
6403 case ARM::VLD3dWB_fixed_Asm_32:
6404 case ARM::VLD3qWB_fixed_Asm_8:
6405 case ARM::VLD3qWB_fixed_Asm_16:
6406 case ARM::VLD3qWB_fixed_Asm_32: {
6407 MCInst TmpInst;
6408 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006409 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006410 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 Spacing));
6413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6414 Spacing * 2));
6415 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6416 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6417 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6418 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6419 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6420 TmpInst.addOperand(Inst.getOperand(4));
6421 Inst = TmpInst;
6422 return true;
6423 }
6424
6425 case ARM::VLD3dWB_register_Asm_8:
6426 case ARM::VLD3dWB_register_Asm_16:
6427 case ARM::VLD3dWB_register_Asm_32:
6428 case ARM::VLD3qWB_register_Asm_8:
6429 case ARM::VLD3qWB_register_Asm_16:
6430 case ARM::VLD3qWB_register_Asm_32: {
6431 MCInst TmpInst;
6432 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006433 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006434 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6436 Spacing));
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing * 2));
6439 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6441 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6442 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6443 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6444 TmpInst.addOperand(Inst.getOperand(5));
6445 Inst = TmpInst;
6446 return true;
6447 }
6448
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006449 // VLD4DUP single 3-element structure to all lanes instructions.
6450 case ARM::VLD4DUPdAsm_8:
6451 case ARM::VLD4DUPdAsm_16:
6452 case ARM::VLD4DUPdAsm_32:
6453 case ARM::VLD4DUPqAsm_8:
6454 case ARM::VLD4DUPqAsm_16:
6455 case ARM::VLD4DUPqAsm_32: {
6456 MCInst TmpInst;
6457 unsigned Spacing;
6458 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6459 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6460 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6461 Spacing));
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 Spacing * 2));
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 Spacing * 3));
6466 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6467 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6468 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6469 TmpInst.addOperand(Inst.getOperand(4));
6470 Inst = TmpInst;
6471 return true;
6472 }
6473
6474 case ARM::VLD4DUPdWB_fixed_Asm_8:
6475 case ARM::VLD4DUPdWB_fixed_Asm_16:
6476 case ARM::VLD4DUPdWB_fixed_Asm_32:
6477 case ARM::VLD4DUPqWB_fixed_Asm_8:
6478 case ARM::VLD4DUPqWB_fixed_Asm_16:
6479 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6480 MCInst TmpInst;
6481 unsigned Spacing;
6482 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6483 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6484 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6485 Spacing));
6486 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6487 Spacing * 2));
6488 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 Spacing * 3));
6490 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6491 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6492 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6493 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6494 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6495 TmpInst.addOperand(Inst.getOperand(4));
6496 Inst = TmpInst;
6497 return true;
6498 }
6499
6500 case ARM::VLD4DUPdWB_register_Asm_8:
6501 case ARM::VLD4DUPdWB_register_Asm_16:
6502 case ARM::VLD4DUPdWB_register_Asm_32:
6503 case ARM::VLD4DUPqWB_register_Asm_8:
6504 case ARM::VLD4DUPqWB_register_Asm_16:
6505 case ARM::VLD4DUPqWB_register_Asm_32: {
6506 MCInst TmpInst;
6507 unsigned Spacing;
6508 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6509 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6510 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6511 Spacing));
6512 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6513 Spacing * 2));
6514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6515 Spacing * 3));
6516 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6517 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6518 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6519 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6520 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6521 TmpInst.addOperand(Inst.getOperand(5));
6522 Inst = TmpInst;
6523 return true;
6524 }
6525
6526 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006527 case ARM::VLD4dAsm_8:
6528 case ARM::VLD4dAsm_16:
6529 case ARM::VLD4dAsm_32:
6530 case ARM::VLD4qAsm_8:
6531 case ARM::VLD4qAsm_16:
6532 case ARM::VLD4qAsm_32: {
6533 MCInst TmpInst;
6534 unsigned Spacing;
6535 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6536 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing));
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing * 2));
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6542 Spacing * 3));
6543 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6544 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6545 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6546 TmpInst.addOperand(Inst.getOperand(4));
6547 Inst = TmpInst;
6548 return true;
6549 }
6550
6551 case ARM::VLD4dWB_fixed_Asm_8:
6552 case ARM::VLD4dWB_fixed_Asm_16:
6553 case ARM::VLD4dWB_fixed_Asm_32:
6554 case ARM::VLD4qWB_fixed_Asm_8:
6555 case ARM::VLD4qWB_fixed_Asm_16:
6556 case ARM::VLD4qWB_fixed_Asm_32: {
6557 MCInst TmpInst;
6558 unsigned Spacing;
6559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 2));
6565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6566 Spacing * 3));
6567 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6568 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6569 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6570 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6571 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6572 TmpInst.addOperand(Inst.getOperand(4));
6573 Inst = TmpInst;
6574 return true;
6575 }
6576
6577 case ARM::VLD4dWB_register_Asm_8:
6578 case ARM::VLD4dWB_register_Asm_16:
6579 case ARM::VLD4dWB_register_Asm_32:
6580 case ARM::VLD4qWB_register_Asm_8:
6581 case ARM::VLD4qWB_register_Asm_16:
6582 case ARM::VLD4qWB_register_Asm_32: {
6583 MCInst TmpInst;
6584 unsigned Spacing;
6585 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6586 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6587 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6588 Spacing));
6589 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6590 Spacing * 2));
6591 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6592 Spacing * 3));
6593 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6594 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6595 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6596 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6597 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6598 TmpInst.addOperand(Inst.getOperand(5));
6599 Inst = TmpInst;
6600 return true;
6601 }
6602
Jim Grosbachd7433e22012-01-23 23:45:44 +00006603 // VST3 multiple 3-element structure instructions.
6604 case ARM::VST3dAsm_8:
6605 case ARM::VST3dAsm_16:
6606 case ARM::VST3dAsm_32:
6607 case ARM::VST3qAsm_8:
6608 case ARM::VST3qAsm_16:
6609 case ARM::VST3qAsm_32: {
6610 MCInst TmpInst;
6611 unsigned Spacing;
6612 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6613 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6614 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6615 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6616 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6617 Spacing));
6618 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6619 Spacing * 2));
6620 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6621 TmpInst.addOperand(Inst.getOperand(4));
6622 Inst = TmpInst;
6623 return true;
6624 }
6625
6626 case ARM::VST3dWB_fixed_Asm_8:
6627 case ARM::VST3dWB_fixed_Asm_16:
6628 case ARM::VST3dWB_fixed_Asm_32:
6629 case ARM::VST3qWB_fixed_Asm_8:
6630 case ARM::VST3qWB_fixed_Asm_16:
6631 case ARM::VST3qWB_fixed_Asm_32: {
6632 MCInst TmpInst;
6633 unsigned Spacing;
6634 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6635 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6636 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6637 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6638 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6639 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 Spacing));
6642 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6643 Spacing * 2));
6644 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6645 TmpInst.addOperand(Inst.getOperand(4));
6646 Inst = TmpInst;
6647 return true;
6648 }
6649
6650 case ARM::VST3dWB_register_Asm_8:
6651 case ARM::VST3dWB_register_Asm_16:
6652 case ARM::VST3dWB_register_Asm_32:
6653 case ARM::VST3qWB_register_Asm_8:
6654 case ARM::VST3qWB_register_Asm_16:
6655 case ARM::VST3qWB_register_Asm_32: {
6656 MCInst TmpInst;
6657 unsigned Spacing;
6658 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6659 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6660 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6661 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6662 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6663 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6664 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6665 Spacing));
6666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 Spacing * 2));
6668 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6669 TmpInst.addOperand(Inst.getOperand(5));
6670 Inst = TmpInst;
6671 return true;
6672 }
6673
Jim Grosbach539aab72012-01-24 00:58:13 +00006674 // VST4 multiple 3-element structure instructions.
6675 case ARM::VST4dAsm_8:
6676 case ARM::VST4dAsm_16:
6677 case ARM::VST4dAsm_32:
6678 case ARM::VST4qAsm_8:
6679 case ARM::VST4qAsm_16:
6680 case ARM::VST4qAsm_32: {
6681 MCInst TmpInst;
6682 unsigned Spacing;
6683 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6684 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6685 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6688 Spacing));
6689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6690 Spacing * 2));
6691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6692 Spacing * 3));
6693 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6694 TmpInst.addOperand(Inst.getOperand(4));
6695 Inst = TmpInst;
6696 return true;
6697 }
6698
6699 case ARM::VST4dWB_fixed_Asm_8:
6700 case ARM::VST4dWB_fixed_Asm_16:
6701 case ARM::VST4dWB_fixed_Asm_32:
6702 case ARM::VST4qWB_fixed_Asm_8:
6703 case ARM::VST4qWB_fixed_Asm_16:
6704 case ARM::VST4qWB_fixed_Asm_32: {
6705 MCInst TmpInst;
6706 unsigned Spacing;
6707 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6708 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6709 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6710 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6711 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6712 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6713 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6714 Spacing));
6715 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6716 Spacing * 2));
6717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6718 Spacing * 3));
6719 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6720 TmpInst.addOperand(Inst.getOperand(4));
6721 Inst = TmpInst;
6722 return true;
6723 }
6724
6725 case ARM::VST4dWB_register_Asm_8:
6726 case ARM::VST4dWB_register_Asm_16:
6727 case ARM::VST4dWB_register_Asm_32:
6728 case ARM::VST4qWB_register_Asm_8:
6729 case ARM::VST4qWB_register_Asm_16:
6730 case ARM::VST4qWB_register_Asm_32: {
6731 MCInst TmpInst;
6732 unsigned Spacing;
6733 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6734 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6735 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6736 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6737 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6738 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6739 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6740 Spacing));
6741 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6742 Spacing * 2));
6743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6744 Spacing * 3));
6745 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6746 TmpInst.addOperand(Inst.getOperand(5));
6747 Inst = TmpInst;
6748 return true;
6749 }
6750
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006751 // Handle encoding choice for the shift-immediate instructions.
6752 case ARM::t2LSLri:
6753 case ARM::t2LSRri:
6754 case ARM::t2ASRri: {
6755 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6756 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6757 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6758 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6759 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6760 unsigned NewOpc;
6761 switch (Inst.getOpcode()) {
6762 default: llvm_unreachable("unexpected opcode");
6763 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6764 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6765 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6766 }
6767 // The Thumb1 operands aren't in the same order. Awesome, eh?
6768 MCInst TmpInst;
6769 TmpInst.setOpcode(NewOpc);
6770 TmpInst.addOperand(Inst.getOperand(0));
6771 TmpInst.addOperand(Inst.getOperand(5));
6772 TmpInst.addOperand(Inst.getOperand(1));
6773 TmpInst.addOperand(Inst.getOperand(2));
6774 TmpInst.addOperand(Inst.getOperand(3));
6775 TmpInst.addOperand(Inst.getOperand(4));
6776 Inst = TmpInst;
6777 return true;
6778 }
6779 return false;
6780 }
6781
Jim Grosbach863d2af2011-12-13 22:45:11 +00006782 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006783 case ARM::t2MOVsr:
6784 case ARM::t2MOVSsr: {
6785 // Which instruction to expand to depends on the CCOut operand and
6786 // whether we're in an IT block if the register operands are low
6787 // registers.
6788 bool isNarrow = false;
6789 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6790 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6791 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6792 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6793 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6794 isNarrow = true;
6795 MCInst TmpInst;
6796 unsigned newOpc;
6797 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6798 default: llvm_unreachable("unexpected opcode!");
6799 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6800 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6801 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6802 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6803 }
6804 TmpInst.setOpcode(newOpc);
6805 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6806 if (isNarrow)
6807 TmpInst.addOperand(MCOperand::CreateReg(
6808 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6809 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6810 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6811 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6812 TmpInst.addOperand(Inst.getOperand(5));
6813 if (!isNarrow)
6814 TmpInst.addOperand(MCOperand::CreateReg(
6815 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6816 Inst = TmpInst;
6817 return true;
6818 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006819 case ARM::t2MOVsi:
6820 case ARM::t2MOVSsi: {
6821 // Which instruction to expand to depends on the CCOut operand and
6822 // whether we're in an IT block if the register operands are low
6823 // registers.
6824 bool isNarrow = false;
6825 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6826 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6827 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6828 isNarrow = true;
6829 MCInst TmpInst;
6830 unsigned newOpc;
6831 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6832 default: llvm_unreachable("unexpected opcode!");
6833 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6834 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6835 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6836 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006837 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006838 }
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006839 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6840 if (Amount == 32) Amount = 0;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006841 TmpInst.setOpcode(newOpc);
6842 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6843 if (isNarrow)
6844 TmpInst.addOperand(MCOperand::CreateReg(
6845 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6846 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006847 if (newOpc != ARM::t2RRX)
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006848 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006849 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6850 TmpInst.addOperand(Inst.getOperand(4));
6851 if (!isNarrow)
6852 TmpInst.addOperand(MCOperand::CreateReg(
6853 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6854 Inst = TmpInst;
6855 return true;
6856 }
6857 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006858 case ARM::ASRr:
6859 case ARM::LSRr:
6860 case ARM::LSLr:
6861 case ARM::RORr: {
6862 ARM_AM::ShiftOpc ShiftTy;
6863 switch(Inst.getOpcode()) {
6864 default: llvm_unreachable("unexpected opcode!");
6865 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6866 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6867 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6868 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6869 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006870 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6871 MCInst TmpInst;
6872 TmpInst.setOpcode(ARM::MOVsr);
6873 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6874 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6875 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6876 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6877 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6878 TmpInst.addOperand(Inst.getOperand(4));
6879 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6880 Inst = TmpInst;
6881 return true;
6882 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006883 case ARM::ASRi:
6884 case ARM::LSRi:
6885 case ARM::LSLi:
6886 case ARM::RORi: {
6887 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006888 switch(Inst.getOpcode()) {
6889 default: llvm_unreachable("unexpected opcode!");
6890 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6891 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6892 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6893 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6894 }
6895 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006896 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006897 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006898 // A shift by 32 should be encoded as 0 when permitted
6899 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6900 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006901 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006902 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006903 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006904 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6905 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006906 if (Opc == ARM::MOVsi)
6907 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006908 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6909 TmpInst.addOperand(Inst.getOperand(4));
6910 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6911 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006912 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006913 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006914 case ARM::RRXi: {
6915 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6916 MCInst TmpInst;
6917 TmpInst.setOpcode(ARM::MOVsi);
6918 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6919 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6920 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6921 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6922 TmpInst.addOperand(Inst.getOperand(3));
6923 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6924 Inst = TmpInst;
6925 return true;
6926 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006927 case ARM::t2LDMIA_UPD: {
6928 // If this is a load of a single register, then we should use
6929 // a post-indexed LDR instruction instead, per the ARM ARM.
6930 if (Inst.getNumOperands() != 5)
6931 return false;
6932 MCInst TmpInst;
6933 TmpInst.setOpcode(ARM::t2LDR_POST);
6934 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6935 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6936 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6937 TmpInst.addOperand(MCOperand::CreateImm(4));
6938 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6939 TmpInst.addOperand(Inst.getOperand(3));
6940 Inst = TmpInst;
6941 return true;
6942 }
6943 case ARM::t2STMDB_UPD: {
6944 // If this is a store of a single register, then we should use
6945 // a pre-indexed STR instruction instead, per the ARM ARM.
6946 if (Inst.getNumOperands() != 5)
6947 return false;
6948 MCInst TmpInst;
6949 TmpInst.setOpcode(ARM::t2STR_PRE);
6950 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6951 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6953 TmpInst.addOperand(MCOperand::CreateImm(-4));
6954 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6955 TmpInst.addOperand(Inst.getOperand(3));
6956 Inst = TmpInst;
6957 return true;
6958 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006959 case ARM::LDMIA_UPD:
6960 // If this is a load of a single register via a 'pop', then we should use
6961 // a post-indexed LDR instruction instead, per the ARM ARM.
6962 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6963 Inst.getNumOperands() == 5) {
6964 MCInst TmpInst;
6965 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6966 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6967 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6968 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6969 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6970 TmpInst.addOperand(MCOperand::CreateImm(4));
6971 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6972 TmpInst.addOperand(Inst.getOperand(3));
6973 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006974 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006975 }
6976 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006977 case ARM::STMDB_UPD:
6978 // If this is a store of a single register via a 'push', then we should use
6979 // a pre-indexed STR instruction instead, per the ARM ARM.
6980 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6981 Inst.getNumOperands() == 5) {
6982 MCInst TmpInst;
6983 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6984 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6985 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6986 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6987 TmpInst.addOperand(MCOperand::CreateImm(-4));
6988 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6989 TmpInst.addOperand(Inst.getOperand(3));
6990 Inst = TmpInst;
6991 }
6992 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006993 case ARM::t2ADDri12:
6994 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6995 // mnemonic was used (not "addw"), encoding T3 is preferred.
6996 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6997 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6998 break;
6999 Inst.setOpcode(ARM::t2ADDri);
7000 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7001 break;
7002 case ARM::t2SUBri12:
7003 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7004 // mnemonic was used (not "subw"), encoding T3 is preferred.
7005 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7006 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7007 break;
7008 Inst.setOpcode(ARM::t2SUBri);
7009 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7010 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007011 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00007012 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7013 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7014 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7015 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007016 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007017 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007018 return true;
7019 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007020 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00007021 case ARM::tSUBi8:
7022 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7023 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7024 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7025 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007026 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00007027 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007028 return true;
7029 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00007030 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00007031 case ARM::t2ADDri:
7032 case ARM::t2SUBri: {
7033 // If the destination and first source operand are the same, and
7034 // the flags are compatible with the current IT status, use encoding T2
7035 // instead of T3. For compatibility with the system 'as'. Make sure the
7036 // wide encoding wasn't explicit.
7037 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00007038 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00007039 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7040 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7041 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7042 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7043 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7044 break;
7045 MCInst TmpInst;
7046 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7047 ARM::tADDi8 : ARM::tSUBi8);
7048 TmpInst.addOperand(Inst.getOperand(0));
7049 TmpInst.addOperand(Inst.getOperand(5));
7050 TmpInst.addOperand(Inst.getOperand(0));
7051 TmpInst.addOperand(Inst.getOperand(2));
7052 TmpInst.addOperand(Inst.getOperand(3));
7053 TmpInst.addOperand(Inst.getOperand(4));
7054 Inst = TmpInst;
7055 return true;
7056 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007057 case ARM::t2ADDrr: {
7058 // If the destination and first source operand are the same, and
7059 // there's no setting of the flags, use encoding T2 instead of T3.
7060 // Note that this is only for ADD, not SUB. This mirrors the system
7061 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7062 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7063 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007064 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7065 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007066 break;
7067 MCInst TmpInst;
7068 TmpInst.setOpcode(ARM::tADDhirr);
7069 TmpInst.addOperand(Inst.getOperand(0));
7070 TmpInst.addOperand(Inst.getOperand(0));
7071 TmpInst.addOperand(Inst.getOperand(2));
7072 TmpInst.addOperand(Inst.getOperand(3));
7073 TmpInst.addOperand(Inst.getOperand(4));
7074 Inst = TmpInst;
7075 return true;
7076 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007077 case ARM::tADDrSP: {
7078 // If the non-SP source operand and the destination operand are not the
7079 // same, we need to use the 32-bit encoding if it's available.
7080 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7081 Inst.setOpcode(ARM::t2ADDrr);
7082 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7083 return true;
7084 }
7085 break;
7086 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007087 case ARM::tB:
7088 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007089 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007090 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007091 return true;
7092 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007093 break;
7094 case ARM::t2B:
7095 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007096 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007097 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007098 return true;
7099 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007100 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007101 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007102 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007103 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007104 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007105 return true;
7106 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007107 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007108 case ARM::tBcc:
7109 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007110 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007111 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007112 return true;
7113 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007114 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007115 case ARM::tLDMIA: {
7116 // If the register list contains any high registers, or if the writeback
7117 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7118 // instead if we're in Thumb2. Otherwise, this should have generated
7119 // an error in validateInstruction().
7120 unsigned Rn = Inst.getOperand(0).getReg();
7121 bool hasWritebackToken =
7122 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7123 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7124 bool listContainsBase;
7125 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7126 (!listContainsBase && !hasWritebackToken) ||
7127 (listContainsBase && hasWritebackToken)) {
7128 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7129 assert (isThumbTwo());
7130 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7131 // If we're switching to the updating version, we need to insert
7132 // the writeback tied operand.
7133 if (hasWritebackToken)
7134 Inst.insert(Inst.begin(),
7135 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007136 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007137 }
7138 break;
7139 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007140 case ARM::tSTMIA_UPD: {
7141 // If the register list contains any high registers, we need to use
7142 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7143 // should have generated an error in validateInstruction().
7144 unsigned Rn = Inst.getOperand(0).getReg();
7145 bool listContainsBase;
7146 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7147 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7148 assert (isThumbTwo());
7149 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007150 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007151 }
7152 break;
7153 }
Jim Grosbach54026372011-11-10 23:17:11 +00007154 case ARM::tPOP: {
7155 bool listContainsBase;
7156 // If the register list contains any high registers, we need to use
7157 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7158 // should have generated an error in validateInstruction().
7159 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007160 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007161 assert (isThumbTwo());
7162 Inst.setOpcode(ARM::t2LDMIA_UPD);
7163 // Add the base register and writeback operands.
7164 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7165 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007166 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007167 }
7168 case ARM::tPUSH: {
7169 bool listContainsBase;
7170 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007171 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007172 assert (isThumbTwo());
7173 Inst.setOpcode(ARM::t2STMDB_UPD);
7174 // Add the base register and writeback operands.
7175 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7176 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007177 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007178 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007179 case ARM::t2MOVi: {
7180 // If we can use the 16-bit encoding and the user didn't explicitly
7181 // request the 32-bit variant, transform it here.
7182 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007183 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007184 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7185 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7186 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007187 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7188 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7189 // The operands aren't in the same order for tMOVi8...
7190 MCInst TmpInst;
7191 TmpInst.setOpcode(ARM::tMOVi8);
7192 TmpInst.addOperand(Inst.getOperand(0));
7193 TmpInst.addOperand(Inst.getOperand(4));
7194 TmpInst.addOperand(Inst.getOperand(1));
7195 TmpInst.addOperand(Inst.getOperand(2));
7196 TmpInst.addOperand(Inst.getOperand(3));
7197 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007198 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007199 }
7200 break;
7201 }
7202 case ARM::t2MOVr: {
7203 // If we can use the 16-bit encoding and the user didn't explicitly
7204 // request the 32-bit variant, transform it here.
7205 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7206 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7207 Inst.getOperand(2).getImm() == ARMCC::AL &&
7208 Inst.getOperand(4).getReg() == ARM::CPSR &&
7209 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7210 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7211 // The operands aren't the same for tMOV[S]r... (no cc_out)
7212 MCInst TmpInst;
7213 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7214 TmpInst.addOperand(Inst.getOperand(0));
7215 TmpInst.addOperand(Inst.getOperand(1));
7216 TmpInst.addOperand(Inst.getOperand(2));
7217 TmpInst.addOperand(Inst.getOperand(3));
7218 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007219 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007220 }
7221 break;
7222 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007223 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007224 case ARM::t2SXTB:
7225 case ARM::t2UXTH:
7226 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007227 // If we can use the 16-bit encoding and the user didn't explicitly
7228 // request the 32-bit variant, transform it here.
7229 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7230 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7231 Inst.getOperand(2).getImm() == 0 &&
7232 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7233 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007234 unsigned NewOpc;
7235 switch (Inst.getOpcode()) {
7236 default: llvm_unreachable("Illegal opcode!");
7237 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7238 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7239 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7240 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7241 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007242 // The operands aren't the same for thumb1 (no rotate operand).
7243 MCInst TmpInst;
7244 TmpInst.setOpcode(NewOpc);
7245 TmpInst.addOperand(Inst.getOperand(0));
7246 TmpInst.addOperand(Inst.getOperand(1));
7247 TmpInst.addOperand(Inst.getOperand(3));
7248 TmpInst.addOperand(Inst.getOperand(4));
7249 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007250 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007251 }
7252 break;
7253 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007254 case ARM::MOVsi: {
7255 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007256 // rrx shifts and asr/lsr of #32 is encoded as 0
7257 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7258 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007259 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7260 // Shifting by zero is accepted as a vanilla 'MOVr'
7261 MCInst TmpInst;
7262 TmpInst.setOpcode(ARM::MOVr);
7263 TmpInst.addOperand(Inst.getOperand(0));
7264 TmpInst.addOperand(Inst.getOperand(1));
7265 TmpInst.addOperand(Inst.getOperand(3));
7266 TmpInst.addOperand(Inst.getOperand(4));
7267 TmpInst.addOperand(Inst.getOperand(5));
7268 Inst = TmpInst;
7269 return true;
7270 }
7271 return false;
7272 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007273 case ARM::ANDrsi:
7274 case ARM::ORRrsi:
7275 case ARM::EORrsi:
7276 case ARM::BICrsi:
7277 case ARM::SUBrsi:
7278 case ARM::ADDrsi: {
7279 unsigned newOpc;
7280 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7281 if (SOpc == ARM_AM::rrx) return false;
7282 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007283 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007284 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7285 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7286 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7287 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7288 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7289 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7290 }
7291 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton8ed97ef2012-07-09 16:31:14 +00007292 // The exception is for right shifts, where 0 == 32
7293 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7294 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007295 MCInst TmpInst;
7296 TmpInst.setOpcode(newOpc);
7297 TmpInst.addOperand(Inst.getOperand(0));
7298 TmpInst.addOperand(Inst.getOperand(1));
7299 TmpInst.addOperand(Inst.getOperand(2));
7300 TmpInst.addOperand(Inst.getOperand(4));
7301 TmpInst.addOperand(Inst.getOperand(5));
7302 TmpInst.addOperand(Inst.getOperand(6));
7303 Inst = TmpInst;
7304 return true;
7305 }
7306 return false;
7307 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007308 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007309 case ARM::t2IT: {
7310 // The mask bits for all but the first condition are represented as
7311 // the low bit of the condition code value implies 't'. We currently
7312 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007313 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007314 MCOperand &MO = Inst.getOperand(1);
7315 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007316 unsigned OrigMask = Mask;
7317 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007318 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007319 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7320 for (unsigned i = 3; i != TZ; --i)
7321 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007322 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007323 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007324
7325 // Set up the IT block state according to the IT instruction we just
7326 // matched.
7327 assert(!inITBlock() && "nested IT blocks?!");
7328 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7329 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7330 ITState.CurPosition = 0;
7331 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007332 break;
7333 }
Richard Barton2b6652f2012-07-09 16:12:24 +00007334 case ARM::t2LSLrr:
7335 case ARM::t2LSRrr:
7336 case ARM::t2ASRrr:
7337 case ARM::t2SBCrr:
7338 case ARM::t2RORrr:
7339 case ARM::t2BICrr:
7340 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007341 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007342 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7343 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7344 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton874b8632012-07-09 18:30:56 +00007345 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7346 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007347 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7348 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7349 unsigned NewOpc;
7350 switch (Inst.getOpcode()) {
7351 default: llvm_unreachable("unexpected opcode");
7352 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7353 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7354 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7355 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7356 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7357 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7358 }
7359 MCInst TmpInst;
7360 TmpInst.setOpcode(NewOpc);
7361 TmpInst.addOperand(Inst.getOperand(0));
7362 TmpInst.addOperand(Inst.getOperand(5));
7363 TmpInst.addOperand(Inst.getOperand(1));
7364 TmpInst.addOperand(Inst.getOperand(2));
7365 TmpInst.addOperand(Inst.getOperand(3));
7366 TmpInst.addOperand(Inst.getOperand(4));
7367 Inst = TmpInst;
7368 return true;
7369 }
7370 return false;
7371 }
7372 case ARM::t2ANDrr:
7373 case ARM::t2EORrr:
7374 case ARM::t2ADCrr:
7375 case ARM::t2ORRrr:
7376 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007377 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007378 // These instructions are special in that they are commutable, so shorter encodings
7379 // are available more often.
7380 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7381 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7382 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7383 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton874b8632012-07-09 18:30:56 +00007384 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7385 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007386 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7387 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7388 unsigned NewOpc;
7389 switch (Inst.getOpcode()) {
7390 default: llvm_unreachable("unexpected opcode");
7391 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7392 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7393 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7394 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7395 }
7396 MCInst TmpInst;
7397 TmpInst.setOpcode(NewOpc);
7398 TmpInst.addOperand(Inst.getOperand(0));
7399 TmpInst.addOperand(Inst.getOperand(5));
7400 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7401 TmpInst.addOperand(Inst.getOperand(1));
7402 TmpInst.addOperand(Inst.getOperand(2));
7403 } else {
7404 TmpInst.addOperand(Inst.getOperand(2));
7405 TmpInst.addOperand(Inst.getOperand(1));
7406 }
7407 TmpInst.addOperand(Inst.getOperand(3));
7408 TmpInst.addOperand(Inst.getOperand(4));
7409 Inst = TmpInst;
7410 return true;
7411 }
7412 return false;
7413 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007414 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007415 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007416}
7417
Jim Grosbach47a0d522011-08-16 20:45:50 +00007418unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7419 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7420 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007421 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007422 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007423 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7424 assert(MCID.hasOptionalDef() &&
7425 "optionally flag setting instruction missing optional def operand");
7426 assert(MCID.NumOperands == Inst.getNumOperands() &&
7427 "operand count mismatch!");
7428 // Find the optional-def operand (cc_out).
7429 unsigned OpNo;
7430 for (OpNo = 0;
7431 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7432 ++OpNo)
7433 ;
7434 // If we're parsing Thumb1, reject it completely.
7435 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7436 return Match_MnemonicFail;
7437 // If we're parsing Thumb2, which form is legal depends on whether we're
7438 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007439 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7440 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007441 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007442 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7443 inITBlock())
7444 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007445 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007446 // Some high-register supporting Thumb1 encodings only allow both registers
7447 // to be from r0-r7 when in Thumb2.
7448 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7449 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7450 isARMLowRegister(Inst.getOperand(2).getReg()))
7451 return Match_RequiresThumb2;
7452 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007453 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007454 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7455 isARMLowRegister(Inst.getOperand(1).getReg()))
7456 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007457 return Match_Success;
7458}
7459
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007460static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007461bool ARMAsmParser::
7462MatchAndEmitInstruction(SMLoc IDLoc,
7463 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7464 MCStreamer &Out) {
7465 MCInst Inst;
Chad Rosier3a86e132012-09-03 02:06:46 +00007466 unsigned Kind;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007467 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007468 unsigned MatchResult;
Chad Rosier3a86e132012-09-03 02:06:46 +00007469
Chad Rosierc4d25602012-09-03 03:16:09 +00007470 MatchResult = MatchInstructionImpl(Operands, Kind, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007471 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007472 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007473 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007474 // Context sensitive operand constraints aren't handled by the matcher,
7475 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007476 if (validateInstruction(Inst, Operands)) {
7477 // Still progress the IT block, otherwise one wrong condition causes
7478 // nasty cascading errors.
7479 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007480 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007481 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007482
Jim Grosbachf8fce712011-08-11 17:35:48 +00007483 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007484 // encoding is selected. Loop on it while changes happen so the
7485 // individual transformations can chain off each other. E.g.,
7486 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7487 while (processInstruction(Inst, Operands))
7488 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007489
Jim Grosbacha1109882011-09-02 23:22:08 +00007490 // Only move forward at the very end so that everything in validate
7491 // and process gets a consistent answer about whether we're in an IT
7492 // block.
7493 forwardITPosition();
7494
Jim Grosbach74423e32012-01-25 19:52:01 +00007495 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7496 // doesn't actually encode.
7497 if (Inst.getOpcode() == ARM::ITasm)
7498 return false;
7499
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007500 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007501 Out.EmitInstruction(Inst);
7502 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007503 case Match_MissingFeature: {
7504 assert(ErrorInfo && "Unknown missing feature!");
7505 // Special case the error message for the very common case where only
7506 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7507 std::string Msg = "instruction requires:";
7508 unsigned Mask = 1;
7509 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7510 if (ErrorInfo & Mask) {
7511 Msg += " ";
7512 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7513 }
7514 Mask <<= 1;
7515 }
7516 return Error(IDLoc, Msg);
7517 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007518 case Match_InvalidOperand: {
7519 SMLoc ErrorLoc = IDLoc;
7520 if (ErrorInfo != ~0U) {
7521 if (ErrorInfo >= Operands.size())
7522 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007523
Chris Lattnere73d4f82010-10-28 21:41:58 +00007524 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7525 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7526 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007527
Chris Lattnere73d4f82010-10-28 21:41:58 +00007528 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007529 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007530 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007531 return Error(IDLoc, "invalid instruction",
7532 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007533 case Match_RequiresNotITBlock:
7534 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007535 case Match_RequiresITBlock:
7536 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007537 case Match_RequiresV6:
7538 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7539 case Match_RequiresThumb2:
7540 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach70c9bf32012-06-22 23:56:48 +00007541 case Match_ImmRange0_15: {
7542 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7543 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7544 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7545 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007546 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007547
Eric Christopherc223e2b2010-10-29 09:26:59 +00007548 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007549}
7550
Jim Grosbach1355cf12011-07-26 17:10:22 +00007551/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007552bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7553 StringRef IDVal = DirectiveID.getIdentifier();
7554 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007555 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007556 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007557 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007558 else if (IDVal == ".arm")
7559 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007560 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007561 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007562 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007563 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007564 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007565 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007566 else if (IDVal == ".unreq")
7567 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007568 else if (IDVal == ".arch")
7569 return parseDirectiveArch(DirectiveID.getLoc());
7570 else if (IDVal == ".eabi_attribute")
7571 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007572 return true;
7573}
7574
Jim Grosbach1355cf12011-07-26 17:10:22 +00007575/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007576/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007577bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007578 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7579 for (;;) {
7580 const MCExpr *Value;
7581 if (getParser().ParseExpression(Value))
7582 return true;
7583
Chris Lattneraaec2052010-01-19 19:46:13 +00007584 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007585
7586 if (getLexer().is(AsmToken::EndOfStatement))
7587 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007588
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007589 // FIXME: Improve diagnostic.
7590 if (getLexer().isNot(AsmToken::Comma))
7591 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007592 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007593 }
7594 }
7595
Sean Callananb9a25b72010-01-19 20:27:46 +00007596 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007597 return false;
7598}
7599
Jim Grosbach1355cf12011-07-26 17:10:22 +00007600/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007601/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007602bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007603 if (getLexer().isNot(AsmToken::EndOfStatement))
7604 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007605 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007606
Jim Grosbach9a70df92011-12-07 18:04:19 +00007607 if (!isThumb())
7608 SwitchMode();
7609 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7610 return false;
7611}
7612
7613/// parseDirectiveARM
7614/// ::= .arm
7615bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7616 if (getLexer().isNot(AsmToken::EndOfStatement))
7617 return Error(L, "unexpected token in directive");
7618 Parser.Lex();
7619
7620 if (isThumb())
7621 SwitchMode();
7622 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007623 return false;
7624}
7625
Jim Grosbach1355cf12011-07-26 17:10:22 +00007626/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007627/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007628bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007629 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7630 bool isMachO = MAI.hasSubsectionsViaSymbols();
7631 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007632 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007633
Jim Grosbachde4d8392011-12-21 22:30:16 +00007634 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007635 // ELF doesn't
7636 if (isMachO) {
7637 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007638 if (Tok.isNot(AsmToken::EndOfStatement)) {
7639 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7640 return Error(L, "unexpected token in .thumb_func directive");
7641 Name = Tok.getIdentifier();
7642 Parser.Lex(); // Consume the identifier token.
7643 needFuncName = false;
7644 }
Rafael Espindola64695402011-05-16 16:17:21 +00007645 }
7646
Jim Grosbachde4d8392011-12-21 22:30:16 +00007647 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007648 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007649
7650 // Eat the end of statement and any blank lines that follow.
7651 while (getLexer().is(AsmToken::EndOfStatement))
7652 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007653
Rafael Espindola64695402011-05-16 16:17:21 +00007654 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007655 // We really should be checking the next symbol definition even if there's
7656 // stuff in between.
7657 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007658 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007659 }
7660
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007661 // Mark symbol as a thumb symbol.
7662 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7663 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007664 return false;
7665}
7666
Jim Grosbach1355cf12011-07-26 17:10:22 +00007667/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007668/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007669bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007670 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007671 if (Tok.isNot(AsmToken::Identifier))
7672 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007673 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007674 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007675 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007676 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007677 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007678 else
7679 return Error(L, "unrecognized syntax mode in .syntax directive");
7680
7681 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007682 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007683 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007684
7685 // TODO tell the MC streamer the mode
7686 // getParser().getStreamer().Emit???();
7687 return false;
7688}
7689
Jim Grosbach1355cf12011-07-26 17:10:22 +00007690/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007691/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007692bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007693 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007694 if (Tok.isNot(AsmToken::Integer))
7695 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007696 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007697 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007698 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007699 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007700 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007701 else
7702 return Error(L, "invalid operand to .code directive");
7703
7704 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007705 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007706 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007707
Evan Cheng32869202011-07-08 22:36:29 +00007708 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007709 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007710 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007711 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007712 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007713 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007714 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007715 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007716 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007717
Kevin Enderby515d5092009-10-15 20:48:48 +00007718 return false;
7719}
7720
Jim Grosbacha39cda72011-12-14 02:16:11 +00007721/// parseDirectiveReq
7722/// ::= name .req registername
7723bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7724 Parser.Lex(); // Eat the '.req' token.
7725 unsigned Reg;
7726 SMLoc SRegLoc, ERegLoc;
7727 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7728 Parser.EatToEndOfStatement();
7729 return Error(SRegLoc, "register name expected");
7730 }
7731
7732 // Shouldn't be anything else.
7733 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7734 Parser.EatToEndOfStatement();
7735 return Error(Parser.getTok().getLoc(),
7736 "unexpected input in .req directive.");
7737 }
7738
7739 Parser.Lex(); // Consume the EndOfStatement
7740
7741 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7742 return Error(SRegLoc, "redefinition of '" + Name +
7743 "' does not match original.");
7744
7745 return false;
7746}
7747
7748/// parseDirectiveUneq
7749/// ::= .unreq registername
7750bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7751 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7752 Parser.EatToEndOfStatement();
7753 return Error(L, "unexpected input in .unreq directive.");
7754 }
7755 RegisterReqs.erase(Parser.getTok().getIdentifier());
7756 Parser.Lex(); // Eat the identifier.
7757 return false;
7758}
7759
Jason W Kimd7c9e082011-12-20 17:38:12 +00007760/// parseDirectiveArch
7761/// ::= .arch token
7762bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7763 return true;
7764}
7765
7766/// parseDirectiveEabiAttr
7767/// ::= .eabi_attribute int, int
7768bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7769 return true;
7770}
7771
Sean Callanan90b70972010-04-07 20:29:34 +00007772extern "C" void LLVMInitializeARMAsmLexer();
7773
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007774/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007775extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007776 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7777 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007778 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007779}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007780
Chris Lattner0692ee62010-09-06 19:11:01 +00007781#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007782#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007783#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007784#include "ARMGenAsmMatcher.inc"